import { Box, Chip, Divider, Typography } from '@mui/material' import { Building2, MapPin, Ruler, Calendar } from 'lucide-react' import type { InquiryPreparationReportDraft, ReportObjectFieldKey } from '../../domain/inquiryReport' import type { Property } from '../../domain/property' import type { Inquiry } from '../../domain/inquiry' interface Props { draft: InquiryPreparationReportDraft inquiry: Inquiry properties: Property[] } const FIELD_LABELS: Partial> = { areaSqm: 'Fläche', rentPricePerSqm: 'Mietpreis', availabilityDate: 'Verfügbar ab', leaseTerm: 'Mietlaufzeit', breakoutOption: 'Breakout-Option', breakoutOptionDate: 'Breakout Zeitpunkt', currentTenant: 'Aktueller Mieter', propertyNumber: 'Objektnummer', assetType: 'Asset Type', floor: 'Stockwerk', parking: 'Parkplätze', fitOut: 'Ausbaugrad', isBarrierFree: 'Barrierefrei', ceilingHeightM: 'Raumhöhe', floorLoad: 'Bodenlast', loadingDocksCount: 'Anlieferung', goodsLift: 'Warenaufzug', passengerLift: 'Personenaufzug', powerSupplyKva: 'Stromanschluss', hasServerRoom: 'Serverraum', internet: 'Internet', deliveryAccess: 'Zufahrt', publicTransportScore: 'ÖV-Anbindung', prestigeScore: 'Prestige', visibilityScore: 'Sichtbarkeit', footfallScore: 'Passantenfrequenz', commuterAccessScore: 'Pendlererreichbarkeit', talentAccessScore: 'Talent Access', esgScore: 'ESG', flexibilityScore: 'Flexibilität', expansionPotentialScore: 'Expansionspotenzial', taxEnvironmentScore: 'Steuerumfeld', microLocation: 'Mikrostandort', competitionEnvironment: 'Konkurrenzumfeld', infrastructure: 'Infrastruktur', marketSignals: 'Marktsignale', negotiationHints: 'Verhandlungshinweise', missingData: 'Datenlücken', dataQuality: 'Datenqualität', description: 'Beschreibung', units: 'Stockwerkstruktur', } function getFieldValue(property: Property, key: ReportObjectFieldKey): string | null { switch (key) { case 'areaSqm': return property.areaSqm ? `${property.areaSqm.toLocaleString('de-CH')} m²` : null case 'rentPricePerSqm': return property.rentPricePerSqm ? `CHF ${property.rentPricePerSqm}/m²/Jahr` : null case 'availabilityDate': return property.availabilityDate ? new Date(property.availabilityDate).toLocaleDateString('de-CH') : null case 'leaseTerm': return property.leaseTerm ?? null case 'breakoutOption': return property.breakoutOption != null ? (property.breakoutOption ? 'Ja' : 'Nein') : null case 'currentTenant': return property.currentTenant ?? null case 'propertyNumber': return property.propertyNumber ?? null case 'assetType': return property.assetType ?? null case 'floor': return property.floorLevel != null ? String(property.floorLevel) : null case 'parking': return property.softFactors?.parkingSpots != null ? `${property.softFactors.parkingSpots} Plätze` : null case 'ceilingHeightM': return property.hardFacts?.ceilingHeightM != null ? `${property.hardFacts.ceilingHeightM} m` : null case 'loadingDocksCount': return property.hardFacts?.loadingDocksCount != null ? String(property.hardFacts.loadingDocksCount) : null case 'powerSupplyKva': return property.hardFacts?.powerSupplyKva != null ? `${property.hardFacts.powerSupplyKva} kVA` : null case 'hasServerRoom': return property.hardFacts?.hasServerRoom != null ? (property.hardFacts.hasServerRoom ? 'Ja' : 'Nein') : null case 'isBarrierFree': return property.hardFacts?.isBarrierFree != null ? (property.hardFacts.isBarrierFree ? 'Ja' : 'Nein') : null case 'fitOut': return property.hardFacts?.fitOut ?? null case 'publicTransportScore': return property.softFactors?.publicTransportMinutes != null ? `${property.softFactors.publicTransportMinutes} Min.` : null case 'prestigeScore': return property.softFactors?.prestige != null ? `${property.softFactors.prestige}/100` : null case 'visibilityScore': return property.softFactors?.visibilityScore != null ? `${property.softFactors.visibilityScore}/100` : null case 'description': return property.description ?? null default: return null } } export function LatentInquiryReportPreview({ draft, inquiry, properties }: Props) { const editableByField = Object.fromEntries(draft.editableFields.map(f => [f.id, f.value])) const selectedProps = draft.selectedPropertyIds .map(id => properties.find(p => p.id === id)) .filter((p): p is Property => !!p) return ( {/* Page 1 — Need Summary */} Objektvorschlag Wincasa AG · {new Date().toLocaleDateString('de-CH')} {editableByField['intro'] && ( {editableByField['intro']} )} Ihre Anfrage Kontakt: {inquiry.tenantName}{inquiry.tenantCompany ? ` · ${inquiry.tenantCompany}` : ''} Betreff: {inquiry.subject} {editableByField['highlights'] && ( <> Warum diese Objekte passen {editableByField['highlights']} )} {selectedProps.map(p => ( } sx={{ bgcolor: '#e0e7ff', color: '#1e3a5f', fontWeight: 600 }} /> ))} {/* Page 2+ — One section per property */} {selectedProps.map((property, idx) => { const selection = draft.fieldSelections.find(fs => fs.propertyId === property.id) const optionalFields = selection?.selectedOptionalFields ?? [] const image = property.images?.[0] return ( Objekt {idx + 1} von {selectedProps.length} {/* Map placeholder */} {!property.mapImageUrl && } {/* Property photo */} {!image && } {property.title} {property.location.city}{property.location.district ? `, ${property.location.district}` : ''} {property.areaSqm.toLocaleString('de-CH')} m² {new Date(property.availabilityDate).toLocaleDateString('de-CH')} {optionalFields.length > 0 && ( {optionalFields.map(key => { const val = getFieldValue(property, key) if (!val) return null return ( {FIELD_LABELS[key] ?? key} {val} ) })} )} ) })} {editableByField['next_steps'] && ( Nächste Schritte {editableByField['next_steps']} )} ) }