import core from '@/core';
import { useViewerStore } from '@/stores/modules/viewer';
import { useDocumentStore } from '@/stores/modules/document';

import { createEncapsulatedStore } from '../api_helpers/createEncapsulatedStore';
import i18n from '../i18n'
import disableElements from './disableElements';
import enableElements from './enableElements';
import setHeaderItems from './setHeaderItems';
import setActiveToolMode from './setActiveToolMode';
import setActiveTool from './setActiveTool';
import setLanguage from './setLanguage';
import getPassword from './getPassword';
import textPopup from './textPopup';
import openElement from './openElement';
import closeElement from './closeElement';
import isElementOpen from './isElementOpen';
import setActiveElementTab from './setActiveElementTab';
import setCustomFonts from './setCustomFonts';
import setAnnotator from './setAnnotator';
import getToolColor from './getToolColor';
import getTool from './getTool';
import getActiveTool from './getActiveTool';
import cropPagePopup from './cropPagePopup';
import setAutoJumpNextSign from './setAutoJumpNextSign';

export default () => {
  const { locale } = i18n.global

  const useViewer = useViewerStore()
  const useDocument = useDocumentStore()
  const viewerStore = createEncapsulatedStore(useViewer)
  const documentStore = createEncapsulatedStore(useDocument)

  useViewer.setLanguage(locale.value)

  const CORE_NAMESPACE = 'Core';
  const UI_NAMESPACE = 'UI';
  const objForWebViewerCore = {
    ...core,
    // Tools: window.Core.Tools,
    // Annotations: window.Core.Annotations,
    // PartRetrievers: window.Core.PartRetrievers,
    // Actions: window.Core.Actions,
    // PDFNet: window.Core.PDFNet,
  };
  const objForWebViewerUI = {
    disableElements: disableElements(useViewer),
    enableElements: enableElements(useViewer),
    setHeaderItems: setHeaderItems(useViewer),
    setActiveToolMode: setActiveToolMode(useViewer),
    setActiceToolMode: setActiveToolMode(useViewer),
    setActiveTool: setActiveTool(useViewer, useDocument),
    setLanguage: setLanguage(useViewer),
    getPassword: getPassword(documentStore),
    textPopup: textPopup(viewerStore),
    openElement: openElement(useViewer),
    closeElement: closeElement(useViewer),
    isElementOpen: isElementOpen(useViewer),
    setActiveElementTab: setActiveElementTab(useViewer),
    setCustomFonts: setCustomFonts(useViewer),
    setAnnotator: setAnnotator(useDocument),
    getActiveTool: getActiveTool(useDocument),
    getToolColor: getToolColor(useDocument),
    getTool: getTool(useDocument),
    cropPagePopup: cropPagePopup(viewerStore),
    setAutoJumpNextSign: setAutoJumpNextSign(useDocument),
  }

  window.instances = {
    // CORE_NAMESPACE_KEY: CORE_NAMESPACE,
    // UI_NAMESPACE_KEY: UI_NAMESPACE,
    [CORE_NAMESPACE]: objForWebViewerCore,
    [UI_NAMESPACE]: objForWebViewerUI,
  };
}
