import { FileUploaderEditorModel } from '@ibiz-template/model';
import {
  FormItemController,
  GridEditItemController,
  IEditorProvider,
  UploadEditorController,
} from '@ibiz-template/controller';
/**
 * 文件上传编辑器适配器
 *
 * @author lxm
 * @date 2022-09-19 22:09:03
 * @export
 * @class FileUploaderEditorProvider
 * @implements {EditorProvider}
 */
export class FileUploaderEditorProvider implements IEditorProvider {
  formEditor: string = 'IBizFileUpload';

  gridEditor: string = 'IBizGridFileUpload';

  constructor(editorType: string) {
    if (editorType.includes('PICTURE')) {
      this.formEditor = 'IBizImageUpload';
    } else if (editorType === 'FILEUPLOADER_ONE') {
      this.formEditor = 'IBizFileUploadOne';
    } else if (editorType.includes('FILEUPLOADER')) {
      this.formEditor = 'IBizFileUpload';
    }
  }

  async createController(
    editorModel: FileUploaderEditorModel,
    parentController: FormItemController | GridEditItemController,
  ): Promise<UploadEditorController> {
    const c = new UploadEditorController(editorModel, parentController);
    await c.init();
    return c;
  }
}
