import { useAjax } from "@/Hook/useAjax"
import { updatePackLinkCodeApi } from "@/services/gameData/roleOperate"
import { Button, message, Popconfirm } from "antd"
import React from "react"

interface Props {
    id: number
    linkId?: number
    onChange?: () => void
}

/**
 * 修改状态
 * @returns 
 */
const EnabledSwitch: React.FC<Props> = ({ id, linkId, onChange }) => {

    /************************************/
    const updatePackLinkCode = useAjax((params) => updatePackLinkCodeApi(params))
    /************************************/

    return <Popconfirm
        title="确定删除?"
        onConfirm={() => {
            updatePackLinkCode.run({ ids: [id], linkId }).then(res => {
                if (res) {
                    onChange?.()
                    message.success('删除成功')
                }
            })
        }}
    >
        <Button loading={updatePackLinkCode.loading} danger type="link" style={{ padding: 0, fontSize: 12 }}>删除</Button>
    </Popconfirm>
}

export default React.memo(EnabledSwitch)