import { useAjax } from "@/Hook/useAjax";
import { iaaConfigBackPolicyApi } from "@/services/iaaSystem/channel";
import { Button, Popconfirm } from "antd";
import React from "react"

interface Props {
    id: number
    onChange?: () => void
    key?: React.Key
}

/**
 * 取消绑定回传策略
 * @param param0 
 * @returns 
 */
const CancelBackPolicy: React.FC<Props> = ({ key, id, onChange }) => {

    /********************************/
    const iaaConfigBackPolicy = useAjax((params) => iaaConfigBackPolicyApi(params))
    /********************************/

    const confirm = () => {
        iaaConfigBackPolicy.run({ agentIds: id }).then(res => {
            if (res?.data) {
                onChange?.()
            }
        })
    }

    return <Popconfirm
        key={key}
        title="取消绑定回传策略?"
        onConfirm={confirm}
    >
        <Button type="link" loading={iaaConfigBackPolicy.loading} danger style={{ padding: 0, height: 'auto' }} >取消绑定回传策略</Button>
    </Popconfirm>
}

export default React.memo(CancelBackPolicy)