import React, { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Settings, Shield, Users, BarChart3, Bell, Database, Globe, Lock, Eye, EyeOff, Save, RotateCcw, Check, X, AlertTriangle, Info, Zap, Palette, Monitor, Smartphone, Mail, Key, Download, Upload, Trash2, RefreshCw, Clock, Calendar } from 'lucide-react'; import styles from '../styles/EnhancedSettings.module.css'; const EnhancedSettings = () => { const [settings, setSettings] = useState({ systemName: 'MKCart Admin', defaultCurrency: 'INR', timeZone: 'Asia/Kolkata', language: 'en', theme: 'dark', sessionTimeout: 30, passwordPolicy: 'strong', twoFactorAuth: true, loginAttempts: 5, passwordExpiry: 90, defaultUserRole: 'user', requireEmailVerification: true, autoActivateUsers: false, allowRegistration: true, dataRetention: 90, realTimeAnalytics: true, trackUserBehavior: true, analyticsEnabled: true, emailNotifications: true, pushNotifications: true, orderAlerts: true, systemAlerts: true, maintenanceMode: false, debugMode: false, autoBackup: true, backupFrequency: 'daily' }); const [isLoading, setIsLoading] = useState(false); const [saveStatus, setSaveStatus] = useState(null); const [activeTab, setActiveTab] = useState('general'); const handleSettingChange = (category, key, value) => { setSettings(prev => ({ ...prev, [key]: value })); }; const handleSaveSettings = async () => { setIsLoading(true); setSaveStatus('saving'); try { await new Promise(resolve => setTimeout(resolve, 1500)); setSaveStatus('success'); setTimeout(() => setSaveStatus(null), 3000); } catch (error) { setSaveStatus('error'); setTimeout(() => setSaveStatus(null), 3000); } finally { setIsLoading(false); } }; const handleResetSettings = () => { if (window.confirm('Are you sure you want to reset all settings to defaults?')) { setSettings({ systemName: 'MKCart Admin', defaultCurrency: 'INR', timeZone: 'Asia/Kolkata', language: 'en', theme: 'dark', sessionTimeout: 30, passwordPolicy: 'strong', twoFactorAuth: true, loginAttempts: 5, passwordExpiry: 90, defaultUserRole: 'user', requireEmailVerification: true, autoActivateUsers: false, allowRegistration: true, dataRetention: 90, realTimeAnalytics: true, trackUserBehavior: true, analyticsEnabled: true, emailNotifications: true, pushNotifications: true, orderAlerts: true, systemAlerts: true, maintenanceMode: false, debugMode: false, autoBackup: true, backupFrequency: 'daily' }); } }; const settingsTabs = [ { id: 'general', label: 'General', icon: Settings }, { id: 'security', label: 'Security', icon: Shield }, { id: 'users', label: 'Users', icon: Users }, { id: 'analytics', label: 'Analytics', icon: BarChart3 }, { id: 'notifications', label: 'Notifications', icon: Bell }, { id: 'system', label: 'System', icon: Database } ]; const SettingItem = ({ label, type = 'text', value, onChange, options, description, icon: Icon, required = false }) => (
{Icon && }
{type === 'select' ? ( ) : type === 'checkbox' ? ( ) : type === 'number' ? ( onChange(e.target.value)} className={styles['setting-input-enhanced']} min="1" max="1000" /> ) : ( onChange(e.target.value)} className={styles['setting-input-enhanced']} /> )} {description && (

{description}

)}
); return (
{}

System Settings

Configure your system preferences and security settings

{saveStatus === 'saving' && ( Saving... )} {saveStatus === 'success' && ( Saved successfully! )} {saveStatus === 'error' && ( Save failed )}
{} {settingsTabs.map((tab) => ( ))} {} {activeTab === 'general' && (

General Settings

handleSettingChange('general', 'systemName', value)} description="The name displayed in the admin panel" icon={Settings} required /> handleSettingChange('general', 'defaultCurrency', value)} options={[ { value: 'INR', label: 'Indian Rupee (₹)' }, { value: 'USD', label: 'US Dollar ($)' }, { value: 'EUR', label: 'Euro (€)' }, { value: 'GBP', label: 'British Pound (£)' } ]} description="Default currency for transactions" icon={Palette} /> handleSettingChange('general', 'timeZone', value)} options={[ { value: 'Asia/Kolkata', label: 'Asia/Kolkata (IST)' }, { value: 'UTC', label: 'UTC' }, { value: 'America/New_York', label: 'America/New_York (EST)' }, { value: 'Europe/London', label: 'Europe/London (GMT)' } ]} description="System time zone for date/time display" icon={Clock} /> handleSettingChange('general', 'language', value)} options={[ { value: 'en', label: 'English' }, { value: 'hi', label: 'Hindi' }, { value: 'es', label: 'Spanish' }, { value: 'fr', label: 'French' } ]} description="Default language for the interface" icon={Globe} />
)} {activeTab === 'security' && (

Security Settings

handleSettingChange('security', 'sessionTimeout', value)} description="Auto-logout after inactivity" icon={Clock} /> handleSettingChange('security', 'passwordPolicy', value)} options={[ { value: 'strong', label: 'Strong (8+ chars, symbols)' }, { value: 'medium', label: 'Medium (6+ chars)' }, { value: 'weak', label: 'Weak (4+ chars)' } ]} description="Minimum password requirements" icon={Lock} /> handleSettingChange('security', 'twoFactorAuth', value)} description="Require 2FA for admin accounts" icon={Key} /> handleSettingChange('security', 'loginAttempts', value)} description="Account lockout threshold" icon={AlertTriangle} /> handleSettingChange('security', 'passwordExpiry', value)} description="Force password change after days" icon={Calendar} />
)} {activeTab === 'users' && (

User Management

handleSettingChange('users', 'defaultUserRole', value)} options={[ { value: 'user', label: 'User' }, { value: 'admin', label: 'Admin' }, { value: 'moderator', label: 'Moderator' } ]} description="Default role for new registrations" icon={Users} /> handleSettingChange('users', 'requireEmailVerification', value)} description="Verify email before account activation" icon={Mail} /> handleSettingChange('users', 'autoActivateUsers', value)} description="Automatically activate new user accounts" icon={Zap} /> handleSettingChange('users', 'allowRegistration', value)} description="Enable public user registration" icon={Users} />
)} {activeTab === 'analytics' && (

Analytics Settings

handleSettingChange('analytics', 'dataRetention', value)} description="How long to keep analytics data" icon={Calendar} /> handleSettingChange('analytics', 'analyticsEnabled', value)} description="Enable system analytics tracking" icon={BarChart3} /> handleSettingChange('analytics', 'realTimeAnalytics', value)} description="Enable real-time data updates" icon={Zap} /> handleSettingChange('analytics', 'trackUserBehavior', value)} description="Track user interactions and patterns" icon={Eye} />
)} {activeTab === 'notifications' && (

Notification Settings

handleSettingChange('notifications', 'emailNotifications', value)} description="Send notifications via email" icon={Mail} /> handleSettingChange('notifications', 'pushNotifications', value)} description="Enable browser push notifications" icon={Bell} /> handleSettingChange('notifications', 'orderAlerts', value)} description="Notify on new orders" icon={AlertTriangle} /> handleSettingChange('notifications', 'systemAlerts', value)} description="System maintenance and error alerts" icon={Info} />
)} {activeTab === 'system' && (

System Settings

handleSettingChange('system', 'maintenanceMode', value)} description="Enable maintenance mode (restricts access)" icon={AlertTriangle} /> handleSettingChange('system', 'debugMode', value)} description="Enable debug logging (development only)" icon={Monitor} /> handleSettingChange('system', 'autoBackup', value)} description="Automatically backup system data" icon={Database} /> handleSettingChange('system', 'backupFrequency', value)} options={[ { value: 'daily', label: 'Daily' }, { value: 'weekly', label: 'Weekly' }, { value: 'monthly', label: 'Monthly' } ]} description="How often to create backups" icon={Calendar} />
)}
{}
); }; export default EnhancedSettings;