import * as api from './api';
import { dict, UserPageQuery, AddReq, DelReq, EditReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
import { inject, nextTick, ref } from 'vue';
import { successMessage } from '/@/utils/message';
import { BaseColumn } from '/@/views/adManage/utils/commonTabColumn.js';

export const createCrudOptions = function ({ crudExpose, context }: 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);
	};

	//权限判定
	const hasPermissions = inject('$hasPermissions');

	return {
		crudOptions: {
			table: {
				height: 800,
				size: "small",
			},
			container: {
        fixedHeight: false
      },
			request: {
				pageRequest,
				addRequest,
				editRequest,
				delRequest,
			},
			rowHandle: {
				fixed: 'right',
				width: 80,
				buttons: {
					view: {
						show: false,
					},
					edit: {
						iconRight: 'Edit',
						type: 'text',
            text: null
						// show: hasPermissions('dictionary:Update'),
					},
					remove: {
						iconRight: 'Delete',
						type: 'text',
            text: null
						// show: hasPermissions('dictionary:Delete'),
					},
					// custom: {
					// 	text: '字典配置',
					// 	type: 'text',
					// 	// show: hasPermissions('dictionary:Update'),
					// 	tooltip: {
					// 		placement: 'top',
					// 		content: '字典配置',
					// 	},
					// 	//@ts-ignore
					// 	click: (ctx: any) => {
					// 		const { row } = ctx;
					// 		context!.subDictRef.value.drawer = true;
					// 		nextTick(() => {
					// 			context!.subDictRef.value.setSearchFormData({ form: { parent: row.id } });
					// 			context!.subDictRef.value.doRefresh();
					// 		});
					// 	},
					// },
				},
			},
			columns: {
				// _index: {
				// 	title: '序号',
				// 	form: { show: false },
				// 	column: {
				// 		//type: 'index',
				// 		align: 'center',
				// 		width: '70px',
				// 		columnSetDisabled: true, //禁止在列设置中选择
				// 		formatter: (context) => {
				// 			//计算序号,你可以自定义计算规则，此处为翻页累加
				// 			let index = context.index ?? 1;
				// 			let pagination = crudExpose!.crudBinding.value.pagination;
				// 			// @ts-ignore
				// 			return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
				// 		},
				// 	},
				// },
        name: {
          title: '广告活动',
          column: {
            width: '150px'
          },
					search: {
						show: true,
						component: {
							props: {
								clearable: true
							}
						}
					},
					form: {
						rules: [{required: true, message:'必填项'}]
					}
        }
			}
		}
	}
}
