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

    const {
        spaces
    } = NCoreUIKitTheme.useContext();

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

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