import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

export function useOrderColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: 'ID',
      width: 80,
    },
    {
      field: 'agent_id',
      title: '代理ID',
      width: 100,
    },
    {
      field: 'order_id',
      title: '订单ID',
      width: 100,
    },
    {
      field: 'product_id',
      title: '产品ID',
      width: 100,
    },
    {
      field: 'product_name',
      title: '产品名称',
      width: 150,
    },
    {
      field: 'order_amount',
      title: '订单金额',
      width: 120,
      formatter: ({ cellValue }: { cellValue: number }) =>
        `¥${cellValue.toFixed(2)}`,
    },
    {
      field: 'set_price',
      title: '设定价格',
      width: 120,
      formatter: ({ cellValue }: { cellValue: number }) =>
        `¥${cellValue.toFixed(2)}`,
    },
    {
      field: 'actual_base_price',
      title: '实际底价',
      width: 120,
      formatter: ({ cellValue }: { cellValue: number }) =>
        `¥${cellValue.toFixed(2)}`,
    },
    {
      field: 'price_cost',
      title: '提价成本',
      width: 120,
      formatter: ({ cellValue }: { cellValue: number }) =>
        `¥${cellValue.toFixed(2)}`,
    },
    {
      field: 'agent_profit',
      title: '代理收益',
      width: 120,
      formatter: ({ cellValue }: { cellValue: number }) =>
        `¥${cellValue.toFixed(2)}`,
    },
    {
      field: 'order_status',
      title: '订单状态',
      width: 120,
      cellRender: {
        name: 'CellTag',
        options: [
          { value: 'pending', color: 'warning', label: '待支付' },
          { value: 'paid', color: 'success', label: '已支付' },
          { value: 'refunded', color: 'error', label: '已退款' },
          { value: 'closed', color: 'default', label: '已关闭' },
          { value: 'failed', color: 'error', label: '支付失败' },
          { value: 'unknown', color: 'default', label: '未知' },
        ],
      },
    },
    {
      field: 'create_time',
      title: '创建时间',
      width: 160,
      sortable: true,
    },
  ] as const;
}

export function useOrderFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'InputNumber',
      fieldName: 'agent_id',
      label: '代理ID',
    },
    {
      component: 'InputNumber',
      fieldName: 'order_id',
      label: '订单ID',
    },
    {
      component: 'Select',
      fieldName: 'order_status',
      label: '订单状态',
      componentProps: {
        allowClear: true,
        options: [
          { label: '待支付', value: 'pending' },
          { label: '已支付', value: 'paid' },
          { label: '已退款', value: 'refunded' },
          { label: '已关闭', value: 'closed' },
          { label: '支付失败', value: 'failed' },
        ],
      },
    },
  ];
}

