"use client"; import { FormEvent, useEffect, useRef, useState } from "react"; import Link from "next/link"; import { Building2, Check, SendHorizontal, UserRound, HardHat, TrafficCone } from "lucide-react"; import type { DemoChatTurn } from "@/lib/chat-demo/assistant"; const bullets = [ "Projekt-Kanäle für jedes Vorhaben", "Dateien & Fotos direkt teilen", "Aufgaben aus dem Chat erstellen", "Desktop & Mobile synchronisiert", ]; const CHAT_BACKGROUND = "hsl(30 17% 95.5%)"; const CHAT_MONOGRAM_PATTERN = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Cpath d='M14 10v8M10 14h8' stroke='%23C4931E' stroke-opacity='0.14' stroke-width='1' stroke-linecap='round'/%3E%3C/svg%3E\")"; // Own messages use the site's secondary colour (teal), not orange. const OWN_BUBBLE_BACKGROUND = "#0D6E6E"; const OWN_BUBBLE_BORDER = "#0A5A5A"; const OTHER_BUBBLE_BACKGROUND = "#FFFFFF"; const OTHER_BUBBLE_BORDER = "#E9E7E5"; const OTHER_BUBBLE_TIME = "#7A726C"; const OTHER_BUBBLE_SENDER = "#F59F0A"; type DemoMessageAuthor = "team" | "self" | "assistant"; type DemoMessage = { id: string; sender: string; text: string; time: string; author: DemoMessageAuthor; }; type ChatDemoSectionProps = { showSideContent?: boolean; /** WIP / "coming soon" state — the mobile app isn't out yet, so the phone is * blurred behind a construction-themed overlay. */ comingSoon?: boolean; }; // Construction "Absperrband" — brand amber / dark hazard stripes. const HAZARD_STRIPES = "repeating-linear-gradient(45deg, #F1B729 0 10px, #171106 10px 20px)"; // Barrier tape ("Absperrband") stretched diagonally across the blurred phone — // reads as "cordoned off / under construction", not a generic badge. Clipped to // the phone's rounded bounds so the ends cut off like real tape. function ComingSoonTape() { return (
{Array.from({ length: 6 }).map((_, i) => ( Bald verfügbar ))}
); } // Construction-themed copy that fills the whitespace next to the phone. function ComingSoonAside() { return (
{/* mini Absperrband accent */}

Der Chat für unterwegs wird gerade gebaut.

Die mobile App legen wir gerade auf die Baustelle. Am Desktop bist du schon voll dabei — die Version fürs Handy folgt in Kürze.

