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

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

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

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

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

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

export default ToggleStatusService