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

import { getStoreOption } from '#/views/system/store/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',
      defaultValue: '',
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
    },
    {
      component: 'ApiSelect',
      componentProps: {
        placeholder: '请选择绑定店铺（留空为平台通用）',
        allowClear: true,
        showSearch: true,
        filterOption: (input: string, option: any) => {
          return option.label?.toLowerCase().includes(input.toLowerCase());
        },
        api: async () => {
          const res = await getStoreOption({});
          // 添加"平台通用"选项
          const options = [
            { label: '平台通用', value: 0 },
            ...(res || []).map((item: any) => ({
              label: item.name || item.label,
              value: item.id || item.value,
            })),
          ];
          return options;
        },
      },
      fieldName: 'store_id',
      label: '绑定店铺',
      formItemClass: 'col-span-12',
      defaultValue: 0,
    },
    {
      component: 'Avatar',
      fieldName: 'drug_license_image',
      label: '药品经营许可证',
      formItemClass: 'col-span-4',
    },
    {
      component: 'Avatar',
      fieldName: 'business_license_image',
      label: '营业执照',
      formItemClass: 'col-span-4',
    },
    {
      component: 'Avatar',
      fieldName: 'medical_device_license_image',
      label: '医疗器械经营许可证',
      formItemClass: 'col-span-4',
    },
    {
      component: 'Avatar',
      fieldName: 'food_license_image',
      label: '食品经营许可证',
      formItemClass: 'col-span-4',
    },
    {
      component: 'Avatar',
      fieldName: 'pharmacist_certificate_image',
      label: '药师资格证',
      formItemClass: 'col-span-4',
    },
    {
      component: 'Avatar',
      fieldName: 'internet_drug_license_image',
      label: '互联网药品经营许可证',
      formItemClass: 'col-span-4',
    },
    {
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入排序顺序',
        min: 0,
      },
      // dependencies: {
      //   show: false,
      //   triggerFields: ['id'],
      // },
      fieldName: 'sort_order',
      label: '排序顺序',
      formItemClass: 'col-span-6',
      defaultValue: 0,
    },
    {
      component: 'VbenSelect',
      componentProps: {
        placeholder: '请选择状态',
        options: [
          { label: '启用', value: 1 },
          { label: '禁用', value: 0 },
        ],
      },
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
      fieldName: 'status',
      label: '状态',
      formItemClass: 'col-span-6',
      defaultValue: 1,
    },
  ],
  showDefaultActions: false,
};
