import { useState, useEffect } from 'react' import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, TextField, Typography, } from '@mui/material' import { Send } from 'lucide-react' import { useToastStore } from '../../stores/toastStore' import { useInquiryStore } from '../../stores/inquiryStore' import { useMoveStage } from '../../hooks/usePipeline' import { DS_BG, DS_BORDER, DS_TEXT } from '../../lib/ds' function buildTemplate(propertyTitle: string, location: string, areaLabel?: string): string { const areaLine = areaLabel ? `\nDie Fläche von ${areaLabel} entspricht unserem Bedarf.` : '' return `Guten Tag\n\nWir interessieren uns für Ihre Fläche «${propertyTitle}» in ${location}.${areaLine} Gerne würden wir einen Besichtigungstermin vereinbaren und offene Fragen klären.\n\nFür Rückfragen stehen wir jederzeit zur Verfügung.\n\nFreundliche Grüsse` } export function InquiryQuickDialog() { const showToast = useToastStore(s => s.showToast) const dialogOpen = useInquiryStore(s => s.dialogOpen) const pendingInquiry = useInquiryStore(s => s.pendingInquiry) const closeInquiryDialog = useInquiryStore(s => s.closeInquiryDialog) const addInquiry = useInquiryStore(s => s.addInquiry) const { mutate: moveStage } = useMoveStage() const [message, setMessage] = useState('') useEffect(() => { if (dialogOpen && pendingInquiry) { setMessage(buildTemplate(pendingInquiry.propertyTitle, pendingInquiry.location, pendingInquiry.areaLabel)) } }, [dialogOpen, pendingInquiry]) function handleSend() { if (!pendingInquiry) return addInquiry(pendingInquiry, message) if (pendingInquiry.pipelineItemId) { moveStage({ id: pendingInquiry.pipelineItemId, stage: 'CONTACTED' }) } showToast('Anfrage gesendet — Sie erhalten eine Antwort per E-Mail.', 'success') closeInquiryDialog() } if (!pendingInquiry) return null return ( Anfrage senden {pendingInquiry.propertyTitle} {pendingInquiry.location} {pendingInquiry.areaLabel && ` · ${pendingInquiry.areaLabel}`} {pendingInquiry.rentLabel && ` · ${pendingInquiry.rentLabel}`} {' · '}Match {pendingInquiry.matchScore}% setMessage(e.target.value)} sx={{ '& .MuiInputBase-root': { fontSize: '0.875rem' } }} /> Der Text kann vor dem Absenden angepasst werden. ) }