import {Button, Text, View} from "react-native-ui-lib";
import React, {useState} from "react";
import {StyleSheet} from "react-native";
import {Octicons} from "@expo/vector-icons";
import CalendarSettingsPage from "./CalendarSettingsPage";
import ChoreRewardSettings from "./ChoreRewardSettings";
import UserSettings from "./UserSettings";
import ProfileIcon from "@/assets/svgs/ProfileIcon";
import CalendarIcon from "@/assets/svgs/CalendarIcon";
import PrivacyPolicyIcon from "@/assets/svgs/PrivacyPolicyIcon";
import ArrowRightIcon from "@/assets/svgs/ArrowRightIcon";
import {ProfileType, useAuthContext} from "@/contexts/AuthContext";

const pageIndex = {
    main: 0,
    user: 1,
    calendar: 2,
    chore: 3,
    policy: 4,
};

const SettingsPage = () => {
    const {profileData} = useAuthContext()
    const isntParent = profileData?.userType !== ProfileType.PARENT

    const [selectedPage, setSelectedPage] = useState<number>(0);
    return (
        <View flexG>
            {selectedPage == 0 && (
                <View flexG centerH marginH-30 marginT-30>
                    <Button
                        disabled={isntParent}
                        backgroundColor="white"
                        style={styles.mainBtn}
                        children={
                            <View row centerV width={"100%"}>
                                <ProfileIcon style={{marginRight: 10}} color="#07b9c8"/>
                                <Text style={[styles.label, isntParent && styles.disabledText]}>
                                    Manage My Profile
                                </Text>
                                <ArrowRightIcon style={{marginLeft: "auto"}}/>
                            </View>
                        }
                        onPress={() => setSelectedPage(pageIndex.user)}
                    />
                    <Button
                        disabled={isntParent}
                        backgroundColor="white"
                        style={styles.mainBtn}
                        children={
                            <View row centerV width={"100%"}>
                                <CalendarIcon style={{marginRight: 10}}/>
                                <Text style={[styles.label, isntParent && styles.disabledText]}>
                                    Calendar Settings
                                </Text>
                                <ArrowRightIcon style={{marginLeft: "auto"}}/>
                            </View>
                        }
                        onPress={() => {
                            setSelectedPage(pageIndex.calendar);
                        }}
                    />
                    <Button
                        disabled={isntParent}
                        backgroundColor="white"
                        style={styles.mainBtn}
                        children={
                            <View row centerV width={"100%"}>
                                <Octicons
                                    name="gear"
                                    size={24}
                                    color="#ff9900"
                                    style={{marginRight: 10}}
                                />
                                <Text style={[styles.label, isntParent && styles.disabledText]}>
                                    To-Do Reward Settings
                                </Text>
                                <ArrowRightIcon style={{marginLeft: "auto"}}/>
                            </View>
                        }
                        onPress={() => setSelectedPage(pageIndex.chore)}
                    />
                    <Button
                        backgroundColor="white"
                        style={styles.mainBtn}
                        children={
                            <View row centerV width={"100%"}>
                                <PrivacyPolicyIcon style={{marginRight: 10}}/>
                                <Text style={styles.label}>
                                    Cally Privacy Policy
                                </Text>
                                <ArrowRightIcon style={{marginLeft: "auto"}}/>
                            </View>
                        }
                    />
                </View>
            )}
            {selectedPage == pageIndex.calendar && (
                <CalendarSettingsPage setSelectedPage={setSelectedPage}/>
            )}
            {selectedPage == pageIndex.chore && (
                <ChoreRewardSettings setSelectedPage={setSelectedPage}/>
            )}
            {selectedPage == pageIndex.user && (
                <UserSettings setSelectedPage={setSelectedPage}/>
            )}
        </View>
    );
};

export default SettingsPage;

const styles = StyleSheet.create({
    mainBtn: {
        width: 311,
        justifyContent: "flex-start",
        marginBottom: 20,
        height: 57.61,
    },
    label: {
        fontFamily: "Poppins_400Regular",
        fontSize: 14.71,
        textAlignVertical: "center",
    },
    disabledText: {
        color: '#A9A9A9', // Example of a gray color for disabled text
    },
});