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

import { getSpecialPrescriptionCategoryOption } from '#/views/business/special-prescription-category/api';

export const modalFormProps: VbenFormProps = {
  wrapperClass: 'grid-cols-12',
  commonConfig: {
    formItemClass: 'col-span-12',
    componentProps: {
      class: 'w-full',
    },
  },
  layout: 'horizontal',
  schema: [
    {
      component: 'VbenInput',
      fieldName: 'id',
      label: 'ID',
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
    },
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '请输入特色方名称',
      },
      fieldName: 'name',
      label: '名称',
      rules: 'required',
      defaultValue: '',
    },
    {
      component: 'ApiSelect',
      componentProps: {
        placeholder: '请选择分类',
        api: getSpecialPrescriptionCategoryOption,
        allowClear: true,
        showSearch: true,
        filterOption: (input: string, option: any) =>
          option?.label?.toLowerCase().includes(input.toLowerCase()),
        afterFetch: (data: { id: number; name: string }[]) =>
          data.map((item) => ({
            label: item.name,
            value: item.id,
          })),
      },
      fieldName: 'category_id',
      label: '分类',
      rules: 'required',
    },
    {
      component: 'Avatar',
      fieldName: 'cover_image',
      label: '封面',
      defaultValue: '',
    },
    {
      component: 'Select',
      componentProps: {
        mode: 'tags',
        placeholder: '输入标签后回车',
      },
      fieldName: 'tags',
      label: '标签',
      rules: 'required',
      defaultValue: [],
    },
    {
      component: 'InputNumber',
      componentProps: {
        placeholder: '展示兜底价/贴',
        min: 0,
        precision: 2,
        style: { width: '100%' },
      },
      fieldName: 'price_per_dose',
      label: '每剂价格',
      formItemClass: 'col-span-6',
      defaultValue: 0,
    },
    {
      component: 'InputNumber',
      componentProps: {
        placeholder: '销量',
        min: 0,
        style: { width: '100%' },
      },
      fieldName: 'sales_count',
      label: '销量',
      formItemClass: 'col-span-6',
      defaultValue: 0,
    },
    {
      component: 'VbenSelect',
      componentProps: {
        placeholder: '请选择状态',
        options: [
          { label: '上架', value: 1 },
          { label: '下架', value: 0 },
        ],
      },
      fieldName: 'status',
      label: '状态',
      formItemClass: 'col-span-6',
      defaultValue: 1,
    },
    {
      component: 'VbenSelect',
      componentProps: {
        placeholder: '请选择处方类型',
        options: [
          { label: '中药', value: 'chinese' },
          { label: '西药', value: 'west' },
          { label: '颗粒药', value: 'granular' },
        ],
      },
      fieldName: 'prescription_type',
      label: '处方类型',
      rules: 'required',
      defaultValue: 'chinese',
    },
    {
      component: 'Editor',
      componentProps: {
        placeholder: '请输入介绍文案',
      },
      fieldName: 'intro_text',
      label: '介绍文案',
      defaultValue: '',
    },
    {
      component: 'UploadImageSortable',
      fieldName: 'introduction_images',
      label: '介绍图',
      formItemClass: 'col-span-12',
      componentProps: {
        maxCount: 20,
        multiple: true,
      },
    },
  ],
  showDefaultActions: false,
};
