import { useState } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import {
User,
Bell,
Shield,
Database,
Monitor,
RefreshCw,
Power,
Server,
Smartphone,
Wifi,
Copy,
Check,
ChevronDown,
type LucideIcon,
} from 'lucide-react';
import { useStore } from '@/store/useStore';
import { useCurrency, CURRENCY_OPTIONS } from '@/store/useCurrencyStore';
import type { CurrencyCode } from '@/store/useCurrencyStore';
// ── Design tokens (matching inventory glassmorphism) ─────────────────────────
const GLASS = {
background: 'rgba(14, 16, 21, 0.72)',
border: '1px solid rgba(255,255,255,0.08)',
backdropFilter: 'blur(18px)',
WebkitBackdropFilter: 'blur(18px)',
} as const;
const INNER_SURFACE = {
background: 'rgba(255,255,255,0.04)',
border: '1px solid rgba(255,255,255,0.07)',
} as const;
// ── Shared primitives ────────────────────────────────────────────────────────
function GlassCard({
children,
delay = 0,
className = '',
}: {
children: React.ReactNode;
delay?: number;
className?: string;
}) {
return (
{children}
);
}
function SectionHeader({ icon: Icon, title, accent = 'hsl(var(--accent))' }: { icon: LucideIcon; title: string; accent?: string }) {
return (
{open && (
{options.map((opt) => (
))}
)}
{open &&
setOpen(false)} />}
);
}
// ── Ghost button ─────────────────────────────────────────────────────────────
function GhostButton({ children, onClick, danger = false }: { children: React.ReactNode; onClick?: () => void; danger?: boolean }) {
return (
{children}
);
}
// ── Text input ───────────────────────────────────────────────────────────────
function DarkInput({ type = 'text', defaultValue, placeholder }: { type?: string; defaultValue?: string; placeholder?: string }) {
return (
{ e.currentTarget.style.border = '1px solid hsl(var(--accent) / 0.4)'; }}
onBlur={(e) => { e.currentTarget.style.border = '1px solid rgba(255,255,255,0.07)'; }}
/>
);
}
// ── System Status ────────────────────────────────────────────────────────────
function SystemStatusCard() {
const { status, updateStatus } = useStore();
return (
{/* Connection pill */}
Backend Connection
{status.isConnected ? 'Connected to local server' : 'Connection lost'}
{status.serverStatus.toUpperCase()}
{/* Version / sync grid */}
{[
{ label: 'Version', value: status.version },
{ label: 'Last Sync', value: status.lastSync.toLocaleTimeString() },
].map(({ label, value }) => (
))}
{/* Actions */}
updateStatus({ serverStatus: 'syncing' })}
>
Sync Now
Restart
);
}
// ── iOS Device Connection ────────────────────────────────────────────────────
function IOSConnectionCard() {
const [paired, setPaired] = useState(false);
const [pairing, setPairing] = useState(false);
const [copied, setCopied] = useState(false);
const pairingCode = 'VLC-7F3A-9B2D';
const deviceIp = '192.168.1.42:8765';
const handlePair = () => {
setPairing(true);
setTimeout(() => { setPairing(false); setPaired(true); }, 2000);
};
const handleCopy = (text: string) => {
void navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 1800);
};
return (
{/* Status */}
{paired ? 'iPhone Paired' : 'No Device Paired'}
{paired ? "Ahmed’s iPhone 15 Pro" : 'Open Velocity iOS app to connect'}
{paired
?
CONNECTED
:
}
{/* Pairing code */}
Pairing Code
{pairingCode}
Local IP: {deviceIp}
{/* Actions */}
{pairing ? (
<> Pairing…>
) : paired ? (
<> Paired>
) : (
<> Pair Device>
)}
{paired && (
setPaired(false)} danger>Unpair
)}
{/* Push notifications toggle */}
Push Notifications
Send alerts to paired iPhone
{ }} />
);
}
// ── Profile ──────────────────────────────────────────────────────────────────
function ProfileSettings() {
const { user } = useStore();
const initials = user?.name.split(' ').map((n) => n[0]).join('') ?? 'AA';
return (
{initials}
{user?.name}
{user?.role === 'sales_director' ? 'Sales Director' : 'Administrator'}
);
}
// ── Notifications ────────────────────────────────────────────────────────────
function NotificationSettings() {
const [s, setS] = useState({ newLeads: true, sentimentAlerts: true, viewings: true, systemUpdates: false, emailDigest: true });
const rows: { key: keyof typeof s; label: string; desc: string }[] = [
{ key: 'newLeads', label: 'New Lead Alerts', desc: 'Get notified when a new lead is captured' },
{ key: 'sentimentAlerts', label: 'Sentiment Alerts', desc: 'Alert when visitor sentiment drops' },
{ key: 'viewings', label: 'Viewing Reminders', desc: 'Reminders for scheduled viewings' },
{ key: 'systemUpdates', label: 'System Updates', desc: 'Notifications about system maintenance' },
{ key: 'emailDigest', label: 'Daily Email Digest', desc: 'Summary of daily activity' },
];
return (
{rows.map(({ key, label, desc }) => (
setS({ ...s, [key]: v })} />
))}
);
}
// ── Security ─────────────────────────────────────────────────────────────────
function SecuritySettings() {
const [twoFactor, setTwoFactor] = useState(true);
const [biometric, setBiometric] = useState(true);
const [timeout, setTimeout_] = useState('30');
return (
Change
Manage
);
}
// ── Display ──────────────────────────────────────────────────────────────────
function DisplaySettings() {
const [reducedMotion, setReducedMotion] = useState(false);
const [compactMode, setCompactMode] = useState(false);
const [language, setLanguage] = useState('en');
const [timezone, setTimezone] = useState('dxb');
const { currency, setCurrency } = useCurrency();
return (
{/* ── Currency ── */}
setCurrency(v as CurrencyCode)}
options={CURRENCY_OPTIONS.map((o) => ({
value: o.code,
label: `${o.flag} ${o.symbol} — ${o.label}`,
}))}
/>
);
}
// ── Data & Privacy ───────────────────────────────────────────────────────────
function DataSettings() {
const [retention, setRetention] = useState('90');
return (
{ }} />
Export
Clear
);
}
// ── About ────────────────────────────────────────────────────────────────────
function AboutSection() {
return (
V
Velocity WebOS
Real Estate Operating System
Version 2.1.0
•
Build 2024.02.18
{['Terms of Service', 'Privacy Policy', 'Documentation'].map((label) => (
))}
);
}
// ── Main ─────────────────────────────────────────────────────────────────────
export function Settings() {
return (
{/* Row 1: System + iOS */}
{/* Row 2: Profile + Notifications */}
{/* Row 3: Security + Display */}
{/* Row 4: Data + About */}
);
}