import {
    useLayoutEffect,
    useState,
    useRef
} from "react";
import {
    View
} from "react-native";
import stylesheet from "./stylesheet";
import {
    NCoreUIKitLocalize,
    NCoreUIKitTheme,
    DateTimeSheet,
    PageContainer,
    CodeViewer,
    Header,
    Button,
    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";
import type {
    IBottomSheetRef
} from "ncore-ui-kit";

const DateTimeSheetPage = () => {
    const {
        localize
    } = NCoreUIKitLocalize.useContext();

    const {
        spaces
    } = NCoreUIKitTheme.useContext();

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

    const bottomSheetRef = useRef<IBottomSheetRef>(null);

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

    useLayoutEffect(() => {
        navigation.setOptions({
            header: () => <Header
                title={localize("components-dateTimeSheet")}
                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("dateTimeSheet-desc")}
            </Text>
            <Text
                variant="titleMediumSize"
                style={stylesheet.title}
            >
                {localize("components-dateTimeSheet")}
            </Text>
            <Button
                onPress={() => setIsActive(true)}
                title="Open DateTime Sheet"
                spreadBehaviour="stretch"
            />
            <View
                style={{
                    marginVertical: spaces.spacingMd
                }}
            >
                <Text
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                    variant="headlineSmallSize"
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    DateTimeSheet\n} from \"ncore-ui-kit\";\n\n<DateTimeSheet\n    isActive={isActive}\n    setIsActive={setIsActive}\n    pickerType=\"date\"\n    variant=\"single\"\n/>"}
                    language="tsx"
                />
            </View>
            <DateTimeSheet
                cancel={() => setIsActive(false)}
                selectMultipleObject={() => {}}
                bottomSheetRef={bottomSheetRef}
                ok={() => setIsActive(false)}
                selectDateRule={() => {}}
                isWorkWithRealtime={true}
                setIsActive={setIsActive}
                dateTimePickerKey="test"
                selectObject={() => {}}
                isActive={isActive}
                pickerType="date"
                isLoading={false}
                clean={() => {}}
                variant="single"
            />
        </View>
    </PageContainer>;
};
export default DateTimeSheetPage;
