import { FC, useState } from 'react'
import SwitchComponent from '../../../components/Switch'
import { useChangeStatusCategory } from '../hooks/useServiceData'

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

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

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

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

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

export default StatusCategory