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

    const {
        spaces
    } = NCoreUIKitTheme.useContext();

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

    useLayoutEffect(() => {
        navigation.setOptions({
            header: () => <Header
                title={localize("components-snackBar")}
                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("snackBar-desc")}
            </Text>
            <Text
                variant="titleMediumSize"
                style={stylesheet.title}
            >
                {localize("components-snackBar")}
            </Text>
            <View
                style={stylesheet.customContainer}
            >
                <SnackBar
                    subTitle="This is an example subtitle"
                    title="This is an example SnackBar"
                    id="example-snackbar"
                    type="primary"
                />
                <Button
                    onPress={() => {
                        NCoreUIKitSnackBar.open({
                            subTitle: "This is an example subtitle",
                            title: "This is an example SnackBar",
                            type: "primary"
                        });
                    }}
                    title="Open SnackBar"
                />
            </View>
            <View
                style={{
                    marginTop: spaces.spacingMd
                }}
            >
                <Text
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                    variant="headlineSmallSize"
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    NCoreUIKitSnackBar\n} from \"ncore-ui-kit\";\n\nNCoreUIKitSnackBar.open({\n    title: \"Title\",\n    subTitle: \"Subtitle\",\n    type: \"primary\"\n});"}
                    language="tsx"
                />
            </View>
        </View>
    </PageContainer>;
};
export default SnackBarPage;
