import type { VbenFormProps } from '#/adapter/form';
import {getDoctorArticleCategoryOption} from "#/views/doctor/doctor-article/api";

export const modalFormProps: VbenFormProps = {
  wrapperClass: 'grid-cols-12', // 24栅格,
  commonConfig: {
    formItemClass: 'col-span-12',
    // 所有表单项
    componentProps: {
      class: 'w-full',
    },
  },
  // handleSubmit: onSubmit,
  layout: 'horizontal',
  schema: [
    // {
    //   fieldName: 'baseinfo',
    //   component: 'Divider',
    //   label: '基础信息',
    //   formItemClass: 'col-span-12',
    //   componentProps: {},
    //   hideLabel: true,
    //   renderComponentContent: () => {
    //     return {
    //       default: () => {
    //         return '基础信息';
    //       },
    //     };
    //   },
    // },
    {
      component: 'VbenInput',
      fieldName: 'id',
      label: 'ID',
      formItemClass: 'col-span-6',
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
    },
    {
      component: 'Avatar',
      componentProps: {
        placeholder: '请上传图片封面',
      },
      fieldName: 'cover',
      label: '图片封面',
      rules: 'required',
    },
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '请输入文章标题',
      },
      fieldName: 'title',
      label: '文章标题',
      rules: 'required',
    },
    {
      component: 'ApiSelect',
      componentProps: {
        placeholder: '请选择',
        api: getDoctorArticleCategoryOption,
        allowClear: true,
        showSearch: true,
        filterOption: (input: string, option: any) => {
          // 自定义过滤逻辑，确保可以根据 name 进行搜索
          return option?.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        // 菜单接口转options格式
        afterFetch: (data: { id: number; name: string }[]) => {
          return data.map((item: any) => ({
            label: `${item.name}`,
            value: item.id,
          }));
        },
      },
      fieldName: 'cid',
      label: '文章分类',
      rules: 'required',
    },
    {
      component: 'RadioGroup',
      componentProps: {
        placeholder: '选择是否草稿',
        options: [
          {
            label: '是',
            value: 1,
          },
          {
            label: '否',
            value: 0,
          },
        ],
      },
      fieldName: 'is_draft',
      defaultValue: 0,
      label: '文章草稿',
      rules: 'required',
    },
    {
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入简介',
      },
      fieldName: 'intro',
      label: '文章简介',
      rules: 'required',
    },
    {
      component: 'Editor',
      componentProps: {
        placeholder: '请输入文章介绍',
      },
      fieldName: 'content',
      label: '文章内容',
      rules: 'required',
    },
  ],
  showDefaultActions: false,
};
