import { FC, useState } from 'react'
import SwitchComponent from '../../../components/Switch'
import { useUpdateSetting } from '../hooks/useSettingData'

type Props = {
    email: boolean,
    id: string
}

const Email: FC<Props> = (props: Props) => {
    const updateSetting = useUpdateSetting()
    const [email, setEmail] = useState<boolean>(props.email)

    const handleChange = (value: boolean) => {
        setEmail(value)
        updateSetting.mutate({ email: value, id: props.id })
    }

    return (
        <SwitchComponent
            active={email}
            onChange={handleChange}
        />
    )
}

export default Email