'use client'; import { useMemo, type ReactNode } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; import { useTranslations } from 'next-intl'; import { useAuth } from '@/hooks/use-auth'; import { useTheme } from '@/hooks/use-theme'; import { SettingsRail } from '@/components/settings/settings-rail'; import { SettingsOverview } from '@/components/settings/settings-overview'; import { ProfileForm } from '@/components/settings/profile-form'; import { SecurityPanel } from '@/components/settings/security-panel'; import { AppearancePanel } from '@/components/settings/appearance-panel'; import { WhatsAppConfig } from '@/components/settings/whatsapp-config'; import { TemplateManager } from '@/components/settings/template-manager'; import { QuickRepliesManager } from '@/components/settings/quick-replies-manager'; import { FieldsAndTagsPanel } from '@/components/settings/fields-and-tags-panel'; import { DealsSettings } from '@/components/settings/deals-settings'; import { MembersTab } from '@/components/settings/members-tab'; import { ApiKeysSettings } from '@/components/settings/api-keys-settings'; import { resolveSection, type SettingsSection, } from '@/components/settings/settings-sections'; export default function SettingsPage() { const router = useRouter(); const searchParams = useSearchParams(); const { defaultCurrency } = useAuth(); const { mode } = useTheme(); const t = useTranslations('Settings'); // The URL (`?tab=`) is the single source of truth for the active // section — deep-linkable, and it keeps the existing links in the // app sidebar/header working. Legacy tab values (tags, custom-fields) // resolve onto their new home; unknown/empty → the Overview landing. const section = resolveSection(searchParams.get('tab')); const go = (next: SettingsSection) => { const params = new URLSearchParams(searchParams.toString()); params.set('tab', next); router.replace(`/settings?${params.toString()}`, { scroll: false }); }; // Cheap, fetch-free rail hints. The Overview landing carries the // full live status/counts; the rail just surfaces the two that are // already in context. const hints: Partial> = useMemo( () => ({ appearance: mode.charAt(0).toUpperCase() + mode.slice(1), deals: defaultCurrency, }), [mode, defaultCurrency], ); const panel: Record = { overview: , profile: , security: , appearance: , whatsapp: , templates: , 'quick-replies': , fields: , deals: , members: , api: , }; return (

{t('pageTitle')}

{t('pageDesc')}

{panel[section]}
); }