import core from '@/core'
import { useDocumentStore } from '@/stores/modules/document'
const useDocument = useDocumentStore()

export default (src, options = {}) => {
  const documentViewer = core.getDocumentViewer()
  documentViewer.init()
  documentViewer.close()
  documentViewer.load()
  options.docId = options.documentId || null;
  options.progress = (percent) => useDocument.setLoadingProgress(percent);

  // ignore caught errors because they are already being handled in the onError callback
  core.loadDocument(src, options, documentViewerKey).catch(() => {});
  dispatch(actions.openElement('progressModal'));
}
