import { 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 { UploaderFieldProps } from "@/components/form/UploaderField.vue";
import type { SingleForm } from "../forms";
import { villageCommonContent } from "./common";
import type { RadioIdFieldProps } from "@/components/dynamic/wrappers/RadioIdField";

export const villageInfoSpeakerForm : 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: '请输入姓名',
          }]
        },
        ...villageCommonContent(r, {
          title: '口述人',
          showTitle: false,
          showContent: true,
          noType: true,
        }).formItems,
        {
          label: '性别',
          name: 'sex',
          type: 'radio-id',
          defaultValue: 3,
          additionalProps: {
            loadData: async () => [
              { value: 1, text: '男' },
              { value: 2, text: '女' },
              { value: 3, text: '未知' },
            ],
          } as RadioIdFieldProps,
          rules: [{
            required: true,
            message: '请选择性别',
          }]
        },
        {
          label: '联系方式',
          name: 'mobile',
          type: 'text',
          defaultValue: '',
          additionalProps: {
            placeholder: '请输入联系方式',
          },
          rules: []
        },
        {
          label: '生日',
          name: 'birth',
          type: 'datetime',
          defaultValue: '',
          additionalProps: {
            type: 'date',
          },
          formProps: { showRightArrow: true } as FieldProps,
        },
      ]
    },
    {
      label: '媒体信息',
      name: 'mediaInfo',
      type: 'flat-group',
      childrenColProps: {
        span: 24,
      },
      children: [
        {
          label: '头像',
          name: 'image',
          type: 'uploader',
          defaultValue: '',
          additionalProps: {
            upload: useAliOssUploadCo('xiangyuan/speaker'),
            maxFileSize: 1024 * 1024 * 20,
            maxUploadCount: 1,
          } as UploaderFieldProps,
          rules: []
        },
        {
          label: '头像说明',
          name: 'image_desc',
          type: 'text',
          defaultValue: '',
          additionalProps: {
            placeholder: '请输入头像说明',
          },
          rules: []
        },
        {
          label: '音频',
          name: 'audio',
          type: 'uploader',
          defaultValue: '',
          additionalProps: {
            upload: useAliOssUploadCo('xiangyuan/speaker/audio'),
            maxFileSize: 1024 * 1024 * 500, // 500MB
            maxUploadCount: 1,
            accept: 'audio/*',
          } as UploaderFieldProps,
          rules: []
        },
      ]
    },
  ]
}), { title: '口述人', typeName: '', }]