import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Switch } from '@/components/ui/switch'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Badge } from '@/components/ui/badge'; import { AdminLayout } from '@/components/layout/AdminLayout'; import { useAuth } from '@/hooks/useAuth'; import { useUserRole } from '@/hooks/useUserRole'; import { useAdminSettings } from '@/hooks/useAdminSettings'; import { NovuMigrationUtility } from '@/components/admin/NovuMigrationUtility'; import { TestDataGenerator } from '@/components/admin/TestDataGenerator'; import { Loader2, Save, Clock, Users, Bell, Shield, Settings, Trash2, Plug, AlertTriangle, Lock } from 'lucide-react'; export default function AdminSettings() { const { user } = useAuth(); const { isSuperuser, loading: roleLoading } = useUserRole(); const { settings, isLoading, error, updateSetting, isUpdating, getSettingsByCategory, getCaptchaBypassEnabled } = useAdminSettings(); if (roleLoading || isLoading) { return (
); } if (!user || !isSuperuser()) { return (

Access Denied

You don't have permission to access admin settings.

{error && (
Error details: {error.message}
)}
); } if (!settings || settings.length === 0) { return (

No Settings Found

No admin settings have been configured yet. Please contact your system administrator.

{error && (
Error details: {error.message}
)}
); } const SettingInput = ({ setting }: { setting: any }) => { const [localValue, setLocalValue] = useState(setting.setting_value); const handleSubmit = async () => { await updateSetting(setting.setting_key, localValue); }; // Auto-flagging threshold settings if (setting.setting_key === 'moderation.auto_flag_threshold') { return (

Content will be automatically flagged for review after receiving this many reports

Current: {localValue} reports
); } // Review retention settings if (setting.setting_key === 'moderation.review_retention_days') { return (

How long to keep moderated content data before automatic cleanup

Current: {localValue} days
); } // Ban duration settings if (setting.setting_key === 'moderation.ban_durations') { const [banDurations, setBanDurations] = useState<{[key: string]: number}>( typeof localValue === 'object' ? localValue : { temporary: 7, extended: 30, permanent: 0 } ); const updateBanDuration = (type: string, days: number) => { const updated = { ...banDurations, [type]: days }; setBanDurations(updated); setLocalValue(updated); }; const saveBanDurations = () => { updateSetting(setting.setting_key, banDurations); }; return (

Configure the available ban duration options for moderators

Short-term restriction for minor violations

Longer restriction for serious violations

Indefinite restriction for severe violations

Permanent
); } // Admin panel refresh mode setting if (setting.setting_key === 'system.admin_panel_refresh_mode') { return (

Choose how the admin panel statistics refresh

Current: {(typeof localValue === 'string' ? localValue.replace(/"/g, '') : localValue) === 'auto' ? 'Auto-refresh' : 'Manual'}
); } // Admin panel poll interval setting if (setting.setting_key === 'system.admin_panel_poll_interval') { return (

How often to automatically refresh admin panel statistics (when auto-refresh is enabled)

Current: {localValue}s
); } // Boolean/switch settings if (setting.setting_key.includes('email_alerts') || setting.setting_key.includes('require_approval') || setting.setting_key.includes('auto_cleanup') || setting.setting_key.includes('enable_') || setting.setting_key.includes('allow_')) { const getSettingIcon = () => { if (setting.setting_key.includes('email_alerts')) return ; if (setting.setting_key.includes('require_approval')) return ; if (setting.setting_key.includes('auto_cleanup')) return ; return ; }; return (
{getSettingIcon()}

{setting.setting_key.includes('email_alerts') && "Receive email notifications for this event"} {setting.setting_key.includes('require_approval') && "Items must be manually approved before being published"} {setting.setting_key.includes('auto_cleanup') && "Automatically remove old or rejected content"} {(!setting.setting_key.includes('email_alerts') && !setting.setting_key.includes('require_approval') && !setting.setting_key.includes('auto_cleanup')) && "Toggle this feature on or off"}

{localValue ? "Enabled" : "Disabled"} { setLocalValue(checked); updateSetting(setting.setting_key, checked); }} />
); } // Numeric threshold settings if (setting.setting_key.includes('threshold') || setting.setting_key.includes('limit') || setting.setting_key.includes('max_')) { return (

Set the numeric limit for this system parameter

{ const value = parseInt(e.target.value) || 0; setLocalValue(value); }} className="w-24" min="0" />
Current: {localValue}
); } // Default string input return (
{ setLocalValue(e.target.value); }} className="flex-1" />
); }; return (

Admin Settings

Configure system-wide settings and preferences

Moderation Auth Users Notifications System Integrations Testing Moderation Settings Configure content moderation rules, thresholds, and automated actions {getSettingsByCategory('moderation').length > 0 ? ( getSettingsByCategory('moderation').map((setting) => ( )) ) : (

No moderation settings configured yet.

)}
Authentication Settings Configure authentication security, CAPTCHA, and login settings {getCaptchaBypassEnabled() && (

CAPTCHA Bypass is Currently Enabled

Authentication requests will not require CAPTCHA verification. This should ONLY be enabled in development environments.

)} {getSettingsByCategory('auth').length > 0 ? ( getSettingsByCategory('auth').map((setting) => ( )) ) : (

No authentication settings configured yet.

)}
User Management Configure user registration, profile settings, and account policies {getSettingsByCategory('user_management').length > 0 ? ( getSettingsByCategory('user_management').map((setting) => ( )) ) : (

No user management settings configured yet.

)}
Notification Settings Configure email alerts, push notifications, and communication preferences {getSettingsByCategory('notifications').length > 0 ? ( getSettingsByCategory('notifications').map((setting) => ( )) ) : (

No notification settings configured yet.

)}
System Configuration Configure system-wide settings, maintenance options, and technical parameters {getSettingsByCategory('system').length > 0 ? ( getSettingsByCategory('system').map((setting) => ( )) ) : (

No system settings configured yet.

)}
Integration Settings Configure third-party integrations and external services {getSettingsByCategory('integrations').length > 0 ? ( getSettingsByCategory('integrations').map((setting) => ( )) ) : (

No integration settings configured yet.

)}
); }