import { pdfViewerId } from "./constants";
import { translate } from "../../locales";
import { PrimariaNavItem } from "../../UI/shared-components/primaria-nav-item/primaria-nav-item";
import { shellApi } from "../api";
import { PdfVisor } from "./pdf-visor/pdf-visor";

export const registerPdfViewerNavItem = () => {
  shellApi.regionManager.registerView(shellApi.regionManager.regions.shell.navigationMenu, {
    id: pdfViewerId,
    sortHint: "0110",
    factory: () => {
      const menuItem = new PrimariaNavItem({
        icon: "picture_as_pdf",
        label: translate("pdfManager.navButtonLabel"),
        callbackFn: () => {
          shellApi.regionManager.activateMainView(pdfViewerId);
        },
      });
      return Promise.resolve(menuItem);
    },
  });
};

export const registerPDFVisorMainView = () => {
  shellApi.regionManager.registerMainView({
    id: pdfViewerId,
    factory: () => {
      const mainItem = new PdfVisor();
      return Promise.resolve(mainItem as unknown as HTMLElement);
    },
  });
};
