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

    const {
        spaces
    } = NCoreUIKitTheme.useContext();

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

    const [
        isActive,
        setIsActive
    ] = useState<boolean>(false);

    useLayoutEffect(() => {
        navigation.setOptions({
            header: () => <Header
                title={localize("components-modal")}
                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.descText}
                variant="bodyMediumSize"
                color="mid"
            >
                {localize("modal-desc")}
            </Text>
            <Text
                variant="titleMediumSize"
                style={stylesheet.title}
            >
                {localize("components-modal")}
            </Text>
            <Button
                onPress={() => setIsActive(true)}
                spreadBehaviour="stretch"
                title="Open Modal"
            />
            <View
                style={{
                    marginVertical: spaces.spacingMd
                }}
            >
                <Text
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                    variant="headlineSmallSize"
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    Modal\n} from \"ncore-ui-kit\";\n\n<Modal\n    isActive={isActive}\n    onOverlayPress={() => setIsActive(false)}\n>\n    <View>\n        <Text>Modal Content</Text>\n    </View>\n</Modal>"}
                    language="tsx"
                />
            </View>
            <Modal
                onOverlayPress={() => setIsActive(false)}
                isActive={isActive}
                id="example-modal"
            >
                <View
                    style={stylesheet.modalContent}
                >
                    <Text>
                        This is an example modal content.
                    </Text>
                    <Button
                        onPress={() => setIsActive(false)}
                        spreadBehaviour="stretch"
                        title="Close Modal"
                        type="primary"
                    />
                </View>
            </Modal>
        </View>
    </PageContainer>;
};
export default ModalPage;
