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

import {
  getWarehouseDrugManagementStoreOption
} from "../api";


export const modalFormProps: VbenFormProps = {
  wrapperClass: 'grid-cols-12', // 24栅格,
  commonConfig: {
    formItemClass: 'col-span-12',
    // 所有表单项
    componentProps: {
      class: 'w-full',
    },
  },
  // handleSubmit: onSubmit,
  layout: 'horizontal',
  schema: [
    {
      component: 'VbenInput',
      fieldName: 'id',
      label: 'ID',
      formItemClass: 'col-span-6',
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
    },
    {
      component: 'ApiSelect',
      fieldName: 'drug_id',
      label: '选择加入的药品',
      formItemClass: 'col-span-12',
      rules: 'required',
      componentProps: {
        api: getWarehouseDrugManagementStoreOption,
        allowClear: true,
        showSearch: true,
        filterOption: (input: string, option: any) => {
          // 自定义过滤逻辑，确保可以根据 name 进行搜索
          return option?.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        // 菜单接口转options格式
        afterFetch: (data: { drug_name: string; id: number }[]) => {
          return data.map((item: any) => ({
            label: `${item.drug_name}【${item.pinyin_simple}】`,
            value: item.id,
          }));
        },
      },
      dependencies: {
        show(formValues: any) {
          return !formValues.id;
        },
        triggerFields: ['id'],
      },
    },
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '请输入价格',
      },
      fieldName: 'price',
      formItemClass: 'col-span-12',
      label: '价格',
      rules: 'required',
      // 绑定配送仓时禁用改价；区间提示由弹窗文案补充
      dependencies: {
        disabled(values: any) {
          return Number(values?.has_delivery_warehouse) === 1;
        },
        triggerFields: ['has_delivery_warehouse'],
      },
    },
    {
      component: 'VbenInput',
      fieldName: 'has_delivery_warehouse',
      label: '配送仓',
      dependencies: {
        show: false,
        triggerFields: ['has_delivery_warehouse'],
      },
    },
    {
      component: 'VbenInput',
      fieldName: 'min_adjust_price',
      label: '底价',
      dependencies: {
        show: false,
        triggerFields: ['min_adjust_price'],
      },
    },
    {
      component: 'VbenInput',
      fieldName: 'max_adjust_price',
      label: '最高价',
      dependencies: {
        show: false,
        triggerFields: ['max_adjust_price'],
      },
    },
  ],
  showDefaultActions: false,
};
export const uploadExcelProps: VbenFormProps = {
  wrapperClass: 'grid-cols-12', // 24栅格,
  commonConfig: {
    formItemClass: 'col-span-12',
    // 所有表单项
    componentProps: {
      class: 'w-full',
    },
  },
  // handleSubmit: onSubmit,
  layout: 'horizontal',
  schema: [
    {
      component: 'Upload',
      componentProps: {
        placeholder: '请选择',
        multiple: true,
      },
      fieldName: 'frequency_id',
      formItemClass: 'col-span-12',
      label: '导入excel',
      rules: 'file',
    },
  ],
  showDefaultActions: false,
};
