import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet,dict, UserPageQuery } from '@fast-crud/fast-crud';
import * as api from './api';
import { auth } from '/@/utils/authFunction';

export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
	const pageRequest = async (query: UserPageQuery) => {
		return await api.GetList(query);
	};

		const getDetail = async ({ row }: InfoReq) => {
		return await api.GetObj(row.id);
	};

	// 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,
				getDetail,
			},
			toolbar:{
				show:false,
			},
			rowHandle:{
				buttons:{
					remove:{
						show:false,
					},
					edit:{
						show:false,
					}

				}

			},
			actionbar: {
				buttons: {
					add: {
						show: auth('area:Create'),
					},
				},
			},
			pagination: {
				show: false,
			},		
			columns: {
				_index: {
					title: '序号',
					form: { show: false },
					column: {
						type: 'index',
						align: 'center',
						width: '70px',
						columnSetDisabled: true, //禁止在列设置中选择
					},
				},
				code:{
					title:'分类编码',
					type:'input',
					column: {
						minWidth: 120,
					},
					form: {
						show: false,
						
					}
				},
				name: {
					title: '名称',
					search: {
						show: true,
					},
					treeNode: true,
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						rules: [
							// 表单校验规则
							{ required: true, message: '名称必填项' },
						],
						component: {
							placeholder: '请输入名称',
						},
					},
				},
				description:{
					title: '设备描述',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						component: { placeholder: '请填写设备描述' },
						rules: [{ required: false, message: '请填写设备描述' }],
					},
				},
				parent:{
					title: '父级',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						component: { placeholder: '请填写设备父级' },
						rules: [{ required: false, message: '请填写设备父级' }],
					},
				},
				sort:{
					title: '排序',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						component: { placeholder: '请填写排序' },
						rules: [{ required: true, message: '请填写排序' }],
					},
				},
				status:{
					title: '状态',
					type: 'dict-select',
					column: {
						minWidth: 120,
					},
					dict: dict({
						data: [
							{ label: '启用', value: true },
							{ label: '禁用', value: false },
						],
					}),
					form: {
						component: { placeholder: '请填写状态' },
						rules: [{ required: true, message: '请填写状态' }],
					},
				},
				tenant:{
					title: '租户',
					type: 'input',
					value: 1,
					column: {
						show:false,
						minWidth: 120,
					},
					form: {
						show:false,
						component: { placeholder: '请填写租户' },
						rules: [{ required: false, message: '请填写租户' }],
					},
				},
			},
		},
	};
};
