'use client' import { useState, useEffect } from 'react' import { Check, ExternalLink, Cloud, HardDrive } from 'lucide-react' import { useAuth } from '@/utils/auth' import { UserProfile, getUserProfile, updateUserProfile, checkApiKeyStatus, saveApiKey, deleteAccount, logout } from '@/utils/api' import { useRouter } from 'next/navigation' declare global { interface Window { ipcRenderer?: any; } } type Tab = 'profile' | 'privacy' | 'billing' type BillingCycle = 'monthly' | 'annually' export default function SettingsPage() { const { user: userInfo, isLoading, mode } = useAuth() const [activeTab, setActiveTab] = useState('profile') const [billingCycle, setBillingCycle] = useState('monthly') const [profile, setProfile] = useState(null) const [hasApiKey, setHasApiKey] = useState(false) const [apiKeyInput, setApiKeyInput] = useState('') const [isSaving, setIsSaving] = useState(false) const [displayNameInput, setDisplayNameInput] = useState('') const router = useRouter() const fetchApiKeyStatus = async () => { try { const apiKeyStatus = await checkApiKeyStatus() setHasApiKey(apiKeyStatus.hasApiKey) } catch (error) { console.error("Failed to fetch API key status:", error); } } useEffect(() => { if (!userInfo) return const fetchProfileData = async () => { try { const userProfile = await getUserProfile() setProfile(userProfile) setDisplayNameInput(userProfile.display_name) await fetchApiKeyStatus(); } catch (error) { console.error("Failed to fetch profile data:", error) } } fetchProfileData() if (window.ipcRenderer) { window.ipcRenderer.on('api-key-updated', () => { console.log('Received api-key-updated event from main process.'); fetchApiKeyStatus(); }); } return () => { if (window.ipcRenderer) { window.ipcRenderer.removeAllListeners('api-key-updated'); } } }, [userInfo]) if (isLoading) { return (

Loading...

) } if (!userInfo) { router.push('/login') return null } const isFirebaseMode = mode === 'firebase' const tabs = [ { id: 'profile' as Tab, name: 'Personal Profile', href: '/settings' }, { id: 'privacy' as Tab, name: 'Data & Privacy', href: '/settings/privacy' }, { id: 'billing' as Tab, name: 'Billing', href: '/settings/billing' }, ] const handleSaveApiKey = async () => { setIsSaving(true) try { await saveApiKey(apiKeyInput) setHasApiKey(true) setApiKeyInput('') if (window.ipcRenderer) { window.ipcRenderer.invoke('save-api-key', apiKeyInput); } } catch (error) { console.error("Failed to save API key:", error) } finally { setIsSaving(false) } } const handleUpdateDisplayName = async () => { if (!profile || displayNameInput === profile.display_name) return; setIsSaving(true); try { await updateUserProfile({ displayName: displayNameInput }); setProfile(prev => prev ? { ...prev, display_name: displayNameInput } : null); } catch (error) { console.error("Failed to update display name:", error); } finally { setIsSaving(false); } } const handleDeleteAccount = async () => { const confirmMessage = isFirebaseMode ? "Are you sure you want to delete your account? This action cannot be undone and all data stored in Firebase will be deleted." : "Are you sure you want to delete your account? This action cannot be undone and all data will be deleted." if (window.confirm(confirmMessage)) { try { await deleteAccount() router.push('/login'); } catch (error) { console.error("Failed to delete account:", error) } } } const handleLogout = async () => { try { await logout() } catch (error) { console.error("Logout failed:", error) } } const renderBillingContent = () => (
{isFirebaseMode ? ( ) : ( )}

{isFirebaseMode ? 'Firebase Hosting Mode' : 'Local Execution Mode'}

{isFirebaseMode ? 'All data is safely stored and synchronized in Firebase Cloud.' : 'Data is stored in local database and you can use personal API keys.' }

Free

$0/month

Experience how Pickle Glass works with unlimited responses.

  • Daily unlimited responses
  • Unlimited access to free models
  • Unlimited text output
  • Screen viewing, audio listening
  • Custom system prompts
  • Community support only

Pro

$25/month

Use latest models, get full response output, and work with custom prompts.

  • Unlimited pro responses
  • Unlimited access to latest models
  • Full access to conversation dashboard
  • Priority support
  • All features from free plan

Enterprise

Custom

Specially crafted for teams that need complete customization.

  • Custom integrations
  • User provisioning & role-based access
  • Advanced post-call analytics
  • Single sign-on
  • Advanced security features
  • Centralized billing
  • Usage analytics & reporting dashboard

All features are currently free!

{isFirebaseMode ? 'Enjoy all Pickle Glass features for free in Firebase hosting mode. Pro and Enterprise plans will be released soon with additional premium features.' : 'Enjoy all Pickle Glass features for free in local mode. You can use personal API keys or continue using the free system.' }

) const renderTabContent = () => { switch (activeTab) { case 'billing': return renderBillingContent() case 'profile': return (
{isFirebaseMode ? ( ) : ( )}

{isFirebaseMode ? 'Firebase Hosting Mode' : 'Local Execution Mode'}

{isFirebaseMode ? `Logged in with Google account (${userInfo.email})` : 'Running as local user' }

{isFirebaseMode && ( )}

Display Name

Enter your full name or a display name you're comfortable using.

setDisplayNameInput(e.target.value)} className="block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm text-black" maxLength={32} />

You can use up to 32 characters.

{!isFirebaseMode && (

API Key

If you want to use your own LLM API key, you can add it here. It will be used for all requests made by the local application.

setApiKeyInput(e.target.value)} className="flex-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm text-black" placeholder="Enter new API key or existing API key" />
{hasApiKey ? (

API key is currently set.

) : (

No API key set. Using free system.

)}
)} {(isFirebaseMode || (!isFirebaseMode && !hasApiKey)) && (

Delete Account

{isFirebaseMode ? 'Permanently remove your Firebase account and all content. This action cannot be undone, so please proceed carefully.' : 'Permanently remove your personal account and all content from the Pickle Glass platform. This action cannot be undone, so please proceed carefully.' }

)}
) case 'privacy': return null default: return renderBillingContent() } } return (

Settings

Personal Settings

{renderTabContent()}
) }