import { useState } from 'react' import { useNavigate } from 'react-router' import { Box, Button, Chip, Divider, IconButton, TextField, Tooltip, Typography, } from '@mui/material' import { AlertTriangle, ChevronRight, CheckCircle, ExternalLink, FileText, MapPin, MessageSquare, Sparkles, StickyNote, X, } from 'lucide-react' import { useMoveStage, useUpdateNotes, useLoseItem } from '../../hooks/usePipeline' import type { PipelineItem } from '../../domain/pipeline' import { STAGES, NEXT_STAGE, MOCK_DOCS } from './pipelineConstants' import { scoreColor, detailPath, getKiInsight } from './pipelineUtils' import { DS_TEXT, DS_SURFACE, DS_BORDER, DS_PRE_MARKET, DS_COLORS } from '../../lib/ds' // ── DetailPanel ─────────────────────────────────────────────────────────────── export function DetailPanel({ item, onClose }: { item: PipelineItem; onClose: () => void }) { const navigate = useNavigate() const { mutate: moveStage } = useMoveStage() const { mutate: updateNotes } = useUpdateNotes() const { mutate: loseItem } = useLoseItem() const path = detailPath(item) const [notes, setNotes] = useState(item.notes ?? '') const stageConfig = STAGES.find(s => s.key === item.stage)! const stageIndex = STAGES.findIndex(s => s.key === item.stage) const nextStage = NEXT_STAGE[item.stage] const ki = getKiInsight(item) const docs = MOCK_DOCS[item.id] ?? [] const isClosed = item.stage === 'CLOSED_WON' || item.stage === 'CLOSED_LOST' const progressIdx = Math.min(stageIndex, 4) return ( {/* Header */} {item.title} {item.location} {item.matchScore}% {path && ( navigate(path)} sx={{ color: DS_TEXT.muted, '&:hover': { color: DS_TEXT.brand } }}> )} {STAGES.slice(0, 5).map((s, idx) => ( ))} {item.inquiryId && ( } label="Chat" size="small" onClick={() => navigate(`/demand/anfragen?inquiry=${item.inquiryId}`)} sx={{ height: 22, fontSize: '0.75rem', cursor: 'pointer', bgcolor: DS_SURFACE.blue.bg, color: DS_TEXT.brand, fontWeight: 600, border: `1px solid ${DS_SURFACE.blue.border}`, '& .MuiChip-icon': { color: DS_TEXT.brand }, '&:hover': { bgcolor: DS_COLORS.futureCard.signal.badgeBg }, }} /> )} {/* Property / unit address */} {item.propertyAddress && ( {item.propertyAddress} )} {/* KI */} KI Einschätzung {ki.summary} {ki.positives.map((p, i) => ( {p} ))} {ki.risks.map((r, i) => ( {r} ))} {/* Stage actions */} {!isClosed && ( Nächste Aktion {nextStage && ( )} )} {/* Notes */} Notizen setNotes(e.target.value)} onBlur={() => updateNotes({ id: item.id, notes })} sx={{ '& .MuiOutlinedInput-root': { fontSize: '0.8rem', borderRadius: 1.5 } }} /> {/* Documents */} Dokumente {docs.length === 0 ? ( Noch keine Dokumente. ) : ( {docs.map((doc, i) => ( {doc.name} {doc.date} ))} )} {item.availabilityLabel && Verfügbar: {item.availabilityLabel}} {item.assignedTo && Verantwortlich: {item.assignedTo}} Hinzugefügt: {new Date(item.addedAt).toLocaleDateString('de-CH')} ) }