import '../fomantic/build/fomantic.js';
import '../css/index.css';

import {initDashboardRepoList} from './features/dashboard.ts';
import {initGlobalCopyToClipboardListener} from './modules/clipboard.ts';
import {initCopyContent} from './features/copycontent.ts';
import {initRepoGraphGit} from './features/repo-graph.ts';
import {initHeatmap} from './features/heatmap.ts';
import {initImageDiff} from './features/imagediff.ts';
import {initRepoMigration} from './features/repo-migration.ts';
import {initRepoProjectsView} from './features/repo-projects.ts';
import {initTableSort} from './features/tablesort.ts';
import {initAdminUserListSearchForm} from './features/admin/users.ts';
import {initAdminConfigs} from './features/admin/config.ts';
import {initMarkupAnchors} from './markup/anchors.ts';
import {initNotificationCount} from './features/notification.ts';
import {initRepoIssueContentHistory} from './features/repo-issue-content.ts';
import {initStopwatch} from './features/stopwatch.ts';
import {initRepoFileSearch} from './features/repo-findfile.ts';
import {initMarkupContent} from './markup/content.ts';
import {initRepoFileView} from './features/file-view.ts';
import {initUserExternalLogins, initUserCheckAppUrl} from './features/user-auth.ts';
import {initRepoPullRequestReview, initRepoIssueFilterItemLabel} from './features/repo-issue.ts';
import {initRepoEllipsisButton, initCommitStatuses, initAvatarStackPopup, initCommitFileHistoryFollowRename} from './features/repo-commit.ts';
import {initRepoTopicBar} from './features/repo-home.ts';
import {initAdminCommon} from './features/admin/common.ts';
import {initRepoCodeView} from './features/repo-code.ts';
import {initSshKeyFormParser} from './features/sshkey-helper.ts';
import {initUserSettings} from './features/user-settings.ts';
import {initRepoActivityTopAuthorsChart, initRepoArchiveLinks} from './features/repo-common.ts';
import {initRepoMigrationStatusChecker} from './features/repo-migrate.ts';
import {initRepoDiffView} from './features/repo-diff.ts';
import {initOrgTeam} from './features/org-team.ts';
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.ts';
import {initRepoReleaseNew} from './features/repo-release.ts';
import {initRepoEditor} from './features/repo-editor.ts';
import {initCompSearchUserBox} from './features/comp/SearchUserBox.ts';
import {initInstall} from './features/install.ts';
import {initCompWebHookEditor} from './features/comp/WebHookEditor.ts';
import {initRepoBranchButton} from './features/repo-branch.ts';
import {initCommonOrganization} from './features/common-organization.ts';
import {initRepoWikiForm} from './features/repo-wiki.ts';
import {initRepository, initBranchSelectorTabs} from './features/repo-legacy.ts';
import {initCaptcha} from './features/captcha.ts';
import {initRepositoryActions} from './features/repo-actions.ts';
import {initGlobalTooltips} from './modules/tippy.ts';
import {initGiteaFomantic} from './modules/fomantic.ts';
import {initRepoIssueList} from './features/repo-issue-list.ts';
import {initCommonIssueListQuickGoto} from './features/common-issue-list.ts';
import {initRepoContributors} from './features/contributors.ts';
import {initRepoCodeFrequency} from './features/code-frequency.ts';
import {initRepoRecentCommits} from './features/recent-commits.ts';
import {initRepoDiffCommitBranchesAndTags} from './features/repo-diff-commit.ts';
import {initGlobalSelectorObserver} from './modules/observer.ts';
import {initRepositorySearch} from './features/repo-search.ts';
import {initColorPickers} from './features/colorpicker.ts';
import {initAdminSelfCheck} from './features/admin/selfcheck.ts';
import {initOAuth2SettingsDisableCheckbox} from './features/oauth2-settings.ts';
import {initGlobalFetchAction} from './features/common-fetch-action.ts';
import {initCommmPageComponents, initGlobalComponent, initGlobalDropdown, initGlobalInput} from './features/common-page.ts';
import {initGlobalButtonClickOnEnter, initGlobalButtons} from './features/common-button.ts';
import {initGlobalComboMarkdownEditor, initGlobalEnterQuickSubmit, initGlobalFormDirtyLeaveConfirm} from './features/common-form.ts';
import {callInitFunctions} from './modules/init.ts';
import {initRepoViewFileTree} from './features/repo-view-file-tree.ts';
import {initActionsPermissionsForm} from './features/common-actions-permissions.ts';
import {initRefIssueContextPopup} from './features/ref-issue.ts';
import {initGlobalShortcut} from './modules/shortcut.ts';
import {initDevtest} from './modules/devtest.ts';

const initStartTime = performance.now();
const initPerformanceTracer = callInitFunctions([
  initGiteaFomantic,

  initGlobalComponent,
  initGlobalDropdown,
  initGlobalFetchAction,
  initGlobalTooltips,
  initGlobalButtonClickOnEnter,
  initGlobalButtons,
  initGlobalCopyToClipboardListener,
  initGlobalEnterQuickSubmit,
  initGlobalFormDirtyLeaveConfirm,
  initGlobalComboMarkdownEditor,
  initGlobalInput,
  initGlobalShortcut,

  initCommonOrganization,
  initCommonIssueListQuickGoto,

  initCompSearchUserBox,
  initCompWebHookEditor,

  initInstall,

  initCommmPageComponents,

  initHeatmap,
  initImageDiff,
  initMarkupAnchors,
  initMarkupContent,
  initRefIssueContextPopup,
  initSshKeyFormParser,
  initStopwatch,
  initTableSort,
  initRepoFileSearch,
  initCopyContent,

  initAdminCommon,
  initAdminUserListSearchForm,
  initAdminConfigs,
  initAdminSelfCheck,

  initDashboardRepoList,

  initNotificationCount,

  initOrgTeam,

  initRepoActivityTopAuthorsChart,
  initRepoArchiveLinks,
  initRepoBranchButton,
  initRepoCodeView,
  initBranchSelectorTabs,
  initRepoEllipsisButton,
  initCommitFileHistoryFollowRename,
  initRepoDiffCommitBranchesAndTags,
  initRepoEditor,
  initRepoGraphGit,
  initRepoIssueContentHistory,
  initRepoIssueList,
  initRepoIssueFilterItemLabel,
  initRepoMigration,
  initRepoMigrationStatusChecker,
  initRepoProjectsView,
  initRepoPullRequestReview,
  initRepoReleaseNew,
  initRepoTopicBar,
  initRepoViewFileTree,
  initRepoWikiForm,
  initRepository,
  initRepositoryActions,
  initRepositorySearch,
  initRepoContributors,
  initRepoCodeFrequency,
  initRepoRecentCommits,

  initCommitStatuses,
  initAvatarStackPopup,
  initCaptcha,

  initUserCheckAppUrl,
  initUserExternalLogins,
  initUserAuthWebAuthn,
  initUserAuthWebAuthnRegister,
  initUserSettings,
  initRepoDiffView,
  initColorPickers,

  initOAuth2SettingsDisableCheckbox,

  initRepoFileView,
  initActionsPermissionsForm,

  initDevtest,
]);

// it must be the last one, then the "querySelectorAll" only needs to be executed once for global init functions.
initGlobalSelectorObserver(initPerformanceTracer);
if (initPerformanceTracer) initPerformanceTracer.printResults();

const initDur = performance.now() - initStartTime;
if (initDur > 500) {
  console.error(`slow init functions took ${initDur.toFixed(3)}ms`);
}

window.config.frontendInited = true;
