'use client'; import { useEffect, useState } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; import { Settings, MessageSquare, Tag, User } from 'lucide-react'; import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'; import { WhatsAppConfig } from '@/components/settings/whatsapp-config'; import { TemplateManager } from '@/components/settings/template-manager'; import { TagManager } from '@/components/settings/tag-manager'; import { ProfileForm } from '@/components/settings/profile-form'; import { PasswordForm } from '@/components/settings/password-form'; import { SessionsCard } from '@/components/settings/sessions-card'; const TAB_VALUES = ['profile', 'whatsapp', 'templates', 'tags'] as const; type TabValue = (typeof TAB_VALUES)[number]; function isTabValue(v: string | null): v is TabValue { return !!v && (TAB_VALUES as readonly string[]).includes(v); } export default function SettingsPage() { const router = useRouter(); const searchParams = useSearchParams(); const initialTab = (() => { const q = searchParams.get('tab'); return isTabValue(q) ? q : 'profile'; })(); const [tab, setTab] = useState(initialTab); // Keep the URL in sync with the active tab so the user-menu deep links // work and the tab is bookmarkable / shareable. useEffect(() => { const q = searchParams.get('tab'); if (isTabValue(q) && q !== tab) setTab(q); }, [searchParams, tab]); const onChange = (next: TabValue) => { setTab(next); const params = new URLSearchParams(searchParams.toString()); params.set('tab', next); router.replace(`/settings?${params.toString()}`, { scroll: false }); }; return (

Settings

Manage your profile, WhatsApp integration, message templates, and tags.

onChange(v as TabValue)}> Profile WhatsApp Config Templates Tags
); }