import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, dict, UserPageQuery,compute } 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 addRequest = async ({ form }: AddReq) => {
		return await api.AddObj(form);
	};
	const editRequest = async ({ form }: AddReq) => {
		return await api.UpdateObj(form);
	};
	const delRequest = async ({ row }: AddReq) => {
		return await api.DelObj(row.id);
	};

	return {
		crudOptions: {
			request: {
				pageRequest,
				editRequest,
				delRequest,
				addRequest,
			},
			toolbar:{
				show:false,
			},
			actionbar: {
				buttons: {
					add: {
						show: true,//auth('area:Create'),
					},
				},
			},
			form:{
				wrapper: {
					buttons: {
						ok:{
							text:'提交',
							show:compute((row) => {
								return row.mode !=='view'
							})
						}
					}
				}
			},
			pagination: {
				show: true,
			},		
			columns: {
				_index: {
					title: '序号',
					form: { show: false },
					column: {
						type: 'index',
						align: 'center',
						width: '70px',
						columnSetDisabled: true, //禁止在列设置中选择
					},
				},
				search:{
					title: '关键字搜索',
					search: { show: true,type: 'input', },
					type: 'input',
					form: {
						component: { placeholder: '请输入' },
						show:false},
					column: {show:false}
				},
				code:{
					title: '仓库编码',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						show: false,
						component: { placeholder: '请填写标签颜色' },
						rules: [{ required: true, message: '请填写标签颜色' }],
					},
				},
				name: {
					title: '仓库名称',
					search: {
						show: true,
					},
					treeNode: true,
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						rules: [
							// 表单校验规则
							{ required: true, message: '仓库名称必填项' },
						],
						component: {
							placeholder: '请输入仓库名称',
						},
					},
				},
				location:{
					title: '仓库位置',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						component: { placeholder: '请填写仓库位置' },
						rules: [{ required: true, message: '请填写仓库位置' }],
					},
				},
				manager:{
					title: '管理',
					type: 'input',
					column: {
						show: false,
						minWidth: 120,
					},
					form: {
						value:5,
						show:false,
						component: { placeholder: '请填管理' },
						rules: [{ required: true, message: '请填管理' }],
					},
				},
				remark:{
					title: '仓库说明',
					type: 'input',
					column: {
						minWidth: 120,
					},
					form: {
						component: { placeholder: '请填仓库说明' },
						rules: [{ required: false, message: '请填仓库说明' }],
					},
				},
				tenant_id:{
					title: '租户id',
					type: 'dict-select',
					column: {
						show:false,
						minWidth: 120,
					},
					dict: dict({
						url: '/api/system/tenant/list/',
						value: 'id', 
						label: 'name'
					}),
					form: {
						value:1,
						show:false,
						component: { placeholder: '请填租户id' },
						rules: [{ required: false, message: '请填租户id' }],
					},
				},
				status:{
					title: '状态',
					type: 'dict-select',
					column: {
						show: true,
						minWidth: 120,
					},
					dict: dict({
						data: [
							{ label: '启用', value: true },
							{ label: '禁用', value: false,color:'danger' },
						],
					}),
					form: {
						component: { placeholder: '请填写状态' },
						rules: [{ required: true, message: '请填写状态' }],
					},
				},
				
			},
		},
	};
};
