import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { motion, AnimatePresence } from 'framer-motion';
import { useTheme } from '../context/ThemeContext';
import { useMockStore } from '../data/mockStore';
import { usePermissions } from '../hooks/usePermissions';
import PermissionGate from '../components/PermissionGate';
import {
Plus, Search, MapPin, Phone, Zap, FileText,
Clock, User, ChevronRight, Filter, Lock,
DoorOpen, MessageSquare,
} from 'lucide-react';
// ---------------------------------------------------------------------------
// Urgency badge
// ---------------------------------------------------------------------------
const URGENCY_CONFIG = {
standard: { label: 'Standard', bg: 'bg-zinc-200 dark:bg-zinc-700', text: 'text-zinc-600 dark:text-zinc-300' },
high: { label: 'High', bg: 'bg-amber-100 dark:bg-amber-500/20', text: 'text-amber-700 dark:text-amber-400' },
emergency: { label: 'Emergency', bg: 'bg-red-100 dark:bg-red-500/20', text: 'text-red-700 dark:text-red-400' },
};
const STATUS_CONFIG = {
New: { bg: 'bg-blue-100 dark:bg-blue-500/20', text: 'text-blue-700 dark:text-blue-400' },
Contacted: { bg: 'bg-purple-100 dark:bg-purple-500/20', text: 'text-purple-700 dark:text-purple-400' },
Appointed: { bg: 'bg-emerald-100 dark:bg-emerald-500/20', text: 'text-emerald-700 dark:text-emerald-400' },
Closed: { bg: 'bg-zinc-100 dark:bg-zinc-700', text: 'text-zinc-500 dark:text-zinc-400' },
};
function UrgencyBadge({ urgency }) {
const cfg = URGENCY_CONFIG[urgency] ?? URGENCY_CONFIG.standard;
return (
{cfg.label}
);
}
function StatusBadge({ status }) {
const cfg = STATUS_CONFIG[status] ?? STATUS_CONFIG.New;
return (
{status}
);
}
// ---------------------------------------------------------------------------
// Relative time formatter
// ---------------------------------------------------------------------------
function timeAgo(isoString) {
const diff = Math.floor((Date.now() - new Date(isoString)) / 1000);
if (diff < 60) return 'just now';
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
return `${Math.floor(diff / 86400)}d ago`;
}
// ---------------------------------------------------------------------------
// Lead Card
// ---------------------------------------------------------------------------
function LeadCard({ lead, index }) {
const { theme } = useTheme();
const isDark = theme === 'dark';
const primaryPhone = lead.phones?.find(p => p.isPrimary) ?? lead.phones?.[0];
return (
No Leads Yet
Capture your first lead at the door or from the office.
{leads.length} total lead{leads.length !== 1 ? 's' : ''}