'use client';

import React from 'react';

import { DialogType, useDialogsStore } from '@/stores/dialogs';

const DlgChangeInputSchema = React.lazy(() =>
  import('@/features/oss/dialogs/dlg-change-input-schema').then(module => ({ default: module.DlgChangeInputSchema }))
);
const DlgChangeLocation = React.lazy(() =>
  import('@/features/library/dialogs/dlg-change-location').then(module => ({
    default: module.DlgChangeLocation
  }))
);
const DlgCloneLibraryItem = React.lazy(() =>
  import('@/features/library/dialogs/dlg-clone-library-item').then(module => ({
    default: module.DlgCloneLibraryItem
  }))
);
const DlgCreateCst = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-create-cst').then(module => ({ default: module.DlgCreateCst }))
);
const DlgCreateOperation = React.lazy(() =>
  import('@/features/oss/dialogs/dlg-create-operation').then(module => ({
    default: module.DlgCreateOperation
  }))
);
const DlgCreateVersion = React.lazy(() =>
  import('@/features/library/dialogs/dlg-create-version').then(module => ({
    default: module.DlgCreateVersion
  }))
);
const DlgCstTemplate = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-cst-template').then(module => ({
    default: module.DlgCstTemplate
  }))
);
const DlgDeleteCst = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-delete-cst').then(module => ({
    default: module.DlgDeleteCst
  }))
);
const DlgDeleteOperation = React.lazy(() =>
  import('@/features/oss/dialogs/dlg-delete-operation').then(module => ({
    default: module.DlgDeleteOperation
  }))
);
const DlgEditEditors = React.lazy(() =>
  import('@/features/library/dialogs/dlg-edit-editors').then(module => ({
    default: module.DlgEditEditors
  }))
);
const DlgEditOperation = React.lazy(() =>
  import('@/features/oss/dialogs/dlg-edit-operation').then(module => ({
    default: module.DlgEditOperation
  }))
);
const DlgEditReference = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-edit-reference').then(module => ({
    default: module.DlgEditReference
  }))
);
const DlgEditVersions = React.lazy(() =>
  import('@/features/library/dialogs/dlg-edit-versions').then(module => ({
    default: module.DlgEditVersions
  }))
);
const DlgEditWordForms = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-edit-word-forms').then(module => ({
    default: module.DlgEditWordForms
  }))
);
const DlgInlineSynthesis = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-inline-synthesis').then(module => ({
    default: module.DlgInlineSynthesis
  }))
);
const DlgRelocateConstituents = React.lazy(() =>
  import('@/features/oss/dialogs/dlg-relocate-constituents').then(module => ({
    default: module.DlgRelocateConstituents
  }))
);
const DlgRenameCst = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-rename-cst').then(module => ({
    default: module.DlgRenameCst
  }))
);
const DlgShowAST = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-show-ast').then(module => ({
    default: module.DlgShowAST
  }))
);
const DlgShowQR = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-show-qr').then(module => ({
    default: module.DlgShowQR
  }))
);
const DlgShowTypeGraph = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-show-type-graph').then(module => ({
    default: module.DlgShowTypeGraph
  }))
);
const DlgSubstituteCst = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-substitute-cst').then(module => ({
    default: module.DlgSubstituteCst
  }))
);
const DlgUploadRSForm = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-upload-rsform').then(module => ({
    default: module.DlgUploadRSForm
  }))
);
const DlgGraphParams = React.lazy(() =>
  import('@/features/rsform/dialogs/dlg-graph-params').then(module => ({ default: module.DlgGraphParams }))
);

export const GlobalDialogs = () => {
  const active = useDialogsStore(state => state.active);

  if (active === null) {
    return null;
  }
  switch (active) {
    case DialogType.CONSTITUENTA_TEMPLATE:
      return <DlgCstTemplate />;
    case DialogType.CREATE_CONSTITUENTA:
      return <DlgCreateCst />;
    case DialogType.CREATE_OPERATION:
      return <DlgCreateOperation />;
    case DialogType.DELETE_CONSTITUENTA:
      return <DlgDeleteCst />;
    case DialogType.EDIT_EDITORS:
      return <DlgEditEditors />;
    case DialogType.EDIT_OPERATION:
      return <DlgEditOperation />;
    case DialogType.EDIT_REFERENCE:
      return <DlgEditReference />;
    case DialogType.EDIT_VERSIONS:
      return <DlgEditVersions />;
    case DialogType.EDIT_WORD_FORMS:
      return <DlgEditWordForms />;
    case DialogType.INLINE_SYNTHESIS:
      return <DlgInlineSynthesis />;
    case DialogType.SHOW_AST:
      return <DlgShowAST />;
    case DialogType.SHOW_TYPE_GRAPH:
      return <DlgShowTypeGraph />;
    case DialogType.CHANGE_INPUT_SCHEMA:
      return <DlgChangeInputSchema />;
    case DialogType.CHANGE_LOCATION:
      return <DlgChangeLocation />;
    case DialogType.CLONE_LIBRARY_ITEM:
      return <DlgCloneLibraryItem />;
    case DialogType.CREATE_VERSION:
      return <DlgCreateVersion />;
    case DialogType.DELETE_OPERATION:
      return <DlgDeleteOperation />;
    case DialogType.GRAPH_PARAMETERS:
      return <DlgGraphParams />;
    case DialogType.RELOCATE_CONSTITUENTS:
      return <DlgRelocateConstituents />;
    case DialogType.RENAME_CONSTITUENTA:
      return <DlgRenameCst />;
    case DialogType.SHOW_QR_CODE:
      return <DlgShowQR />;
    case DialogType.SUBSTITUTE_CONSTITUENTS:
      return <DlgSubstituteCst />;
    case DialogType.UPLOAD_RSFORM:
      return <DlgUploadRSForm />;
  }
};
