import { FC, useState } from 'react'
import SwitchComponent from '../../../components/Switch'
import { useToggleStatusCompany } from '../hooks/useCompanyData'

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

const ToggleStatusCompany: FC<Props> = (props: Props) => {

    const toggleStatus = useToggleStatusCompany()
    const [isActive, setIsActive] = useState<boolean>(props.defaultActive)

    const handleChange = (value: boolean) => {
        setIsActive(value)
        toggleStatus.mutate(props.id)
    }

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

export default ToggleStatusCompany