import { CommonInfoModel } from "@/api/inhert/VillageInfoApi";
import { villageCommonContent } from "./common";
import type { FieldProps } from "@/components/form/Field.vue";
import type { SingleForm } from "../forms";
import MapApi from "@/api/map/MapApi";

export const villageInfoSpotsFormItems : SingleForm = [CommonInfoModel, (form) => ({
  formItems: [
    ...villageCommonContent(form, {
      title: '风景名胜',
      showContent: true,
      showTitle: true,
    }).formItems,
    {
      label: '地理信息',
      name: 'baseInfo',
      type: 'flat-group',
      childrenColProps: {
        span: 24,
      },
      children: [
        { 
          label: '经纬度', 
          name: 'lonlat', 
          type: 'select-lonlat', 
          defaultValue: '',
          additionalProps: {
            onChange(val: [number, number]) {
              if (form.value.getValueByPath('address'))
                return;
              MapApi.regeoAddress(val[0], val[1]).then(res => {
                form.value.setValueByPath('address', res);
              });
            },
          },
          formProps: { showRightArrow: true } as FieldProps,
        }, 
        {
          label: '地址',
          name: 'address',
          type: 'text',
          defaultValue: '',
          additionalProps: {
            placeholder: '请输入地址',
          },
          rules: []
        },
        {
          label: '方位',
          name: 'orientation',
          type: 'text',
          rules: []
        },
        {
          label: '相对距离',
          name: 'distance',
          type: 'text',
          defaultValue: '',
          additionalProps: {
            placeholder: '请输入相对距离',
          },
          rules: []
        },
      ]
    },
  ]
}), { title: '风景名胜', typeName: '', }]