"use client" import * as React from "react" import { IconPlus } from "@tabler/icons-react" import { toast } from "sonner" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Separator } from "@/components/ui/separator" import { Switch } from "@/components/ui/switch" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Textarea } from "@/components/ui/textarea" // import { useChatStateOptional } from "@/components/agent/chat-provider" // import { ChatView } from "@/components/agent/chat-view" import { NetSuiteConnectionStatus } from "@/components/netsuite/connection-status" import { SyncControls } from "@/components/netsuite/sync-controls" import { GoogleDriveConnectionStatus } from "@/components/google/connection-status" import { AppearanceTab } from "@/components/settings/appearance-tab" import { AgentTab } from "@/components/settings/agent-tab" import { TeamTab } from "@/components/settings/team-tab" import { useNative } from "@/hooks/use-native" import { useBiometricAuth } from "@/hooks/use-biometric-auth" import { cn } from "@/lib/utils" const SETTINGS_TABS = [ { value: "team", label: "Team" }, { value: "general", label: "General" }, { value: "notifications", label: "Notifications" }, { value: "appearance", label: "Theme" }, { value: "integrations", label: "Integrations" }, { value: "agent", label: "Agent" }, ] as const const CREATE_SETTING_TAB = { value: "create-setting", label: "Create", } as const interface CustomSettingTab { readonly value: string readonly label: string readonly prompt: string } function makeCustomSettingValue( label: string, existingTabs: ReadonlyArray ): string { const normalized = label .trim() .toLowerCase() .replace(/[^a-z0-9]+/g, "-") .replace(/(^-|-$)/g, "") const base = normalized.length > 0 ? normalized : "setting" let candidate = `custom-${base}` let suffix = 2 while (existingTabs.some((tab) => tab.value === candidate)) { candidate = `custom-${base}-${suffix}` suffix += 1 } return candidate } export function SettingsModal({ open, onOpenChange, }: { open: boolean onOpenChange: (open: boolean) => void }) { const [emailNotifs, setEmailNotifs] = React.useState(true) const [pushNotifs, setPushNotifs] = React.useState(true) const [weeklyDigest, setWeeklyDigest] = React.useState(false) const [timezone, setTimezone] = React.useState("America/New_York") const [customTabs, setCustomTabs] = React.useState>([]) const [activeTab, setActiveTab] = React.useState("general") const [newSettingName, setNewSettingName] = React.useState("") const [newSettingPrompt, setNewSettingPrompt] = React.useState("") // const [isMobileChatOpen, setIsMobileChatOpen] = React.useState(false) // const chatState = useChatStateOptional() const menuTabs = React.useMemo( () => [...SETTINGS_TABS, ...customTabs], [customTabs] ) const sendCreateSettingToChat = React.useCallback(() => { toast.info("AI chat is currently disabled in settings") }, []) const openCreateSettingFlow = React.useCallback(() => { setActiveTab(CREATE_SETTING_TAB.value) // setIsMobileChatOpen(true) // chatState?.sendMessage({ text: "Create a new setting" }) }, []) const handleSectionSelect = React.useCallback((value: string) => { if (value === CREATE_SETTING_TAB.value) { openCreateSettingFlow() return } setActiveTab(value) }, [openCreateSettingFlow]) const createCustomSetting = React.useCallback(() => { const label = newSettingName.trim() const details = newSettingPrompt.trim() if (!label) { toast.error("Add a setting name first") return } if (!details) { toast.error("Describe what the setting should do") return } const nextTab: CustomSettingTab = { value: makeCustomSettingValue(label, customTabs), label, prompt: details, } setCustomTabs((prev) => [...prev, nextTab]) setActiveTab(nextTab.value) // setIsMobileChatOpen(true) setNewSettingName("") setNewSettingPrompt("") sendCreateSettingToChat() toast.success(`Added ${nextTab.label} to settings`) }, [customTabs, newSettingName, newSettingPrompt, sendCreateSettingToChat]) const native = useNative() const biometric = useBiometricAuth() const renderContent = () => { switch (activeTab) { case "team": return case "general": return (

Receive a summary of activity each week.

) case "notifications": return (

Get notified about project updates via email.

{native ? "Receive push notifications on your device." : "Receive push notifications in your browser."}

{native && biometric.isAvailable && ( <>

Require Face ID or fingerprint when returning to the app.

)}
) case "appearance": return
case "integrations": return (
) case "agent": return
case CREATE_SETTING_TAB.value: return (

Create a new setting

Describe the setting you want, then send it to AI chat.

setNewSettingName(e.target.value)} placeholder="Example: Project defaults" className="h-9" />