import {Message, Modal, Tag} from "@arco-design/web-vue";
import {h} from 'vue';

const ModalContent = {
    props: {
        status: {
            type: String,
            default: 'success',
        },
        status_text: {
            type: String,
            default: null,
        }
    },
    setup(props) {
        switch (props.status) {
            case 'success':
                return () => h('div', {}, [
                    h('div', {class: 'flex items-center gap-[8px]'}, [
                        h('div', {}, '该子任务状态为:'),
                        h(Tag, {color: 'orangered'}, props.status_text)
                    ]),
                    h('div', {class: 'text-[14px] text-[rgb(78, 89, 105)]'}, '点击终止子任务后，达人将无法再领取子任务')
                ]);
            case 'warning':
                return () => h('div', {}, [
                    h('div', {class: 'flex items-center gap-[8px]'}, [
                        h('div', {}, '该子任务状态为:'),
                        h(Tag, {color: 'orangered'}, props.status_text)
                    ]),
                    h('div', {class: 'text-[14px] text-[rgb(78, 89, 105)]'}, '无法终止')
                ]);
            case 'none':
                return () => h('div', {}, [
                    h('div', {class: 'text-[14px] text-[rgb(78, 89, 105)]'}, '点击终止子任务后，达人将无法再领取子任务'),
                    h('div', {class: 'text-[14px] text-[#4E5969]'}, '*请商家及时处理已经被接单的子任务，处理完毕后，剩余任务金额将返款至商家钱包')
                ]);
        }
    }
}

const openTerminateTask = ({type = 'none', status_text = '待上传素材', taskId, Api = Api.admin.stopTask, callback}) => {
    const status = type;

    Modal.warning({
        title: '确认终止子任务',
        draggable: true,
        hideCancel: status === 'warning',
        content: () =>
            h(
                ModalContent,
                {
                    status: status,
                    status_text: status_text
                }
            ),
        okButtonProps: {
            status: 'danger',
        },
        okText: status === 'success' ? '确认终止' : '确认',
        onOk: async () => {
            if (status !== 'warning') {
                const {code, msg} = await Api(taskId);
                if (code === 1) Message.success(msg);
            }
            callback && callback();
        }
    });
}

export default openTerminateTask;
