import React, { useState, useMemo } from 'react'; import { DomaApplication, DomaApplicationStatus } from '../../types'; import { Search, Clock, User, HardHat, ExternalLink, RotateCw } from 'lucide-react'; import { ApplicationCardDetail } from './ApplicationCardDetail'; interface Props { applications: DomaApplication[]; onRefresh?: () => void; } const statusConfig = { new: { label: 'Новая', color: 'bg-red-500', textColor: 'text-red-600', bgColor: 'bg-red-100' }, in_progress: { label: 'В работе', color: 'bg-blue-500', textColor: 'text-blue-600', bgColor: 'bg-blue-100' }, deferred: { label: 'Отложена', color: 'bg-orange-500', textColor: 'text-orange-600', bgColor: 'bg-orange-100' }, done: { label: 'Выполнена', color: 'bg-emerald-500', textColor: 'text-emerald-600', bgColor: 'bg-emerald-100' }, canceled: { label: 'Отменена', color: 'bg-slate-400', textColor: 'text-slate-600', bgColor: 'bg-slate-100' }, }; export const ApplicationsRegistry: React.FC = ({ applications, onRefresh }) => { const [search, setSearch] = useState(''); const [filter, setFilter] = useState('all'); const [openCardId, setOpenCardId] = useState(null); const filtered = useMemo(() => { return applications.filter(app => { const matchesSearch = app.address.toLowerCase().includes(search.toLowerCase()) || app.number.toLowerCase().includes(search.toLowerCase()); const matchesFilter = filter === 'all' || app.status === filter; return matchesSearch && matchesFilter; }).sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()); }, [applications, search, filter]); return (
setSearch(e.target.value)} className="w-full pl-11 pr-4 py-3 bg-white border border-slate-200 rounded-2xl text-sm outline-none focus:ring-2 focus:ring-primary-500 shadow-sm" /> {onRefresh && ( )}
{['all', 'new', 'in_progress', 'deferred', 'done'].map((f) => ( ))}
{filtered.map(app => ( setOpenCardId(app.id)} /> ))} {filtered.length === 0 && (
Заявки не найдены
)}
{openCardId !== null && ( setOpenCardId(null)} onUpdated={onRefresh} /> )}
); }; const ApplicationCard: React.FC<{ application: DomaApplication; onOpenCard: () => void }> = ({ application, onOpenCard }) => { const { label, color, textColor, bgColor } = statusConfig[application.status]; const timeSince = (dateStr: string) => { const date = new Date(dateStr); const seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000); if (seconds < 3600) return Math.floor(seconds/60) + " мин. назад"; if (seconds < 86400) return Math.floor(seconds/3600) + " ч. назад"; return Math.floor(seconds/86400) + " д. назад"; }; const handleCardClick = (e: React.MouseEvent) => { const target = e.target as HTMLElement; if (target.closest('a[href]')) return; onOpenCard(); }; return (

{application.address}, кв. {application.apartment}

{application.description}

{timeSince(application.createdAt)}
{application.clientName}
{application.performer && (
{application.performer.name}
)}
); };