import type { VbenFormProps } from '#/adapter/form';

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

/**
 * 仓侧「我的商品」顶部搜索
 * 字段与后端 queryField 对齐：名称模糊、类型/审核/状态精确
 */
export const formOptions: VbenFormProps = {
  collapsed: false,
  schema: [
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '输入药品名称',
        allowClear: true,
      },
      fieldName: 'drug_name',
      label: '药品名称',
    },
    {
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        showSearch: true,
        filterOption: (input: string, option: any) =>
          option?.label?.toLowerCase?.().indexOf(input.toLowerCase()) >= 0,
        // type-options 已是 { label, value }
        afterFetch: (data: { label: string; value: number }[]) =>
          (data || []).map((item) => ({
            label: item.label,
            value: item.value,
          })),
        api: getDeliveryWarehouseProductTypeOptions,
        placeholder: '请选择类型',
      },
      fieldName: 'type',
      label: '商品类型',
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        placeholder: '请选择审核状态',
        options: [
          { label: '待审核', value: 0 },
          { label: '已审核', value: 1 },
        ],
      },
      fieldName: 'audit_status',
      label: '审核状态',
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        placeholder: '请选择商品状态',
        options: [
          { label: '草稿', value: 1 },
          { label: '下架', value: 2 },
          { label: '上架', value: 3 },
        ],
      },
      fieldName: 'status',
      label: '商品状态',
    },
  ],
  showCollapseButton: true,
  submitButtonOptions: {
    content: '查询',
  },
  submitOnChange: true,
  submitOnEnter: false,
};
