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 { 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: {},
      container: {
        fixedHeight: false,
      },
      actionbar: {
        show: false,
      },
      search: {
        show: true,
        buttons: {
					search: {
						show: false
					},
					reset: {
						show: false
					}
				}
      },
      // toolbar: {
      //   buttons: {
      //     search: {
      //       show: true,
      //     },
      //     compact: {
      //       show: false,
      //     },
      //   },
      // },
      request: {
        pageRequest,
      },
      rowHandle: {
        show: false,
      },
      columns: {
        searchTerm: {
          title: '搜索词',
          column: {
            width: '200px',
            fixed: 'left',
          },
        },
        targeting: {
          title: '定向',
          column: {
            width: '200px'
          },
        },
        matchType: {
          title: '匹配类型',
          column: {
            width: '100px',
            align: 'center'
          },
        },
        ...BaseColumn,
      },
    },
  }
}
