import React, { useEffect, useState } from "react"
import { Button, Switch, Text, TouchableOpacity, View } from "react-native"
import Collapsible from "react-native-collapsible"
import { GlobalStyles } from "../../../utils/GlobalUtils"
import { Separator } from "../../Separator"
import { ProfileSectionStyles } from "../Styles/ProfileSections.styles"
import { ProfileSection } from "./ProfileSection"
import { ProfileSectionHeader } from "./ProfileSectionHeader"

interface PrefsInformationProps {
    openPrefs: () => void
    prefsCollapsed: boolean
    toggleTipsAsync: () => void 
    showTips: boolean
}

export const ProfilePrefs: React.FC<PrefsInformationProps> = ({openPrefs, prefsCollapsed, toggleTipsAsync, showTips}) => {    
    const [localTipsEnabled, toggleLocalTips] = useState<boolean>(false)

    useEffect(() => {
        const changeTipsStateOnToggle = () => {
            toggleLocalTips(showTips)
        }
        changeTipsStateOnToggle()
    }, [showTips])

    const toggleTips = async () => {
        toggleLocalTips(!showTips)
        await toggleTipsAsync();
    }

    return (
        <ProfileSection isCollapsed={prefsCollapsed} collapseToggleMethod={openPrefs} title="Preferences">
            <View style={GlobalStyles.itemRowContainer}>
                <Text>Startup tips:</Text>
                <Switch value={localTipsEnabled} onValueChange={async () => toggleTips()} />
            </View>
        </ProfileSection>
    )
}