import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, 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 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);
	};

	/**
	 * 懒加载
	 * @param row
	 * @returns {Promise<unknown>}
	 */
	// const loadContentMethod = (tree: any, treeNode: any, resolve: Function) => {
	// 	pageRequest({ pcode: tree.code }).then((res: APIResponseData) => {
	// 		resolve(res.data);
	// 	});
	// };

	return {
		crudOptions: {
			request: {
				pageRequest,
				addRequest,
			},
			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, //禁止在列设置中选择
					},
				},
				name: {
					title: '名称',
					search: {
						show: true,
					},
					treeNode: true,
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						rules: [
							// 表单校验规则
							{ required: true, message: '名称必填项' },
						],
						component: {
							placeholder: '请输入名称',
						},
					},
				},
				color:{
					title: '颜色',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						component: { placeholder: '请填写标签颜色' },
						rules: [{ required: true, message: '请填写标签颜色' }],
					},
				},
				description:{
					title: '标签描述',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						component: { placeholder: '请填写标签描述' },
						rules: [{ required: true, message: '请填写标签描述' }],
					},
				},
				sort:{
					title: '排序',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						component: { placeholder: '请填写排序' },
						rules: [{ required: true, message: '请填写排序' }],
					},
				},
			},
		},
	};
};
