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 setActiceToolMode from './setActiceToolMode';
import setLanguage from './setLanguage';
import getPassword from './getPassword';
import textPopup from './textPopup';

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 = {
    instance: window.instance
    // 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),
    setActiceToolMode: setActiceToolMode(useViewer),
    setLanguage: setLanguage(useViewer),
    getPassword: getPassword(documentStore),
    textPopup: textPopup(viewerStore)
  }
  const documentViewer = core.getDocumentViewer(1);

  window.instances = {
    // CORE_NAMESPACE_KEY: CORE_NAMESPACE,
    // UI_NAMESPACE_KEY: UI_NAMESPACE,
    [CORE_NAMESPACE]: {
      ...objForWebViewerCore,
      ...core,
      documentViewer,
      // annotationManager: documentViewer.getAnnotationManager(),
      getDocumentViewers: () => core.getDocumentViewers(),
    },
    [UI_NAMESPACE]: objForWebViewerUI,
  };
}
