import {
    useLayoutEffect,
    useState
} from "react";
import {
    View
} from "react-native";
import stylesheet from "./stylesheet";
import {
    NCoreUIKitLocalize,
    NCoreUIKitTheme,
    PageContainer,
    CodeViewer,
    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";

const TextPage = () => {
    const {
        typography,
        radiuses,
        borders,
        spaces,
        colors
    } = NCoreUIKitTheme.useContext();

    const {
        localize
    } = NCoreUIKitLocalize.useContext();

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

    const [
        variant,
        setVariant
    ] = useState<number>(0);

    useLayoutEffect(() => {
        navigation.setOptions({
            header: () => <Header
                isWrapSafeareaContext={false}
                title={localize("text")}
                navigation={navigation}
                isGoBackEnable={true}
            />,
            headerShown: true
        });
    }, []);

    return <PageContainer
        isWorkWithHeaderSpace={false}
        style={[
            stylesheet.container
        ]}
        isScrollable={false}
    >
        <View
            style={[
                stylesheet.contentContainer
            ]}
        >
            <Text
                style={stylesheet.marginContainer}
                variant="bodyMediumSize"
                color="mid"
            >
                {localize("text-desc")}
            </Text>
            <View
                style={[
                    stylesheet.paddedMarginContainer,
                    {
                        borderColor: colors.content.border.subtle,
                        marginBottom: spaces.spacingMd,
                        borderRadius: radiuses.form,
                        borderWidth: borders.line,
                        padding: spaces.spacingMd
                    }
                ]}
            >
                <Text
                    variant={Object.keys(typography)[variant] as keyof NCoreUIKit.Typography}
                    style={{
                        marginBottom: spaces.spacingLg
                    }}
                >
                    {localize("this-is-test-sub-page")}
                </Text>
            </View>
            <View
                style={{
                    marginBottom: spaces.spacingMd
                }}
            >
                <Text
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                    variant="headlineSmallSize"
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    Text\n} from \"ncore-ui-kit\";\n\n<Text variant=\"bodyMediumSize\">\n    Hello World\n</Text>"}
                    language="tsx"
                />
            </View>
            <Button
                onPress={() => {
                    setVariant(variant + 1 > Object.keys(typography).length - 1 ? 0 : variant + 1);
                }}
                title={`variant = ${Object.keys(typography)[variant]}`}
                spreadBehaviour="stretch"
            />
        </View>
    </PageContainer>;
};
export default TextPage;
