import {
    useLayoutEffect,
    useState
} from "react";
import {
    View
} from "react-native";
import stylesheet from "./stylesheet";
import {
    NCoreUIKitLocalize,
    NCoreUIKitTheme,
    PageContainer,
    MainHeader,
    CodeViewer,
    Header,
    Switch,
    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 MainHeaderPage = () => {
    const {
        radiuses,
        borders,
        spaces,
        colors
    } = NCoreUIKitTheme.useContext();

    const {
        localize
    } = NCoreUIKitLocalize.useContext();

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

    const [
        isWorkWithSeperator,
        setIsWorkWithSeperator
    ] = useState<boolean>(true);

    const [
        isWorkWithSticky,
        setIsWorkWithSticky
    ] = useState<boolean>(false);

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

    return <PageContainer
        scrollViewProps={{
            contentContainerStyle: stylesheet.scrollContent
        }}
        isWorkWithHeaderSpace={false}
        scrollViewStyle={[
            stylesheet.container
        ]}
        isScrollable={true}
    >
        <View
            style={[
                stylesheet.contentContainer
            ]}
        >
            <Text
                style={stylesheet.marginContainer}
                variant="bodyMediumSize"
                color="mid"
            >
                {localize("mainHeader-desc")}
            </Text>
            <View
                style={[
                    stylesheet.paddedMarginContainer,
                    {
                        borderColor: colors.content.border.subtle,
                        marginBottom: spaces.spacingMd,
                        borderRadius: radiuses.form,
                        borderWidth: borders.line,
                        padding: spaces.spacingMd
                    }
                ]}
            >
                <MainHeader
                    isWorkWithSeperator={isWorkWithSeperator}
                    isWorkWithSticky={isWorkWithSticky}
                    isWorkWithSafeAreaView={false}
                    isWorkWithPortal={false}
                />
            </View>
            <View
                style={{
                    marginBottom: spaces.spacingMd
                }}
            >
                <Text
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                    variant="headlineSmallSize"
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    MainHeader\n} from \"ncore-ui-kit\";\n\n<MainHeader />"}
                    language="tsx"
                />
            </View>
            <View
                style={stylesheet.rowSpaceBetween}
            >
                <Switch
                    onPress={() => setIsWorkWithSeperator(!isWorkWithSeperator)}
                    title={localize("mainHeader-toggleSeperator")}
                    isActive={isWorkWithSeperator}
                    spreadBehaviour="free"
                />
                <Switch
                    onPress={() => setIsWorkWithSticky(!isWorkWithSticky)}
                    title={localize("mainHeader-toggleSticky")}
                    isActive={isWorkWithSticky}
                    spreadBehaviour="free"
                />
            </View>
        </View>
    </PageContainer>;
};
export default MainHeaderPage;
