import { Pressable, StyleSheet, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';

import { LUOGHI, LUOGHI_GRATIS } from '../../gioco.ts';
import { useAcquisti } from '../acquisti.tsx';
import { COLORI, FONT, FONT_TESTO, SceltaStile } from '../componenti.tsx';
import { GrigliaLuoghi } from '../GrigliaLuoghi.tsx';
import type { Schermate } from '../navigazione.ts';
import { useStato } from '../stato.tsx';

export function Luoghi({ navigation }: NativeStackScreenProps<Schermate, 'Luoghi'>) {
  const { t } = useStato();
  const { sbloccato } = useAcquisti();
  // Nella versione gratis prima i 10 luoghi in gioco, poi gli altri col lucchetto.
  const luoghi = sbloccato ? LUOGHI : [...LUOGHI_GRATIS, ...LUOGHI.filter((l) => !LUOGHI_GRATIS.includes(l))];
  return (
    <SafeAreaView style={st.pieno} edges={['top', 'left', 'right']}>
      <View style={st.barra}>
        <SceltaStile />
        <Pressable accessibilityRole="button" accessibilityLabel={t('regole.chiudi')} hitSlop={12} onPress={() => navigation.goBack()} style={st.chiudi}>
          <Text style={st.x}>✕</Text>
        </Pressable>
      </View>
      <GrigliaLuoghi
        luoghi={luoghi}
        bloccato={sbloccato ? undefined : (id) => !LUOGHI_GRATIS.includes(id)}
        onBloccato={() => navigation.navigate('Sblocca')}
        intestazione={sbloccato ? undefined : <Text style={st.avviso}>{t('luoghi.gratis')}</Text>}
      />
    </SafeAreaView>
  );
}

const st = StyleSheet.create({
  pieno: { flex: 1, backgroundColor: '#000' },
  barra: { height: 52, justifyContent: 'center' },
  chiudi: { position: 'absolute', right: 16, top: 12 },
  x: { fontFamily: FONT, fontSize: 24, color: '#FFFFFF' },
  avviso: { fontFamily: FONT_TESTO, fontSize: 18, lineHeight: 23, color: COLORI.arancio, textAlign: 'center', padding: 10 },
});
