import { FormSchema } from '/@/components/Table';
import { getOrganizationList } from '/@/api/system/system';
import { copyTransFun } from '/@/utils/fnUtils';
import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue';
import { createImgPreview } from '/@/components/Preview';
import { uploadThumbnail } from '/@/api/configuration/center/configurationCenter';
export enum Platform {
  PHONE = 0,
  PC = 1,
}

export enum ConfigurationPermission {
  CREATE = 'api:yt:dataview:center:post',
  UPDATE = 'api:yt:dataview:center:update',
  DELETE = 'api:yt:dataview:center:delete',
  DESIGN = 'api:yt:dataview:center:get_configuration_info:design',
  PREVIEW = 'api:yt:dataview:center:get_configuration_info:preview',
}

// 查询字段
export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '大屏名称',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: {
      maxLength: 36,
      placeholder: '请输入大屏名称',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'thumbnail',
    label: '缩略图',
    component: 'ApiUpload',
    changeEvent: 'update:fileList',
    valueField: 'fileList',
    componentProps: () => {
      return {
        listType: 'picture-card',
        maxFileLimit: 1,
        api: async (file: File) => {
          try {
            const formData = new FormData();
            formData.set('file', file);
            const { fileStaticUri, fileName } = await uploadThumbnail(formData);
            return {
              uid: fileStaticUri,
              name: fileName,
              url: fileStaticUri,
            } as FileItem;
          } catch (error) {
            return {};
          }
        },
        onPreview: (fileList: FileItem) => {
          createImgPreview({ imageList: [fileList.url!] });
        },
      };
    },
  },

  {
    field: 'name',
    label: '大屏名称',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入大屏名称',
      maxLength: 255,
    },
  },
  {
    field: 'organizationId',
    label: '所属组织',
    required: true,
    component: 'ApiTreeSelect',
    componentProps: {
      api: async () => {
        const data = await getOrganizationList();
        copyTransFun(data as any as any[]);
        return data;
      },
    },
  },
  // {
  //   field: 'state',
  //   label: '发布状态',
  //   required: true,
  //   component: 'RadioGroup',
  //   defaultValue: Platform.PC,
  //   componentProps: {
  //     defaultValue: Platform.PC,
  //     options: [
  //       { label: '未发布', value: Platform.PC },
  //       { label: '已发布', value: Platform.PHONE },
  //     ],
  //   },
  // },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
            rows: 4,
      allowClear:false,
      placeholder: '请输入备注',
      maxLength: 255,
    },
  },
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: 'id',
    },
  },
];
