import * as api from './api'
import {CreateCrudOptionsProps, CreateCrudOptionsRet, dict, UserPageQuery} 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: {
        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,
      },
      search: {
        show: true,
        buttons: {
					search: {
						show: false
					},
					reset: {
						show: false
					}
				}
      },
      request: {
        pageRequest,
      },
      rowHandle: {
        show: false,
      },
      columns: {
        resolvedExpression_value: {
          title: '商品和分类',
          column: {
            width: '200px',
            fixed: 'left',
            align: 'left',
          },
        },
        state: {
          title: '状态',
          column: {
            width: '90px',
            align: 'center',
            sortable: true,
          },
          type: 'dict-select',
          search: {
            show: true
          },
          dict: dict({
            data: [
              {value: 'paused', label: '已暂停', color: 'warning'},
              {value: 'enabled', label: '投放中', color: 'success'},
            ]
          })
        },
        ASIN: {
          title: 'ASIN',
          column: {
            width: '130px',
            align: 'center',
          },
        },
        suggestedBid: {
          title: '建议竞价',
          column: {
            width: '100px',
            align: 'center',
          },
        },
        bid: {
          title: '出价',
          column: {
            width: '60px',
            align: 'center',
          },
        },
        // '分时': {
        //   title: '分时调价',
        //   column: {
        //     width: '100px',
        //     align: 'right',
        //   }
        // },

        ...BaseColumn,
      },
    },
  }
}
