import type { VxeGridProps } from '#/adapter/vxe-table';

import { getWarehouseDrugManagementStoreList } from '../api';

interface RowType {
  id: string;
  name: string;
  logo: string;
  introduce: string;
  created_at: string;
}

export function createGridOptions(productType: number): VxeGridProps<RowType> {
  return {
    checkboxConfig: {
      highlight: true,
      labelField: '',
    },
    columnConfig: {
      useKey: true,
    },
    rowConfig: {
      useKey: true,
    },
    columns: [
      { type: 'checkbox', width: 60 },
      { field: 'id', align: 'left', title: 'ID', width: 100 },
      { field: 'drug.drug_name', align: 'left', title: '药品名称' },
      { field: 'drug.pinyin_simple', title: '拼音' },
      {
        field: 'image',
        align: 'left',
        title: '产品图片',
        slots: { default: 'image' },
        width: 130,
      },
      { field: 'buy_price', title: '供货价' },
      { field: 'drug.drug_store_drug.price', title: '建议售价' },
      { field: 'price', title: '售价' },
      { field: 'status', title: '状态', slots: { default: 'status' } },
      {
        type: 'html',
        align: 'right',
        title: '操作',
        slots: { default: 'action' },
        width: 300,
      },
    ],
    keepSource: true,
    pagerConfig: {},
    proxyConfig: {
      ajax: {
        query: async ({ page }, formValues) => {
          return await getWarehouseDrugManagementStoreList({
            page: page.currentPage,
            pageSize: page.pageSize,
            type: productType,
            ...formValues,
          });
        },
      },
    },
    height: 'auto',
    border: false,
    toolbarConfig: {
      search: true,
      refresh: true,
      print: false,
      export: false,
      zoom: true,
      slots: {
        buttons: 'toolbar-buttons',
      },
      custom: {
        icon: 'vxe-icon-menu',
      },
    },
    showOverflow: false,
  };
}
