import * as api from './api'
import { dict, UserPageQuery, compute, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud'
import { inject } from 'vue'
import { SpCampaignPuchasedOtherProductsColumn } from '/@/views/adManage/utils/commonTabColumn.js'
import { parseQueryParams } from '/@/views/adManage/utils/tools.js'
import XEUtils from 'xe-utils'

export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
	const pageRequest = async (query: UserPageQuery) => {
		const params = parseQueryParams(context.value)
		XEUtils.assign(query, params)
		return await api.GetList(query)
	}

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

	return {
		crudOptions: {
			table: {
				height: 800,
				headerCellStyle: {
					backgroundColor: '#f6f7fa', // 直接设置背景颜色
					height: '20px',
					borderRight: 'none',
				},
				cellStyle: {
					border: 'none',
					borderBottom: '0.5px solid #ddd',
				},
				showSummary: true,
				stripe: false
			},
			container: {
				fixedHeight: false,
			},
			actionbar: {
				show: false,
			},
			search: {
				show: false,
			},
			toolbar: {
				buttons: {
					search: {
						show: true,
					},
					compact: {
						show: false,
					},
				},
			},
			request: {
				pageRequest,
			},
			rowHandle: {
				show: false,
			},
			columns: {
				adProduct: {
					title: '推广商品',
					column: {
						width: '250px',
					},
				},
				purchasedProduct: {
					title: '购买的其它商品',
				},
				state: {
					title: '状态',
				},
				campaignName: {
					title: '广告活动名称',
					column: {
						width: '200px',
					},
					search: {
						show: true,
						component: {
							props: {
								clearable: true,
							},
						},
					},
					form: {
						rules: [{ required: true, message: '必填项' }],
					},
				},
				adGroupName: {
					title: '广告组名称',
					column: {
						width: '200px',
					},
				},
				matchType: {
					title: '定向',
				},
				...SpCampaignPuchasedOtherProductsColumn,
			},
		},
	}
}
