import {
    useLayoutEffect,
    useState
} from "react";
import {
    View
} from "react-native";
import stylesheet from "./stylesheet";
import {
    NCoreUIKitLocalize,
    NCoreUIKitTheme,
    PageContainer,
    CodeViewer,
    StateCard,
    TextInput,
    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";
import {
    Home as HomeIcon
} from "lucide-react-native";

const StateCardPage = () => {
    const {
        radiuses,
        borders,
        spaces,
        colors
    } = NCoreUIKitTheme.useContext();

    const {
        localize
    } = NCoreUIKitLocalize.useContext();

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

    const [
        title,
        setTitle
    ] = useState<string>("");

    const [
        subTitle,
        setSubTitle
    ] = useState<string>("");

    const [
        value,
        setValue
    ] = useState<string>("");

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

    return <PageContainer
        scrollViewProps={{
            contentContainerStyle: stylesheet.scrollContent
        }}
        scrollViewStyle={[
            stylesheet.container
        ]}
        isWorkWithHeaderSpace={false}
        isScrollable={true}
    >
        <View
            style={[
                stylesheet.contentContainer
            ]}
        >
            <Text
                variant="bodyMediumSize"
                color="mid"
                style={stylesheet.descText}
            >
                {localize("stateCard-desc")}
            </Text>
            <View
                style={[
                    stylesheet.previewContainer,
                    {
                        borderColor: colors.content.border.subtle,
                        marginBottom: spaces.spacingMd,
                        borderRadius: radiuses.form,
                        borderWidth: borders.line,
                        padding: spaces.spacingMd
                    }
                ]}
            >
                <StateCard
                    icon={({
                        color,
                        size
                    }) => <HomeIcon
                        color={
                            colors.content.icon[
                                        color as keyof typeof colors.content.icon
                            ]
                        }
                        size={size}
                    />
                    }
                    subTitle={
                        subTitle ||
                            localize("stateCard-exampleSubTitle")
                    }
                    title={
                        title || localize("stateCard-exampleTitle")
                    }
                />
            </View>
            <View
                style={{
                    marginBottom: spaces.spacingMd
                }}
            >
                <Text
                    variant="headlineSmallSize"
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    StateCard\n} from \"ncore-ui-kit\";\n\n<StateCard\n    title=\"Title\"\n    subTitle=\"Subtitle\"\n/>"}
                    language="tsx"
                />
            </View>
            <TextInput
                placeholder={localize("stateCard-enterTitle")}
                title={localize("stateCard-titleLabel")}
                style={{
                    marginBottom: spaces.spacingMd
                }}
                spreadBehaviour="stretch"
                onChangeText={setTitle}
                value={title}
            />
            <TextInput
                placeholder={localize("stateCard-enterSubTitle")}
                title={localize("stateCard-subTitleLabel")}
                style={{
                    marginBottom: spaces.spacingMd
                }}
                onChangeText={setSubTitle}
                spreadBehaviour="stretch"
                value={subTitle}
            />
            <TextInput
                placeholder={localize("stateCard-enterValue")}
                title={localize("stateCard-valueLabel")}
                style={{
                    marginBottom: spaces.spacingMd
                }}
                spreadBehaviour="stretch"
                onChangeText={setValue}
                value={value}
            />
        </View>
    </PageContainer>;
};
export default StateCardPage;
