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

import { STATUS_OPTIONS } from './constants';

/** 金方新增/编辑表单 */
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',
      fieldName: 'name',
      label: '药方名字',
      rules: 'required',
      componentProps: { placeholder: '如：桂枝汤' },
    },
    {
      component: 'VbenInput',
      fieldName: 'clause_number',
      label: '条文编号',
      help: '典籍条文编号，如「第12条」，可空',
      componentProps: { placeholder: '如：第12条' },
      defaultValue: '',
    },
    {
      component: 'VbenSelect',
      fieldName: 'source_id',
      label: '金方来源',
      help: '选择来源字典；如无合适项可先在「金方来源管理」新增',
      componentProps: {
        showSearch: true,
        optionFilterProp: 'label',
        options: [],
        allowClear: true,
        placeholder: '选择金方来源',
      },
      defaultValue: 0,
    },
    {
      component: 'VbenInput',
      fieldName: 'source',
      label: '来源(旧文本)',
      formItemClass: 'col-span-6',
      componentProps: { placeholder: '如：伤寒论（旧字段，优先用上面的来源选择）' },
      defaultValue: '',
    },
    {
      component: 'VbenSelect',
      fieldName: 'status',
      label: '状态',
      formItemClass: 'col-span-3',
      componentProps: { options: STATUS_OPTIONS },
      defaultValue: 1,
    },
    {
      component: 'InputNumber',
      fieldName: 'sort',
      label: '排序',
      formItemClass: 'col-span-3',
      componentProps: { min: 0 },
      defaultValue: 0,
    },
    {
      component: 'VbenInput',
      fieldName: 'herb_overview',
      label: '药材速览',
      help: '展示用；药方组成请在行操作「药方设置」中维护，保存组成时会按药名重算本字段',
      componentProps: { placeholder: '如：桂枝、芍药、甘草、生姜、大枣' },
      defaultValue: '',
    },
    {
      component: 'VbenInput',
      fieldName: 'original_formula',
      label: '原方',
      help: '典籍药味与服法全文（含煮法、服法、禁忌）',
      componentProps: {
        type: 'textarea',
        rows: 5,
        placeholder:
          '桂枝三两，去皮 芍药三两 甘草二两，炙 生姜三两，切 大枣十二枚，擘。右五味，㕮咀三味，以水七升…',
      },
      defaultValue: '',
    },
    {
      component: 'VbenInput',
      fieldName: 'indication_original',
      label: '主治（原文）',
      componentProps: { type: 'textarea', rows: 2 },
      defaultValue: '',
    },
    {
      component: 'VbenInput',
      fieldName: 'indication_translation',
      label: '主治（译文）',
      componentProps: { type: 'textarea', rows: 2 },
      defaultValue: '',
    },
    {
      component: 'VbenInput',
      fieldName: 'intro',
      label: '简介',
      componentProps: { type: 'textarea', rows: 2 },
      defaultValue: '',
    },
    {
      component: 'VbenInput',
      fieldName: 'cover',
      label: '封面',
      componentProps: { placeholder: '封面图 URL' },
      defaultValue: '',
    },
    {
      component: 'VbenInput',
      fieldName: 'pinyin_initials',
      label: '拼音首拼',
      formItemClass: 'col-span-6',
      componentProps: { placeholder: '可空，保存时按药方名自动生成' },
      defaultValue: '',
    },
    {
      component: 'VbenInput',
      fieldName: 'pinyin',
      label: '拼音全拼',
      formItemClass: 'col-span-6',
      componentProps: { placeholder: '可空，保存时按药方名自动生成' },
      defaultValue: '',
    },
  ],
  showDefaultActions: false,
};
