import { useAjax } from "@/Hook/useAjax";
import { iaaConfigPutStatusApi } from "@/services/iaaSystem/channel";
import { Form, message, Modal, Select } from "antd";
import React from "react"

interface Props {
    selectedRows: any[]
    onChange?: () => void
    visible?: boolean
    onClose?: () => void
}

const ConfigPutStatus: React.FC<Props> = ({ selectedRows, onChange, visible, onClose }) => {

    /*******************************/
    const [form] = Form.useForm<IAAAPI.AddIaaAgentProps>();

    const iaaConfigPutStatus = useAjax((params) => iaaConfigPutStatusApi(params))
    /*******************************/


    const handleOk = async () => {
        form.submit()
        let data: any = await form.validateFields()
        iaaConfigPutStatus.run({...data, agentIds: selectedRows.map(item => item.id).toString()}).then(res => {
            if (res?.data) {
                message.success('变更成功')
                onChange && onChange()
            }
        })
    }

    return <Modal
        title={<strong>{'变更投放状态'}</strong>}
        open={visible}
        onCancel={onClose}
        onOk={handleOk}
        confirmLoading={iaaConfigPutStatus.loading}
    >
        <Form
            name="configPutStatus"
            layout="vertical"
            form={form}
            autoComplete="off"
            colon={false}
        >
            <Form.Item label={<strong>投放状态</strong>} name="putStatus">
                <Select
                    placeholder="请选择投放状态"
                    options={[
                        {
                            value: 'PUT_STATUS_PUT_ING',
                            label: '投放中',
                        },
                        {
                            value: 'PUT_STATUS_PUT_STOP',
                            label: '投放结束',
                        }
                    ]}
                />
            </Form.Item>
        </Form>
    </Modal> 
}

export default React.memo(ConfigPutStatus)