import * as api from './api';
import {
    dict,
    UserPageQuery,
    AddReq,
    DelReq,
    EditReq,
    compute,
    CreateCrudOptionsProps,
    CreateCrudOptionsRet
} from '@fast-crud/fast-crud';
import {request} from '/@/utils/service';
import {dictionary} from '/@/utils/dictionary';
import {successMessage} from '/@/utils/message';
import {auth} from '/@/utils/authFunction'

export const createCrudOptions = function ({crudExpose}: CreateCrudOptionsProps): CreateCrudOptionsRet {
    const pageRequest = async (query: UserPageQuery) => {
        return await api.GetList(query);
    };
    const editRequest = async ({form, row}: EditReq) => {
        form.id = row.id;
        return await api.UpdateObj(form);
    };
    const delRequest = async ({row}: DelReq) => {
        return await api.DelObj(row.id);
    };
    const addRequest = async ({form}: AddReq) => {
        return await api.AddObj(form);
    };

    return {
        crudOptions: {
            request: {
                pageRequest,
                addRequest,
                editRequest,
                delRequest,
            },
            view: {
                // 配置查看操作的对话框
                dialog: {
                  footer: false, // 直接隐藏整个底部区域
                  // 或自定义底部插槽（二选一）
                  footerBuild: () => null // 返回 null 不渲染底部
                }
              },
            actionbar: {
                buttons: {
                    add: {
                        text: "新增标签",
                        icon: "Plus",
                        type: "primary",
                        show: true
                    }
                }
            },
            search: {
				show: true,
				layout: 'auto',
				autoSearch:false,
				buttons: {
					search: {
						size: 'small', // 设置查询按钮大小为small
					},
					reset: {
						size: 'small', // 设置重置按钮大小为small
					}
				},		
            },
            rowHandle: {
                fixed: 'right',
                width: 260,
                buttons: {
                    view: {
                        iconRight: 'View',
                        type: 'text',
                        show: true,
                    },
                    edit: {
                        iconRight: 'Edit',
                        type: 'text',
                        show: true,
                    },
                    remove: {
                        iconRight: 'Delete',
                        type: 'text',
                        show: true,
                    },
                },
            },
            form: {
                col: {span: 24},
                labelWidth: '110px',
                wrapper: {
                    is: 'el-dialog',
                    width: '600px',
                    title: "标签信息"
                },
                defaultValue: {
                    color: "#4A90E2",
                    is_system: false,
                    status: true
                },
                display: "flex",
                labelPosition: "right"
            },
            columns: {
                _index: {
                    title: '序号',
                    form: {show: false},
                    column: {
                        align: 'center',
                        width: '70px',
                        columnSetDisabled: true,
                        formatter: (context) => {
                            let index = context.index ?? 1;
                            let pagination: any = crudExpose!.crudBinding.value.pagination;
                            return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
                        },
                    },
                },
              /*   search:{
                    title: '标签名称',
                    search: {
                        show: true,
                        component: {
                            props: {
                                clearable: true,
                            },
                            placeholder: '请输入标签名称',
                        },
                    },
                    form: {
                        show: false,
                    },
                    column: {
                        show: false,
                    },
                }, */
                name: {
                    title: '标签名称',
                    search: {
                        show: true,
                        component: {
                            props: {
                                clearable: true,
                            },
                            placeholder: '请输入标签名称',
                        },
                    },
                    form: {
                        rules: [
                            { required: true, message: '请输入标签名称' },
                            { max: 50, message: '标签名称不能超过50个字符' }
                        ],
                        component: {
                            span: 24,
                            props: {
                                clearable: true,
                                placeholder: '请输入标签名称'
                            },
                        },
                    },
                    column: {
                        minWidth: 120,
                    },
                },
                description: {
                    title: '标签描述',
                    search: {
                        show: false,
                    },
                    form: {
                        rules: [
                            { max: 200, message: '标签描述不能超过200个字符' }
                        ],
                        component: {
                            span: 24,
                            name: 'el-input',
                            type: 'textarea',
                            props: {
                                rows: 3,
                                placeholder: '请输入标签描述'
                            },
                        },
                    },
                    column: {
                        minWidth: 200,
                        showOverflowTooltip: true,
                    },
                },
                employment_status:{
                     title: '标签类型',
                    search: {
                        show: true,
                    },
                    type: 'dict-select',
                    dict: dict({
                        data: [
                            { label: '在职', value: 1 },
                            { label: '在外', value: 2 },
                        ],
                    }),
                    form: {
                        value: 1,
                        component: {
                            span: 24,
                        }
                    },
                },
                color: {
                    title: '标签颜色',
                    search: {
                        show: false,
                    },
                    form: {
                        show: false,
                        rules: [{ required: true, message: '请选择标签颜色' }],
                        component: {
                            span: 24,
                            name: 'el-color-picker',
                            props: {
                                showAlpha: false
                            }
                        },
                    },
                    column: {
                        show: false,
                        width: 80,
                        component: {
                            name: 'el-tag',
                            props: (context: any) => {
                                return {
                                    color: context.row.color,
                                    effect: 'plain',
                                };
                            },
                        },
                    },
                },
                is_system: {
                    title: '系统标签',
                    search: {
                        show: true,
                    },
                    type: 'dict-select',
                    dict: dict({
                        data: [
                            { label: '是', value: true },
                            { label: '否', value: false },
                        ],
                    }),
                    form: {
                        value: false,
                        component: {
                            span: 24,
                        }
                    },
                    column: {
                        width: 160,
                        formatter: (context: any) => {
                            return context.row.is_system ? '是' : '否';
                        },
                        component: {
                            name: 'el-tag',
                            props: (context: any) => {
                                return {
                                    type: context.row.is_system ? '' : 'info',
                                    effect: 'plain',
                                    round: true
                                };
                            },
                        },
                    },
                },
                status: {
                    title: '状态',
                    search: {
                        show: false,
                    },
                    type: 'dict-radio',
                    dict: dict({
                        data: [
                            { label: '启用', value: true },
                            { label: '禁用', value: false },
                        ],
                    }),
                    form: {
                        show: false,
                        value: true,
                        component: {
                            show: false,
                            span: 24,
                        }
                    },
                    column: {
                        show: false,
                        width: 160,  formatter: (context: any) => {
                                return context.row.status ? '启用' : '禁用';
                            },
                            component: {
                                
                                name: 'el-tag',
                                props: (context: any) => {
                                    return {
                                        type: context.row.status ? '' : 'info',
                                        effect: 'plain',
                                        round: true
                                    };
                                },
                            },
                        
                    },
                },
            },
        },
    };
};
