import * as api from './api'
import { dict, UserPageQuery, compute, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud'
import { inject } from 'vue'
import { BaseColumn } from '/@/views/adManage/utils/commonTabColumn.js'
import { dynBidStrategyEnum } from '/@/views/adManage/utils/enum.js'

export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
	const pageRequest = async (query: UserPageQuery) => {
		query['profile'] = context['profileId']
		return await api.GetList(query)
	}

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

	return {
		crudOptions: {
			table: {
				height: 800,
			},
			container: {
				fixedHeight: false,
			},
			actionbar: {
				show: false
			},
			search: {
				show: false,
			},
			toolbar: {
				buttons: {
					search: {
						show: true,
					},
					compact: {
						show: false,
					},
				},
			},
			request: {
				pageRequest,
			},
			rowHandle: {
				show: false,
			},
			columns: {
				id: {
					title: 'ID',
					column: {
						show: false,
					},
					form: {
						show: false,
					},
				},
				campaignName: {
					title: '广告活动',
					column: {
						width: '200px',
						fixed: 'left',
					},
					search: {
						show: true,
						component: {
							props: {
								clearable: true,
							},
						},
					},
				},
				placement: {
					title: '广告位',
				},
				dynBidStrategy: {
					title: '竞价策略',
					form: {
						show: false,
					},
					column: {
						width: '160px',
					},
					type: 'dict-select',
					dict: dict({
						data: dynBidStrategyEnum,
					}),
				},
				...BaseColumn,
			},
		},
	}
}
