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

import {getStoreOption} from "#/views/system/store/api";
import {getPharmacistTitleOptionApi} from "#/views/doctor/pharmacist/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',
      componentProps: {
        allowClear: true,
        filterOption: (input: string, option: any) => {
          // 自定义过滤逻辑，确保可以根据 name 进行搜索
          return option?.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        showSearch: true,
        // 菜单接口转options格式
        afterFetch: (data: { id: number; name: string }[]) => {
          return data.map((item: any) => ({
            label: item.name,
            value: item.id,
          }));
        },
        api: getStoreOption,
        placeholder: '请选择',
        model: 'multiple',
      },
      fieldName: 'stores',
      formItemClass: 'col-span-6',
      label: '诊所',
      rules: 'required',
    },
  ],
  showDefaultActions: false,
};

export const infoModalFormProps: 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: 'VbenInput',
      fieldName: 'su_id',
      label: 'WxID',
      formItemClass: 'col-span-6',
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
    },
    {
      fieldName: 'otherinfo',
      label: '基础信息',
      component: 'Divider',
      formItemClass: 'col-span-12',
      componentProps: {},
      hideLabel: true,
      renderComponentContent: () => {
        return {
          default: () => {
            return '基础信息';
          },
        };
      },
    },
    {
      component: 'Avatar',
      componentProps: {
        placeholder: '请上传药师头像',
      },
      fieldName: 'avatar',
      formItemClass: 'col-span-12',
      label: '药师头像',
      rules: 'required',
    },
    {
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        filterOption: (input: string, option: any) => {
          // 自定义过滤逻辑，确保可以根据 name 进行搜索
          return option?.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        showSearch: true,
        // 菜单接口转options格式
        afterFetch: (data: { id: number; name: string }[]) => {
          return data.map((item: any) => ({
            label: item.name,
            value: item.id,
          }));
        },
        api: getStoreOption,
        placeholder: '请选择诊所',
        model: 'multiple',
      },
      dependencies: {
        show: (values) => {
          return values.id == null;
        },
        triggerFields: ['id'],
      },
      fieldName: 'store_id',
      formItemClass: 'col-span-6',
      label: '诊所',
      rules: 'required',
    },
    {
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        filterOption: (input: string, option: any) => {
          // 自定义过滤逻辑，确保可以根据 name 进行搜索
          return option?.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        showSearch: true,
        // 菜单接口转options格式
        afterFetch: (data: { id: number; name: string }[]) => {
          return data.map((item: any) => ({
            label: item.name,
            value: item.id,
          }));
        },
        api: getPharmacistTitleOptionApi,
        placeholder: '请选择职称',
      },
      fieldName: 'title_id',
      formItemClass: 'col-span-6',
      label: '职称',
      rules: 'required',
    },
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '请填写药师名称',
      },
      fieldName: 'name',
      formItemClass: 'col-span-6',
      label: '药师名称',
      rules: 'required',
    },
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '请填写手机号码',
      },
      fieldName: 'mobile',
      formItemClass: 'col-span-6',
      label: '手机号码',
      rules: 'required',
    },
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '请填写身份证',
      },
      dependencies: {
        show: (values) => {
          return values.id == null;
        },
        triggerFields: ['id'],
      },
      fieldName: 'idcard',
      formItemClass: 'col-span-6',
      label: '身份证',
      rules: 'required',
    },
    {
      component: 'VbenSelect',
      componentProps: {
        placeholder: '请填选择身份',
        options: [
          {
            label: '中医药师',
            value: 1,
          },
          {
            label: '西医药师',
            value: 2,
          },
        ],
      },
      fieldName: 'type',
      formItemClass: 'col-span-6',
      label: '身份',
      rules: 'required',
    },
    {
      component: 'VbenSelect',
      componentProps: {
        placeholder: '请填选择签名类型',
        options: [
          {
            label: '电子签名',
            value: 1,
          },
          {
            label: '手写签名',
            value: 2,
          },
        ],
      },
      dependencies: {
        show: (values) => {
          return values.id == null;
        },
        triggerFields: ['id'],
      },
      fieldName: 'sign_type',
      formItemClass: 'col-span-6',
      label: '签名类型',
      rules: 'required',
    },
    {
      fieldName: 'otherinfo',
      label: '执业&身份信息',
      component: 'Divider',
      formItemClass: 'col-span-12',
      componentProps: {},
      hideLabel: true,
      renderComponentContent: () => {
        return {
          default: () => {
            return '执业&身份信息';
          },
        };
      },
    },
    {
      component: 'Avatar',
      componentProps: {
        placeholder: '请上传资格证书',
      },
      fieldName: 'qualification',
      formItemClass: 'col-span-6',
      label: '资格证书',
      rules: 'required',
    },
    {
      component: 'Avatar',
      componentProps: {
        placeholder: '请上传执业证书',
      },
      fieldName: 'practicing',
      formItemClass: 'col-span-6',
      label: '执业证书',
      rules: 'required',
    },
    {
      component: 'Avatar',
      componentProps: {
        placeholder: '请上传职称证书',
      },
      fieldName: 'title',
      formItemClass: 'col-span-6',
      label: '职称证书',
      rules: 'required',
    },
    // {
    //   fieldName: 'otherinfo',
    //   label: '身份信息',
    //   component: 'Divider',
    //   formItemClass: 'col-span-12',
    //   componentProps: {},
    //   hideLabel: true,
    //   renderComponentContent: () => {
    //     return {
    //       default: () => {
    //         return '身份信息';
    //       },
    //     };
    //   },
    // },
    {
      component: 'Avatar',
      componentProps: {
        placeholder: '请上传身份证正面',
      },
      fieldName: 'card_up',
      formItemClass: 'col-span-6',
      label: '身份证正面',
      rules: 'required',
    },
    {
      component: 'Avatar',
      componentProps: {
        placeholder: '请上传身份证反面',
      },
      fieldName: 'card_down',
      formItemClass: 'col-span-6',
      label: '身份证反面',
      rules: 'required',
    },
    {
      component: 'Avatar',
      componentProps: {
        placeholder: '请上传签名图片',
      },
      fieldName: 'sign_image',
      formItemClass: 'col-span-6',
      label: '签名图片',
      rules: 'required',
    },
  ],
  showDefaultActions: false,
};
