/* Copyright (C) Click & Push Accessibility, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written and maintained by the Click & Push Development team 
 * <dev@clicknpush.ca>, January 2022
 */

import React, { useEffect, useState } from "react"
import { Switch, Text, View } from "react-native"
import { GlobalStyles } from "../../../utils/GlobalUtils"
import { ProfileSection } from "./ProfileSection"

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>
    )
}