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

const SiteLogoPage = () => {
    const {
        activeTheme,
        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 [
        isShowIcon,
        setIsShowIcon
    ] = useState<boolean>(true);

    useLayoutEffect(() => {
        navigation.setOptions({
            header: () => <Header
                title={localize("siteLogo-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("siteLogo-desc")}
            </Text>
            <View
                style={[
                    stylesheet.previewContainer,
                    {
                        borderColor: colors.content.border.subtle,
                        marginBottom: spaces.spacingMd,
                        borderRadius: radiuses.form,
                        borderWidth: borders.line,
                        padding: spaces.spacingMd
                    }
                ]}
            >
                <SiteLogo
                    imageUrl={
                        activeTheme.indexOf("dark") !== -1
                            ? "http://ncore.nibgat.space/assets/images/darklogo.png"
                            : "http://ncore.nibgat.space/assets/images/ncorelogo.png"
                    }
                    title={
                        title || localize("siteLogo-exampleTitle")
                    }
                    subTitle={
                        subTitle ||
                            localize("siteLogo-exampleSubTitle")
                    }
                    isShowIcon={isShowIcon}
                />
            </View>
            <View
                style={{
                    marginBottom: spaces.spacingMd
                }}
            >
                <Text
                    style={{
                        marginBottom: spaces.spacingSm
                    }}
                    variant="headlineSmallSize"
                >
                    {localize("usage")}
                </Text>
                <CodeViewer
                    code={"import {\n    SiteLogo\n} from \"ncore-ui-kit\";\n\n<SiteLogo\n    imageUrl=\"https://.../logo.png\"\n    title=\"Site Title\"\n/>"}
                    language="tsx"
                />
            </View>
            <TextInput
                placeholder={localize("siteLogo-enterTitle")}
                title={localize("siteLogo-titleLabel")}
                style={{
                    marginBottom: spaces.spacingMd
                }}
                spreadBehaviour="stretch"
                onChangeText={setTitle}
                value={title}
            />
            <TextInput
                placeholder={localize("siteLogo-enterSubTitle")}
                title={localize("siteLogo-subTitleLabel")}
                style={{
                    marginBottom: spaces.spacingMd
                }}
                onChangeText={setSubTitle}
                spreadBehaviour="stretch"
                value={subTitle}
            />
            <Switch
                onPress={() => setIsShowIcon(!isShowIcon)}
                title={localize("siteLogo-toggleIcon")}
                spreadBehaviour="free"
                isActive={isShowIcon}
            />
        </View>
    </PageContainer>;
};
export default SiteLogoPage;
