import type { CustomColumn } from '@/types/table'
import type { ProductList } from '@/types/api/podMakeOrder'

export type PodMakeOrderType = 'cn' | 'us' | 'new'

export const operationStatusMap: Record<string, string> = {
  PENDING_PACKING: '待配货',
  PENDING_SCHEDULE: '待排单',
  PENDING_REPLENISH: '待补胚',
  PENDING_PICK: '待拣胚',
  IN_PRODUCTION: '生产中',
  PACKING_COMPLETED: '配货完成',
  COMPLETED: '已完成',
  CANCELLED: '已取消',
  ARCHIVE: '已归档',
}

export type OperationStatusTagConfig = {
  type?: 'success' | 'warning' | 'info' | 'danger' | 'primary'
  style?: { backgroundColor: string; color: string; borderColor: string }
}

export const operationStatusTagMap: Record<string, OperationStatusTagConfig> = {
  PENDING_PACKING: { type: 'warning' },
  PENDING_SCHEDULE: { type: 'info' },
  PENDING_REPLENISH: {
    style: {
      backgroundColor: '#E6A23C',
      color: '#FFFFFF',
      borderColor: '#E6A23C',
    },
  },
  PENDING_PICK: {
    style: {
      backgroundColor: '#409EFF',
      color: '#FFFFFF',
      borderColor: '#409EFF',
    },
  },
  IN_PRODUCTION: { type: 'primary' },
  PACKING_COMPLETED: { type: 'success' },
  COMPLETED: { type: 'success' },
  CANCELLED: { type: 'danger' },
  ARCHIVE: {
    style: {
      backgroundColor: '#909399',
      color: '#FFFFFF',
      borderColor: '#909399',
    },
  },
}

export function getPodOrderDetailsColumns(options: {
  orderNoName: string
  type: PodMakeOrderType
}): CustomColumn<ProductList>[] {
  const { orderNoName, type } = options

  return [
    {
      label: '图片',
      prop: 'image',
      width: 250,
      slot: 'image',
      align: 'center',
      fixed: 'left',
    },
    {
      label: orderNoName,
      align: 'center',
      slot: 'productionOrderNo',
      showOverflowTooltip: true,
      width: type === 'new' ? 180 : 150,
    },
    {
      label: '库存 SKU',
      prop: 'thirdSkuCode',
      width: 180,
      align: 'center',
      showOverflowTooltip: true,
    },
    {
      label: 'variant SKU',
      prop: 'variantSku',
      width: 160,
      align: 'center',
      showOverflowTooltip: true,
    },
    {
      label: '商品名称',
      prop: 'productName',
      minWidth: 100,
      showOverflowTooltip: true,
    },
    {
      label: '购买数量',
      prop: 'purchaseNumber',
      width: 90,
      align: 'center',
      fixed: 'right',
    },
    {
      label: '拣货数量',
      prop: 'count',
      width: 90,
      align: 'center',
      fixed: 'right',
    },
    {
      label: '验证结果',
      slot: 'verifyResult',
      width: 90,
      align: 'center',
      fixed: 'right',
    },
  ]
}
