import { FC, useState } from 'react'
import SwitchComponent from '../../../components/Switch'
import { useToggleStatusAds } from '../hooks/useAdsData'

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

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

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

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

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

export default ToggleStatusAds