import {
    useLayoutEffect
} from "react";
import {
    View
} from "react-native";
import stylesheet from "./stylesheet";
import {
    NCoreUIKitLocalize,
    NCoreUIKitTheme,
    PaletteSwitcher,
    PageContainer,
    CodeViewer,
    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 PaletteSwitcherPage = () => {
    const {
        localize
    } = NCoreUIKitLocalize.useContext();

    const {
        spaces
    } = NCoreUIKitTheme.useContext();

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

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

    return <PageContainer
        scrollViewProps={{
            contentContainerStyle: stylesheet.scrollContent
        }}
        scrollViewStyle={[
            stylesheet.container
        ]}
        isWorkWithHeaderSpace={false}
        isScrollable={true}
    >
        <View
            style={[
                stylesheet.contentContainer
            ]}
        >
            <Text
                variant="bodyMediumSize"
                color="mid"
                style={stylesheet.descText}
            >
                {localize("paletteSwitcher-desc")}
            </Text>
            <Text
                style={stylesheet.title}
                variant="titleMediumSize"
            >
                {localize("components-paletteSwitcher")}
            </Text>
            <PaletteSwitcher />
            <View
                style={{
                    marginTop: spaces.spacingMd
                }}
            >
                <Text
                    variant="headlineSmallSize"
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    PaletteSwitcher\n} from \"ncore-ui-kit\";\n\n<PaletteSwitcher />"}
                    language="tsx"
                />
            </View>
        </View>
    </PageContainer>;
};
export default PaletteSwitcherPage;
