import {
    apiGet,
    checkerOnly,
    checkOverMapping,
    checkTypeMapping,
    crudCommonOptions,
    mappingField,
    operationField,
    stringField,
    timeField,
} from "../../components/constants.js";
import {authenticationDetailDialog, confirmationDetailDialog} from "../../components/permission/dialog-permission.js";
import {wareDetailDialog} from "../../components/ware/dialog-ware.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('state', '状态', checkOverMapping),
                    timeField('createdTime', '创建时间'),
                    stringField('createdUsername', '创建人', 100),
                    timeField('modifiedTime', '最后修改时间'),
                    stringField('modifiedUsername', '最后操作人', 100),
                    operationField('操作', undefined, [
                        {
                            visibleOn: `\${type === 'CONFIRMATION' && state === 'CHECKING'}`,
                            type: 'action',
                            label: '处理',
                            level: 'link',
                            ...confirmationDetailDialog(
                                '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: `\${type === 'CONFIRMATION' && state !== NORMAL}`,
                            type: 'action',
                            label: '查看',
                            level: 'link',
                            ...confirmationDetailDialog('parameters.confirmationId'),
                        },
                        {
                            visibleOn: `\${type === 'AUTHENTICATION' && state === 'CHECKING'}`,
                            type: 'action',
                            label: '处理',
                            level: 'link',
                            ...authenticationDetailDialog(
                                'parameters.authenticationId',
                                [
                                    {
                                        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: `\${type === 'AUTHENTICATION' && state !== NORMAL}`,
                            type: 'action',
                            label: '查看',
                            level: 'link',
                            ...authenticationDetailDialog('parameters.authenticationId'),
                        },
                        {
                            visibleOn: `\${type === 'MARKET' && state === 'CHECKING'}`,
                            type: 'action',
                            label: '处理',
                            level: 'link',
                            ...wareDetailDialog(
                                'parameters.wareId',
                                [
                                    {
                                        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: `\${type === 'MARKET' && state !== NORMAL}`,
                            type: 'action',
                            label: '查看',
                            level: 'link',
                            ...wareDetailDialog('parameters.wareId'),
                        },
                    ]),
                ],
            },
        ],
    }
}