import { useAjax } from "@/Hook/useAjax"
import { modifyStatusBatchApi } from "@/services/launchAdq/adqv3"
import { message, Switch } from "antd"
import React from "react"



/**
 * 修改启停
 */
interface Props {
    configuredStatus: string,
    isDeleted?: boolean,
    accountId: number
    adgroupId: number,
    onChange?: () => void
}
const SwitchStatus: React.FC<Props> = (prosp) => {

    const { configuredStatus, isDeleted, accountId, adgroupId, onChange } = prosp
    const modifyStatusBatch = useAjax((params) => modifyStatusBatchApi(params))

    const switchHandle = (accountAdgroupMaps: string[], suspend: boolean) => {
        modifyStatusBatch.run({ accountAdgroupMaps, suspend: !suspend }).then(res => {
            message.success(`${suspend ? '启动' : '暂停'}成功`)
            onChange?.()
        })
    }

    return <Switch size="small" checked={configuredStatus === 'AD_STATUS_NORMAL'} loading={modifyStatusBatch.loading} disabled={isDeleted} onChange={(checked) => switchHandle([accountId + ',' + adgroupId], checked)} />
}


export default React.memo(SwitchStatus)