import {
    apiGet,
    checkerOnly,
    checkOverMapping,
    checkTypeMapping,
    crudCommonOptions,
    mappingField,
    operationField,
    stringField,
    timeField,
} from "../../components/constants.js";
import {permissionDetailDialog} from "../../components/permission/dialog-permission.js";

export function tabCheck() {
    return {
        visibleOn: checkerOnly,
        title: '审核审查',
        icon: 'fa fa-shield-halved',
        reload: true,
        body: [
            {
                name: 'check_order_list',
                type: 'crud',
                api: apiGet('${base}/check_order/list'),
                ...crudCommonOptions(),
                headerToolbar: [
                    'reload',
                ],
                columns: [
                    stringField('description', '描述'),
                    mappingField('type', '类型', checkTypeMapping),
                    mappingField('over', '状态', checkOverMapping),
                    timeField('createdTime', '创建时间'),
                    stringField('createdUsername', '创建人', 100),
                    timeField('modifiedTime', '最后修改时间'),
                    stringField('modifiedUsername', '最后操作人', 100),
                    operationField('操作', undefined, [
                        {
                            visibleOn: '${!over}',
                            type: 'action',
                            label: '处理',
                            level: 'link',
                            ...permissionDetailDialog(
                                'parameters.confirmationId',
                                [
                                    {
                                        type: 'action',
                                        label: '同意',
                                        actionType: 'ajax',
                                        close: true,
                                        api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'),
                                        reload: 'check_order_list',
                                    },
                                    {
                                        type: 'action',
                                        label: '拒绝',
                                        actionType: 'ajax',
                                        close: true,
                                        api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'),
                                        reload: 'check_order_list',
                                    },
                                ],
                            ),
                        },
                        {
                            visibleOn: '${over}',
                            type: 'action',
                            label: '查看',
                            level: 'link',
                            ...permissionDetailDialog('parameters.confirmationId'),
                        },
                    ]),
                ],
            },
        ],
    }
}