"use client"

import {
  resolveAdminSettingsSection,
  type AdminSettingsSectionId,
} from "@/lib/admin-settings/settings-nav"
import { AdminAccessGuard } from "@/components/admin/settings/admin-access-guard"
import { OverviewSection } from "@/components/admin/settings/sections/overview-section"
import { UsersSection } from "@/components/admin/settings/sections/users-section"
import { AuthenticationSection } from "@/components/admin/settings/sections/authentication-section"
import { SecuritySection } from "@/components/admin/settings/sections/security-section"
import { StorageQuotasSection } from "@/components/admin/settings/sections/storage-quotas-section"
import { UsageQuotasSection } from "@/components/admin/settings/sections/usage-quotas-section"
import { FilePoliciesSection } from "@/components/admin/settings/sections/file-policies-section"
import { PublicSharesSection } from "@/components/admin/settings/sections/public-shares-section"
import { LlmSection } from "@/components/admin/settings/sections/llm-section"
import { SearchSection } from "@/components/admin/settings/sections/search-section"
import { PluginsSection } from "@/components/admin/settings/sections/plugins-section"
import { NextcloudSection } from "@/components/admin/settings/sections/nextcloud-section"
import { MailingSection } from "@/components/admin/settings/sections/mailing-section"
import { MailDomainsSection } from "@/components/admin/settings/sections/mail-domains-section"
import { OnlyofficeSection } from "@/components/admin/settings/sections/onlyoffice-section"
import { RichtextSection } from "@/components/admin/settings/sections/richtext-section"
import { AiAssistantSection } from "@/components/admin/settings/sections/ai-assistant-section"
import { AgendaSection } from "@/components/admin/settings/sections/agenda-section"
import { UltimeetSection } from "@/components/admin/settings/sections/ultimeet-section"
import { AuditSection } from "@/components/admin/settings/sections/audit-section"

const SECTIONS: Record<AdminSettingsSectionId, React.ComponentType> = {
  overview: OverviewSection,
  users: UsersSection,
  authentication: AuthenticationSection,
  security: SecuritySection,
  "storage-quotas": StorageQuotasSection,
  "usage-quotas": UsageQuotasSection,
  "file-policies": FilePoliciesSection,
  "public-shares": PublicSharesSection,
  llm: LlmSection,
  search: SearchSection,
  plugins: PluginsSection,
  nextcloud: NextcloudSection,
  agenda: AgendaSection,
  ultimeet: UltimeetSection,
  mailing: MailingSection,
  "mail-domains": MailDomainsSection,
  onlyoffice: OnlyofficeSection,
  richtext: RichtextSection,
  "ai-assistant": AiAssistantSection,
  audit: AuditSection,
}

export function AdminSettingsSectionView({
  sectionId,
}: {
  sectionId: AdminSettingsSectionId
}) {
  const Section = SECTIONS[sectionId]
  return (
    <AdminAccessGuard>
      <Section />
    </AdminAccessGuard>
  )
}

export function AdminSettingsSectionFromSegments({
  segments,
}: {
  segments?: string[]
}) {
  const sectionId = resolveAdminSettingsSection(segments)
  return <AdminSettingsSectionView sectionId={sectionId} />
}
