import VillageInfoApi, { CommonInfoModel } from "@/api/inhert/VillageInfoApi";
import { useAliOssUploadCo } from "@/common/components/upload/AliOssUploadCo";
import type { PickerIdFieldProps } from "@/components/dynamic/wrappers/PickerIdField";
import type { FieldProps } from "@/components/form/Field.vue";
import type { StepperProps } from "@/components/form/Stepper.vue";
import type { UploaderFieldProps } from "@/components/form/UploaderField.vue";
import type { SingleForm } from "../forms";
import { villageCommonContent } from "./common";

export const villageInfoRelicForm : SingleForm = [CommonInfoModel, (r) => ({
  formItems: [
    {
      label: '基础信息',
      name: 'baseInfo',
      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: 'age',
          type: 'select-id', 
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(103))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择年代',
          }],
        },
        {
          label: '保护级别', 
          name: 'level',
          type: 'select-id', 
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(158))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择保护级别',
          }],
        },
        {
          label: '文物类型', 
          name: 'crType',
          type: 'select-id', 
          additionalProps: {
            loadData: async () => 
            (await VillageInfoApi.getCategoryChildList(3))
              .map((p) => ({
                value: p.id,
                text: p.title,
              }))
            ,
          } as PickerIdFieldProps,
          formProps: { showRightArrow: true } as FieldProps,
          rules: [{
            required: true,
            message: '请选择文物类型',
          }],
        },
      ]
    },
    {
      label: '介绍',
      name: 'introdInfo',
      type: 'flat-group',
      childrenColProps: { span: 24 },
      children: [
        {
          label: '描述', 
          name: 'description', 
          type: 'richtext', 
          defaultValue: '',
          additionalProps: {
            placeholder: '请输入简介',
            maxLength: 200,
            showWordLimit: true, 
          },
          rules:  [{
            required: true,
            message: '请输入描述',
          }] 
        },
        {
          label: '图片', 
          name: 'images', 
          type: 'uploader', 
          defaultValue: '',
          additionalProps: {
            upload: useAliOssUploadCo('xiangyuan/relic'),
            maxFileSize: 1024 * 1024 * 20,
            maxUploadCount: 20,
          } as UploaderFieldProps,
          rules:  [] 
        },
        {
          label: '文化故事', 
          name: 'content', 
          type: 'richtext', 
          defaultValue: '',
          additionalProps: { 
            placeholder: '输入关于此文物的历史文化故事',
            maxLength: 5000,
            showWordLimit: true, 
          } as FieldProps,
          rules: []
        },
        ...villageCommonContent(r, {
          title: '文物古迹',
          showContent: false,
          showTitle: false,
        }).formItems
      ]
    },
    {
      label: '位置信息',
      name: 'locationInfo',
      type: 'flat-group',
      childrenColProps: { span: 24 },
      children: [
        {
          label: '经纬度', 
          name: 'lonlat', 
          type: 'select-lonlat', 
          defaultValue: '',
          additionalProps: {},
          formProps: { showRightArrow: true } as FieldProps,
          rules:  [{
            required: true,
            message: '请输入经纬度',
          }]
        }, 
        {
          label: '地址', 
          name: 'address', 
          type: 'select-address', 
          defaultValue: '',
          additionalProps: {},
          rules:  [{
            required: true,
            message: '请输入地址',
          }] 
        },
        {
          label: '方位', 
          name: 'orientation', 
          type: 'text', 
          defaultValue: '',
          additionalProps: { placeholder: '方位' },
          rules: []
        },
        {
          label: '相对距离', 
          name: 'distance', 
          type: 'text', 
          defaultValue: '',
          additionalProps: { placeholder: '相对距离' },
          rules: []
        },
        {
          name: '',
          label: '平面坐标XY',
          type: 'flat-simple',
          children: [
            { 
              label: '', 
              name: 'mapX', 
              type: 'number', 
              defaultValue: 0,
              additionalProps: {
                min: -250,
                max: 250,
              } as StepperProps,
              formProps: {
                labelWidth: '0rpx',
                labelPosition: 'left',
                showBottomBorder: false,
              },
              rules:  [{
                required: true,
                message: '请输入X',
              }] 
            },
            { 
              label: '', 
              name: 'mapY', 
              type: 'number', 
              defaultValue: 0,
              additionalProps: {
                min: -250,
                max: 250,
              } as StepperProps,
              formProps: {
                labelWidth: '0rpx',
                labelPosition: 'left',
                showBottomBorder: false,
              },
              rules:  [{
                required: true,
                message: '请输入Y',
              }] 
            },
          ]
        },
      ]
    },


    
  ] 
}), { title: '文物古迹', typeName: '', }];