import { useAjax } from "@/Hook/useAjax"
import { delPageApi } from "@/services/adqV3/global"
import { Button, message, Popconfirm } from "antd"
import React from "react"

interface Props {
    accountId: number,
    pageIds: number[],
    onChange?: () => void
}

/**
 * 删除落地页
 * @param param0 
 * @returns 
 */
const DelPage: React.FC<Props> = ({ accountId, pageIds, onChange }) => {

    /**********************************/
    const delPage = useAjax((params) => delPageApi(params))
    /**********************************/

    const handleDel = () => {
        delPage.run({ accountId, pageIds }).then(res => {
            if (res?.length === 0) {
                message.success('删除成功，结果可能会延迟几分钟返回')
                onChange?.()
            }
        })
    }

    return <Popconfirm
        title="确定删除?"
        onConfirm={() => handleDel?.()}
    >
        <Button style={{ fontSize: 12, color: 'red', padding: 0 }} danger type="link" loading={delPage.loading}>删除</Button>
    </Popconfirm>
}

export default React.memo(DelPage)