import type { Dependency } from '@univerjs/core';

import { DependentOn, IImageIoService, Inject, Injector, LocaleService, mergeOverrideWithDependencies, Plugin, UniverInstanceType } from '@univerjs/core';
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';

import { JnpfSheetsFloatImageController } from '../controllers/sheet-float-image.controller';
import zhCN from '../locales/zh-CN';
import { JnpfSheetsFloatImageService } from '../services/sheet-float-image.service';
import { JnpfSheetImageIoImplService } from '../services/sheet-image-io-impl.service';

@DependentOn(UniverSheetsUIPlugin)
export class JnpfSheetsFloatImagePlugin extends Plugin {
  static override pluginName = 'JNPF_SHEET_FLOAT_IMAGE_PLUGIN';
  static override type = UniverInstanceType.UNIVER_SHEET;

  constructor(
    @Inject(Injector) protected readonly _injector: Injector,
    @Inject(LocaleService) private readonly _localeService: LocaleService,
  ) {
    super();

    this._localeService.load({
      zhCN,
    });
  }

  override onStarting(): void {
    mergeOverrideWithDependencies(
      [[JnpfSheetsFloatImageController], [JnpfSheetsFloatImageService], [IImageIoService, { useClass: JnpfSheetImageIoImplService }]] as Dependency[],
      [],
    ).forEach(d => this._injector.add(d));

    this._injector.get(JnpfSheetsFloatImageController);
  }
}
