"use client"; import { useState, useEffect } from "react"; import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" export default function SettingsPage() { const [settings, setSettings] = useState({ maintenance_mode: false, allow_new_registrations: true, enable_free_trial: true, trial_duration_days: 5, trial_tier: "Al_Coach" }); const [loading, setLoading] = useState(true); useEffect(() => { fetch("/api/admin/settings") .then(res => res.json()) .then(data => { if(data && !data.detail) { setSettings(prev => ({ ...prev, ...data })); } setLoading(false); }) .catch(err => { console.error("Failed to load settings:", err); setLoading(false); }); }, []); const saveSettings = async (section: string, overrides: Partial = {}) => { try { const payload = { ...settings, ...overrides }; const res = await fetch("/api/admin/settings", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); if (res.ok) { alert(`${section} saved successfully!`); setSettings(payload); } else { alert(`Failed to save ${section}.`); } } catch (err) { alert("Error saving settings."); } }; const handleToggle = (key: keyof typeof settings, sectionName: string) => { const newValue = !settings[key]; setSettings(prev => ({ ...prev, [key]: newValue })); saveSettings(sectionName, { [key]: newValue }); }; if (loading) return
Loading System Settings...
; return (

System Settings

Configure global application variables and security protocols.

AI Inference Configuration Manage the underlying LLM models and API keys for the AI agents.
Trial Management Configure the trial length and tier access for new signups.
Enable Free Trial
Offer a trial to newly registered users.
handleToggle('enable_free_trial', 'Free Trial')} className={`h-6 w-11 rounded-full relative cursor-pointer transition-colors ${settings.enable_free_trial ? 'bg-primary border border-primary shadow-[0_0_10px_var(--color-primary)]' : 'bg-secondary border border-border'}`}>
setSettings(prev => ({ ...prev, trial_duration_days: parseInt(e.target.value) || 0 }))} className="w-full bg-background border border-border rounded-lg px-4 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-[var(--cyan-ai)]" />
Platform Maintenance Global toggles for site availability.
Maintenance Mode
Disable all student access and show maintenance screen.
handleToggle('maintenance_mode', 'Maintenance Mode')} className={`h-6 w-11 rounded-full relative cursor-pointer transition-colors ${settings.maintenance_mode ? 'bg-red-500 border border-red-500 shadow-[0_0_10px_rgba(239,68,68,0.8)]' : 'bg-secondary border border-border'}`}>
Allow New Registrations
Open the `/signup` route for new users.
handleToggle('allow_new_registrations', 'Registration Setting')} className={`h-6 w-11 rounded-full relative cursor-pointer transition-colors ${settings.allow_new_registrations ? 'bg-primary border border-primary shadow-[0_0_10px_var(--color-primary)]' : 'bg-secondary border border-border'}`}>
Danger Zone
) }