import { Box, Button, Divider, LinearProgress, MenuItem, TextField, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material' import { ExternalLink, FileText } from 'lucide-react' import type { Property, UpdatePropertyInput } from '../../domain/property' import { PropertyMap } from '../shared' import { getAssetTypeLabel, qualityColor } from './propertyHelpers' import { Field, FieldGrid, SectionTitle } from './PropertyDetailHelpers' import { UnitStructurePanel } from './UnitStructurePanel' import { PreMarketPanel } from './PreMarketPanel' import { FIT_OUT_LABELS } from '../../lib/constants' import { FIT_OUT_OPTIONS } from '../../pages/supply/newListingConstants' // Stufen, die noch Mieterausbau benötigen — nur dann ist die Träger-Frage relevant const FIT_OUT_NEEDS_BUILD = new Set(['SHELL', 'BASIC']) interface PropertyDetailOverviewProps { p: Property editing: boolean draft: UpdatePropertyInput onDraftChange: (d: UpdatePropertyInput) => void } export function PropertyDetailOverview({ p, editing, draft, onDraftChange }: PropertyDetailOverviewProps) { // Mehr-Einheiten-Objekt: Preis als Spanne, Fläche mit Anzahl, Verfügbarkeit pro Einheit const units = p.units ?? [] const isMultiUnit = units.length > 1 const unitPrices = units.map(u => u.rentPricePerSqm ?? p.rentPricePerSqm).filter(v => v > 0) const priceMin = unitPrices.length ? Math.min(...unitPrices) : p.rentPricePerSqm const priceMax = unitPrices.length ? Math.max(...unitPrices) : p.rentPricePerSqm const rentLabel = isMultiUnit && priceMin !== priceMax ? `CHF ${priceMin.toLocaleString('de-CH')}–${priceMax.toLocaleString('de-CH')}` : p.rentPricePerSqm > 0 ? `CHF ${p.rentPricePerSqm.toLocaleString('de-CH')}` : undefined const areaLabel = isMultiUnit ? `${p.areaSqm.toLocaleString('de-CH')} m² · ${units.length} Einheiten` : `${p.areaSqm.toLocaleString('de-CH')} m²` const availLabel = isMultiUnit ? 'pro Einheit ↓' : p.availabilityDate ? new Date(p.availabilityDate).toLocaleDateString('de-CH') : undefined // Effektive (Draft-überlagerte) hardFacts für den Bearbeiten-Modus const hf = draft.hardFacts ?? p.hardFacts ?? {} const editFitOut = hf.fitOut ?? '' const editByLandlord = hf.fitOutByLandlord const showBuildResponsibility = FIT_OUT_NEEDS_BUILD.has(editFitOut) const patchHF = (patch: Partial>) => onDraftChange({ ...draft, hardFacts: { ...hf, ...patch } }) return ( {/* Key metrics */} {[ { label: 'Fläche', value: areaLabel }, { label: isMultiUnit ? 'CHF/m²/Jahr (Spanne)' : 'CHF/m²/Jahr', value: rentLabel }, { label: 'Verfügbar ab', value: availLabel }, ].map(({ label, value }) => ( {label} {value ?? k.A.} ))} {p.propertyNumber && ( Objekt-Nr. {p.propertyNumber} )} {/* Description */} {editing ? ( onDraftChange({ ...draft, description: e.target.value })} placeholder="Beschreibung des Objekts…" /> ) : p.description ? ( {p.description} ) : null} {/* Floor / unit structure — primary tenant/lease view */} {/* Fallback: property-level contract doc only when no unit-level contracts exist */} {(() => { const hasUnitContracts = p.units?.some(u => u.leases?.some(l => l.contractDocumentUrl)) if (editing) { return ( Gebäude-Mietvertrag (Fallback) onDraftChange({ ...draft, leaseContractUrl: e.target.value })} placeholder="https://…" slotProps={{ input: { startAdornment: } }} /> onDraftChange({ ...draft, leaseContractName: e.target.value })} placeholder="z.B. Mietvertrag 2021–2026" /> ) } if (!p.leaseContractUrl || hasUnitContracts) return null return ( {p.leaseContractName ?? 'Mietvertrag'} ) })()} {/* Pre-Market Matching */} {/* Object details */} {editing ? ( patchHF({ fitOut: (e.target.value || undefined) as 'SHELL' | 'BASIC' | 'FULL' | 'PREMIUM' | undefined })} > {FIT_OUT_OPTIONS.map(o => {o.label})} patchHF({ parking: parseInt(e.target.value) || undefined })} /> patchHF({ ceilingHeightM: parseFloat(e.target.value) || undefined })} /> {showBuildResponsibility && ( Wer baut aus? * { if (v) patchHF({ fitOutByLandlord: v === 'landlord', ...(v === 'landlord' ? { mieterausbaubeitragPerSqm: undefined } : {}) }) }} > Vermieter übernimmt Mieter baut aus {editByLandlord === undefined && ( Pflichtangabe bei Rohbau/Edelrohbau )} {editByLandlord === false && ( patchHF({ mieterausbaubeitragPerSqm: parseInt(e.target.value) || undefined })} /> )} )} ) : ( {p.propertyNumber && } {p.hardFacts?.fitOut && FIT_OUT_NEEDS_BUILD.has(p.hardFacts.fitOut) && ( )} {p.hardFacts?.mieterausbaubeitragPerSqm && !p.hardFacts.fitOutByLandlord && ( )} )} {/* Map */} {p.location.coordinates && ( Standort {p.address.street} {p.address.houseNumber}, {p.address.postalCode} {p.address.city} )} {/* Data quality */} Score {Math.round(p.dataQuality.score * 100)}% {p.dataQuality.warnings.length > 0 && ( {p.dataQuality.warnings.map((w, i) => ( ⚠ {w} ))} )} ) }