In Arbeit · noch ohne Termin, aber unterwegs.
); } const seedMessages: DemoMessage[] = [ { id: "m-1", sender: "Murat Kaya", text: "Foto vom Heizungskeller hochgeladen.", time: "09:12", author: "team", }, { id: "m-2", sender: "Lea Brandt", text: "Aufmaß ist fertig, schicke gleich die Unterlagen.", time: "09:15", author: "team", }, { id: "m-3", sender: "Du", text: "Super, dann können wir morgen mit der Installation anfangen. 👍", time: "09:17", author: "self", }, { id: "m-4", sender: "Murat Kaya", text: "Material ist bestellt, Lieferung Donnerstag.", time: "09:20", author: "team", }, { id: "m-5", sender: "Daniel Reiter", text: "Hinweis: Für morgen fehlt noch eine verbindliche Terminbestätigung vom Kunden.", time: "09:21", author: "assistant", }, ]; function nowTimeLabel(): string { return new Intl.DateTimeFormat("de-DE", { hour: "2-digit", minute: "2-digit" }).format(new Date()); } function createMessageId(): string { if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") { return crypto.randomUUID(); } return `demo-${Date.now()}-${Math.random().toString(16).slice(2)}`; } function toConversationTurns(messages: DemoMessage[]): DemoChatTurn[] { return messages .filter((msg) => msg.author !== "team") .map((msg) => ({ role: msg.author === "self" ? "user" : "assistant", content: msg.text, })); } async function requestAssistantReply(message: string, conversation: DemoChatTurn[]): Promise { const response = await fetch("/api/demo-chat/reply", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message, conversation }), }); if (!response.ok) { throw new Error("assistant_unavailable"); } const data = (await response.json()) as { reply?: unknown }; if (typeof data.reply !== "string" || !data.reply.trim()) { throw new Error("assistant_invalid"); } return data.reply.trim(); } export default function ChatDemoSection({ showSideContent = true, comingSoon = false }: ChatDemoSectionProps) { const phoneRef = useRef(null); const [messages, setMessages] = useState(seedMessages); const [draft, setDraft] = useState(""); const [isReplying, setIsReplying] = useState(false); const [sendError, setSendError] = useState(null); const scrollRef = useRef(null); useEffect(() => { const container = scrollRef.current; if (!container) { return; } container.scrollTop = container.scrollHeight; }, [messages, isReplying]); useEffect(() => { const phoneEl = phoneRef.current; if (!phoneEl) { return; } const handleNativeWheel = (event: WheelEvent) => { const container = scrollRef.current; if (!container) { return; } if (container.scrollHeight <= container.clientHeight) { return; } event.preventDefault(); event.stopPropagation(); container.scrollTop += event.deltaY; }; phoneEl.addEventListener("wheel", handleNativeWheel, { passive: false }); return () => { phoneEl.removeEventListener("wheel", handleNativeWheel); }; }, []); async function handleSubmit(event: FormEvent) { event.preventDefault(); const trimmed = draft.trim(); if (!trimmed || isReplying) { return; } const userMessage: DemoMessage = { id: createMessageId(), sender: "Du", text: trimmed, time: nowTimeLabel(), author: "self", }; const nextConversation = [...messages, userMessage]; setMessages(nextConversation); setDraft(""); setSendError(null); setIsReplying(true); try { const [replyText] = await Promise.all([ requestAssistantReply(trimmed, toConversationTurns(nextConversation)), new Promise((resolve) => setTimeout(resolve, 520)), ]); setMessages((prev) => [ ...prev, { id: createMessageId(), sender: "Daniel Reiter", text: replyText, time: nowTimeLabel(), author: "assistant", }, ]); } catch { setSendError("Antwort konnte gerade nicht geladen werden."); } finally { setIsReplying(false); } } return (
{comingSoon ? : null} {showSideContent ? (
KOMMUNIKATION

Ihr Team bleibt vernetzt, informiert und abgestimmt.

) : null} {/* Phone mockup (wrapped so the coming-soon overlay can sit on top) */}
{/* Status bar */}
9:41
{/* Chat header */}

Heizungsprojekt Schulz

4 Mitglieder · 2 online

{/* Messages */}
{messages.map((msg) => (
{msg.author !== "self" && (
)}
{msg.author !== "self" ? (

{msg.sender}

) : null} {msg.text}

{msg.time}

))}
{sendError ? (
{sendError}
) : null} {/* Input */}
{ void handleSubmit(event); }} className="flex items-center gap-2 shrink-0" style={{ height: 56, background: "#FFFFFF", padding: "0 12px", borderTop: "1px solid #E5E7EB", }} > setDraft(event.target.value)} placeholder="Nachricht schreiben..." className="flex-1 min-w-0 rounded-full text-[14px]" style={{ background: "#FFFFFF", height: 36, padding: "0 14px", color: "#111827", fontSize: 14, outline: "none", border: "1px solid #E5E7EB", }} />
{/* Home indicator */}
{comingSoon ? : null}
{showSideContent ? ( <>
KOMMUNIKATION

Ihr Team bleibt vernetzt, informiert und abgestimmt.

So vertraut wie WhatsApp, aber fürs Handwerk gebaut: Alle Fotos, Aufgaben und Absprachen sind projektbezogen und zentral dokumentiert.

    {bullets.map((b) => (
  • {b}
  • ))}
Chat App entdecken →

So vertraut wie WhatsApp, aber fürs Handwerk gebaut: Alle Fotos, Aufgaben und Absprachen sind projektbezogen und zentral dokumentiert.

    {bullets.map((b) => (
  • {b}
  • ))}
Chat App entdecken →
) : null}
); }