"use client"; import { useState } from "react"; import { Clock, CheckCircle2, X, History, ShieldCheck, Building2 } from "lucide-react"; import { Badge } from "@/shared/components/ui/badge"; import { Button } from "@/shared/components/ui/button"; import type { TrackedDeadline } from "../types"; import { getDeadlineType } from "../services/deadline-catalog"; import { getDeadlineDisplayStatus } from "../services/deadline-service"; import { cn } from "@/shared/lib/utils"; interface DeadlineCardProps { deadline: TrackedDeadline; onResolve: (deadline: TrackedDeadline) => void; onRemove: (deadlineId: string) => void; } const VARIANT_CLASSES: Record = { green: "border-green-500/30 bg-green-50 dark:bg-green-950/20", yellow: "border-yellow-500/30 bg-yellow-50 dark:bg-yellow-950/20", red: "border-red-500/30 bg-red-50 dark:bg-red-950/20", blue: "border-blue-500/30 bg-blue-50 dark:bg-blue-950/20", gray: "border-muted bg-muted/30", }; const BADGE_CLASSES: Record = { green: "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200", yellow: "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200", red: "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200", blue: "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200", gray: "bg-muted text-muted-foreground", }; export function DeadlineCard({ deadline, onResolve, onRemove, }: DeadlineCardProps) { const def = getDeadlineType(deadline.typeId); const status = getDeadlineDisplayStatus(deadline); const [showAudit, setShowAudit] = useState(false); const auditLog = deadline.auditLog ?? []; const isAutoTrack = def?.autoTrack === true; const isVerificationDeadline = deadline.typeId === "cu-verificare"; const isCJDeadline = deadline.typeId === "cu-cj-solicitare-aviz" || deadline.typeId === "cu-cj-aviz-primar"; // For verification deadlines, check if the 10-day period has passed const verificationExpired = isVerificationDeadline && deadline.resolution === "pending" && status.daysRemaining !== null && status.daysRemaining < 0; return (
{isAutoTrack ? ( isCJDeadline ? ( ) : ( ) ) : ( )}
{def?.label ?? deadline.typeId} {isAutoTrack && ( auto )} {status.label} {status.daysRemaining !== null && status.variant !== "blue" && ( ( {status.daysRemaining < 0 ? `${Math.abs(status.daysRemaining)}z depasit` : `${status.daysRemaining}z`} ) )}
{/* Verification badge: institution lost right to return docs */} {verificationExpired && (
Nu mai pot returna documentatia
)} {/* Interruption badge */} {deadline.resolution === "intrerupt" && (
Intrerupt — completari solicitate
)}
{def?.isBackwardDeadline ? "Termen limita" : "Start"}:{" "} {formatDate(deadline.startDate)} {" \u2192 "} {def?.isBackwardDeadline ? "Depunere pana la" : "Termen"}:{" "} {formatDate(deadline.dueDate)} {def?.dayType === "working" && ( (zile lucratoare) )}
{auditLog.length > 0 && ( )} {deadline.resolution === "pending" && ( )}
{/* Audit log */} {showAudit && auditLog.length > 0 && (

Istoric modificări

{auditLog.map((entry, i) => (
{formatDateTime(entry.timestamp)} {entry.actor && ( {entry.actor} )} {entry.detail}
))}
)}
); } function formatDate(iso: string): string { try { return new Date(iso).toLocaleDateString("ro-RO", { day: "2-digit", month: "2-digit", year: "numeric", }); } catch { return iso; } } function formatDateTime(iso: string): string { try { return new Date(iso).toLocaleString("ro-RO", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", }); } catch { return iso; } }