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

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,
        rowKey: (row: any) => row.keywordId + row.searchTerm,
        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: {
        searchTerm: {
          title: '搜索词',
          column: {
            width: 130,
            fixed: 'left',
          },
        },
        matchType: {
          title: '定向',
          column: {
            width: 90,
          },
        },
        campaignName: {
          title: '广告活动',
          column: {
            width: 180,
          },
        },
        adGroupName: {
          title: '广告组',
          column: {
            width: 180,
          },
        },
        ...BaseColumn,
      },
    },
  }
}
