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

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

    const {
        localize
    } = NCoreUIKitLocalize.useContext();

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

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

    const [
        showLeftIcon,
        setShowLeftIcon
    ] = useState<boolean>(true);

    const [
        showRightIcon,
        setShowRightIcon
    ] = useState<boolean>(true);

    useLayoutEffect(() => {
        navigation.setOptions({
            header: () => <Header
                title={localize("rowCard-title")}
                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("rowCard-desc")}
            </Text>
            <View
                style={[
                    stylesheet.previewContainer,
                    {
                        borderColor: colors.content.border.subtle,
                        marginBottom: spaces.spacingMd,
                        borderRadius: radiuses.form,
                        borderWidth: borders.line,
                        padding: spaces.spacingMd
                    }
                ]}
            >
                <RowCard
                    rightIcon={showRightIcon ? ({
                        color,
                        size
                    }) => <ChevronRightIcon
                        color={
                            colors.content.icon[
                                        color as keyof typeof colors.content.icon
                            ]
                        }
                        size={size}
                    />
                        : undefined}
                    icon={showLeftIcon ? ({
                        color,
                        size
                    }) => <HomeIcon
                        color={
                            colors.content.icon[
                                        color as keyof typeof colors.content.icon
                            ]
                        }
                        size={size}
                    />
                        : undefined}
                    title={title || localize("rowCard-exampleTitle")}
                    onPress={() => {}}
                />
            </View>
            <View
                style={{
                    marginBottom: spaces.spacingMd
                }}
            >
                <Text
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                    variant="headlineSmallSize"
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    RowCard\n} from \"ncore-ui-kit\";\n\n<RowCard\n    title=\"Row Card\"\n    onPress={() => {}}\n/>"}
                    language="tsx"
                />
            </View>
            <TextInput
                placeholder={localize("rowCard-enterTitle")}
                title={localize("rowCard-titleLabel")}
                style={{
                    marginBottom: spaces.spacingMd
                }}
                spreadBehaviour="stretch"
                onChangeText={setTitle}
                value={title}
            />
            <View
                style={stylesheet.switchesContainer}
            >
                <Switch
                    onPress={() => setShowLeftIcon(!showLeftIcon)}
                    title={localize("rowCard-toggleLeftIcon")}
                    isActive={showLeftIcon}
                    spreadBehaviour="free"
                />
                <Switch
                    onPress={() => setShowRightIcon(!showRightIcon)}
                    title={localize("rowCard-toggleRightIcon")}
                    isActive={showRightIcon}
                    spreadBehaviour="free"
                />
            </View>
        </View>
    </PageContainer>;
};
export default RowCardPage;
