import VillageInfoApi, { CommonInfoModel } from "@/api/inhert/VillageInfoApi";
import type { CheckBoxToIntProps } from "@/components/dynamic/wrappers/CheckBoxToInt";
import type { PickerIdFieldProps } from "@/components/dynamic/wrappers/PickerIdField";
import type { FieldProps } from "@/components/form/Field.vue";
import type { SingleForm } from "../forms";
import { villageCommonContent } from "./common";

export const ichFormItems : SingleForm = [CommonInfoModel, (m) => ({
  formItems: [
    {
      label: '非遗基础信息', 
      name: 'a', 
      type: 'flat-group', 
      childrenColProps: {
        span: 24,
      },
      children: [
        {
          label: '名称及管理编号', 
          name: 'name', 
          type: 'text', 
          defaultValue: '',
          additionalProps: {
            placeholder: '请输入名称',
          },
          rules:  [{
            required: true,
            message: '请输入名称',
          }] 
        }, 
        {
          label: '编号', 
          name: 'code', 
          type: 'text', 
          defaultValue: '',
          additionalProps: {
            placeholder: '请输入编号',
          },
          rules:  [{
            required: true,
            message: '请输入编号',
          }] 
        },
        {
          label: '级别', 
          name: 'ichLevel',
          type: 'select-id', 
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(111))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择级别',
          }],
        },
        {
          label: '类型', 
          name: 'ichType',
          type: 'select-id', 
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(4))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择类型',
          }],
        },
      ]
    },
    ...villageCommonContent(m, {
      title: '非遗',
      showTitle: false,
    }).formItems,
    {
      label: '传承人信息', 
      name: 'b', 
      type: 'flat-group', 
      childrenColProps: {
        span: 24,
      },
      children: [
        {
          label: '是否确定传承人', 
          name: 'isInheritor', 
          type: 'check-box-int', 
          defaultValue: 0,
          additionalProps: {
            text: '是',
          } as CheckBoxToIntProps ,
          rules:  [{
            required: true,
            message: '请选择是否确定传承人',
          }] 
        },
        {
          label: '传承人情况',
          name: 'inheritor',
          type: 'richtext',
          defaultValue: '',
          show: { callback: (_, m) => m.isInheritor == 1 },
          additionalProps: {
            placeholder: '请输入传承人情况',
            maxLength: 200,
            showWordLimit: true, 
          },
          rules:  [{
            required: true,
            message: '请输入输入传承人情况',
          }]
        },
        {
          label: '加入时间', 
          name: 'joinAt',
          type: 'datetime', 
          additionalProps: {
            type: 'datetime',
          },
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择加入时间',
          }],
        },
      ]
    },
    
    {
      label: '详细信息', 
      name: 'c', 
      type: 'flat-group', 
      childrenColProps: {
        span: 24,
      },
      children: [
        {
          label: '项目续存情况', 
          name: 'ichExistenceStatus',
          type: 'select-id', 
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(120))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择项目续存情况',
          }],
        },
        {
          label: '与村社依存程度', 
          name: 'ichDependenceDegree',
          type: 'select-id', 
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(124))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择与村社依存程度',
          }],
        },
        {
          label: '活动规模', 
          name: 'activityScale',
          type: 'select-id',
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(142))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择活动规模',
          }],
        },
        {
          label: '传承时间', 
          name: 'inheritanceTime',
          type: 'select-id', 
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(147))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择传承时间',
          }],
        },
        {
          label: '具体传承时间', 
          name: 'otherInheritanceTime',
          type: 'datetime', 
          show: { callback(model, rawModel) {
            return (rawModel.inheritanceTime == 150);
          } },
          additionalProps: {
            type: 'datetime',
          },
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择具体传承时间',
          }],
        },
      ]
    },
  ] 
}), { title: '非遗基础信息', typeName: '', }]
