"use client"

import {
  resolveMailSettingsSection,
  type MailSettingsSectionId,
} from "@/lib/mail-settings/settings-nav"
import { DisplaySettingsSection } from "@/components/gmail/settings/sections/display-settings-section"
import { AccountsSettingsSection } from "@/components/gmail/settings/sections/accounts-settings-section"
import { SignaturesSettingsSection } from "@/components/gmail/settings/sections/signatures-settings-section"
import { LabelsFoldersSettingsSection } from "@/components/gmail/settings/sections/labels-folders-settings-section"
import { NotificationsSettingsSection } from "@/components/gmail/settings/sections/notifications-settings-section"
import { AutomationSettingsSection } from "@/components/gmail/settings/sections/automation-settings-section"

const SECTIONS: Record<MailSettingsSectionId, React.ComponentType> = {
  display: DisplaySettingsSection,
  accounts: AccountsSettingsSection,
  signatures: SignaturesSettingsSection,
  labels: LabelsFoldersSettingsSection,
  notifications: NotificationsSettingsSection,
  automation: AutomationSettingsSection,
}

export function MailSettingsSectionView({
  sectionId,
}: {
  sectionId: MailSettingsSectionId
}) {
  const Section = SECTIONS[sectionId]
  return <Section />
}

export function MailSettingsSectionFromSegments({
  segments,
}: {
  segments?: string[]
}) {
  const sectionId = resolveMailSettingsSection(segments)
  return <MailSettingsSectionView sectionId={sectionId} />
}
