import {
    useLayoutEffect
} from "react";
import {
    View
} from "react-native";
import stylesheet from "./stylesheet";
import {
    NCoreUIKitLocalize,
    NCoreUIKitTheme,
    LocaleSwitcher,
    PageContainer,
    Button,
    Header,
    Text
} from "ncore-ui-kit";
import {
    useNavigation
} from "@react-navigation/native";
import type RootStackParamList from "../../../navigation/type";
import type {
    NativeStackNavigationProp
} from "@react-navigation/native-stack";
import {
    ChevronRightIcon,
    ChevronLeftIcon
} from "lucide-react-native";

const LocaleExamples = () => {
    const {
        colors,
        spaces
    } = NCoreUIKitTheme.useContext();

    const {
        activeLocale,
        localize
    } = NCoreUIKitLocalize.useContext();

    const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();

    useLayoutEffect(() => {
        navigation.setOptions({
            header: () => <Header
                navigation={navigation as unknown as NCoreUIKit.Navigation}
                title={localize("localeExamples-title")}
                isWrapSafeareaContext={false}
                isGoBackEnable={true}
            />,
            headerShown: true
        });
    }, [
        navigation,
        localize
    ]);

    return <PageContainer
        isWorkWithHeaderSpace={false}
        isScrollable={true}
    >
        <Text
            variant="headlineSmallSize"
            color="high"
        >
            {localize("localeExamples-title")}
        </Text>
        <Text
            color="mid"
        >
            {localize("localeExamples-desc")}
        </Text>
        <Text
            style={{
                marginBottom: spaces.spacingLg,
                marginTop: spaces.spacingXl
            }}
            variant="titleMediumSize"
            color="high"
        >
            {localize("localeExamples-languageSwitcher")}
        </Text>
        <View
            style={[
                stylesheet.rowContainer,
                {
                    gap: spaces.spacingMd
                }
            ]}
        >
            <LocaleSwitcher/>
        </View>
        <View
            style={[
                stylesheet.borderedCard,
                {
                    backgroundColor: colors.content.container.subtle,
                    marginTop: spaces.spacingLg,
                    padding: spaces.spacingLg
                }
            ]}
        >
            <Text
                style={{
                    marginBottom: spaces.spacingMd
                }}
                variant="titleMediumSize"
                color="high"
            >
                {localize("localeExamples-localizedTexts")}
            </Text>
            <Text
                style={{
                    marginBottom: spaces.spacingSm
                }}
                color="mid"
            >
                {localize("localeExamples-currentLanguage")}<Text
                    variant="labelLargeSize"
                    color="high"
                >
                    {activeLocale}
                </Text>
            </Text>
            <View
                style={[
                    stylesheet.borderedCard2,
                    {
                        backgroundColor: colors.content.container.default,
                        padding: spaces.spacingMd,
                        gap: spaces.spacingMd
                    }
                ]}
            >
                <View>
                    <Text
                        variant="labelMediumSize"
                        color="mid"
                    >
                        "hello-world" key
                    </Text>
                    <Text
                        variant="bodyLargeSize"
                        color="high"
                    >
                        {localize("hello-world")}
                    </Text>
                </View>
                <View>
                    <Text
                        variant="labelMediumSize"
                        color="mid"
                    >
                        "menu" key
                    </Text>
                    <Text
                        variant="bodyLargeSize"
                        color="high"
                    >
                        {localize("menu")}
                    </Text>
                </View>
                <View>
                    <Text
                        variant="labelMediumSize"
                        color="mid"
                    >
                        "installation" key
                    </Text>
                    <Text
                        variant="bodyLargeSize"
                        color="high"
                    >
                        {localize("installation")}
                    </Text>
                </View>
            </View>
        </View>
        <View
            style={[
                stylesheet.rowSpaceBetween,
                {
                    marginTop: spaces.spacingXl
                }
            ]}
        >
            <Button
                icon={({
                    color,
                    size
                }) => {
                    return <ChevronLeftIcon
                        color={colors.content.icon[color]}
                        size={size + 3}
                    />;
                }}
                onPress={() => {
                    navigation.navigate("CoreFeatures", {
                        screen: "ThemeExamples"
                    });
                }}
                title={localize("themeExamples-title")}
            />
            <Button
                icon={({
                    color,
                    size
                }) => {
                    return <ChevronRightIcon
                        color={colors.content.icon[color]}
                        size={size + 3}
                    />;
                }}
                onPress={() => {
                    navigation.navigate("CoreFeatures", {
                        screen: "TypesOverride"
                    });
                }}
                title={localize("typesOverride-title")}
                iconDirection="right"
            />
        </View>
    </PageContainer>;
};
export default LocaleExamples;
