import * as api from './api'
import {CreateCrudOptionsProps, CreateCrudOptionsRet, UserPageQuery} from '@fast-crud/fast-crud'
import {parseQueryParams} from '/@/views/adManage/utils/tools.js'
import XEUtils from 'xe-utils'
import {sbCampaignPlacementEnum, spCampaignPlacementEnum} from '/@/views/adManage/utils/enum'
import {BaseColumn} from '/@/views/adManage/utils/commonTabColumn'

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)
	}


	return {
		crudOptions: {
				table: {
					height: 750,
					headerCellStyle: {
						backgroundColor: '#f6f7fa', // 直接设置背景颜色
						height: '20px',
						// border: '0.5px solid #ddd',
					},
					cellStyle: {
						border: 'none',
						borderBottom: '0.5px solid #ddd',
					},
				},
			container: {
        fixedHeight: false
      },
			actionbar: {
				show: false,
				buttons: {
					add: {
						show: false
					}
				}
			},
			search: {
				show: true,
				buttons: {
					search: {
						show: false
					},
					reset: {
						show: false
					}
				}
			},
			toolbar: {
        buttons: {
					search: {
						show: true
					},
					compact: {
						show: false
					},
				}
			},
			request: {
				pageRequest,
			},
			pagination: {
				show: false
			},
			rowHandle: {
        show: false
      },
			columns: {
        placement: {
          title: '广告位',
          column: {
            width: '200px',
						fixed: 'left',
						formatter({ value, row, index }){
								return XEUtils.find(sbCampaignPlacementEnum, (item) => item.value === value).label
						}
          }
        },
				bidAdjustment: {
					title: '竞价调整'
				},
        ...BaseColumn
			}
		}
	}
}
