"use client"; import { FormEvent, useEffect, useRef, useState } from "react"; import { Hash, SendHorizontal, UserRound } from "lucide-react"; /* ────────────────────────────────────────────────────────────────────────── * WebChatDemo — interactive desktop chat workspace for the chat subpage. Four * project channels, each with a fixed conversation. Click a channel to open it * (its unread badge clears). When you send a message, the team's conversation * simply CONTINUES — the next scripted message replies to the thread, not to * your line — so it feels like a live chat you dropped into. Own messages use * the site's secondary colour (teal). The mobile app is a "coming soon" below. * ────────────────────────────────────────────────────────────────────────── */ const OWN_BG = "#0D6E6E"; const OWN_BORDER = "#0A5A5A"; const OTHER_BG = "#FFFFFF"; const OTHER_BORDER = "#E9E7E5"; const SENDER = "#C4931E"; type Author = "team" | "self" | "assistant"; type Message = { id: string; sender: string; text: string; time: string; author: Author }; type ScriptMsg = { sender: string; text: string; author: Author }; type Channel = { id: string; name: string; meta: string; unread: number; seed: Message[]; followups: ScriptMsg[] }; // Fixed per-channel conversations (identical on every refresh). `followups` // continue the thread after each user message — they never address the user. const CHANNELS: Channel[] = [ { id: "heizung", name: "Heizungsprojekt Schulz", meta: "4 Mitglieder · 2 online", unread: 0, seed: [ { id: "h1", sender: "Murat Kaya", text: "Foto vom Heizungskeller hochgeladen.", time: "09:12", author: "team" }, { id: "h2", sender: "Lea Brandt", text: "Aufmaß ist fertig, schicke gleich die Unterlagen.", time: "09:15", author: "team" }, { id: "h3", sender: "Du", text: "Super, dann können wir morgen mit der Installation anfangen. 👍", time: "09:17", author: "self" }, { id: "h4", sender: "Murat Kaya", text: "Material ist bestellt, Lieferung Donnerstag.", time: "09:20", author: "team" }, { id: "h5", sender: "Daniel Reiter", text: "Hinweis: Für morgen fehlt noch eine verbindliche Terminbestätigung vom Kunden.", time: "09:21", author: "assistant" }, ], followups: [ { sender: "Lea Brandt", text: "Der Kunde meldet sich sonst eigentlich immer recht zuverlässig zurück.", author: "team" }, { sender: "Murat Kaya", text: "Werkzeug und Material für morgen liegen jedenfalls schon bereit.", author: "team" }, { sender: "Tom Berger", text: "Wetter soll morgen auch passen – trocken und mild.", author: "team" }, { sender: "Sara Möller", text: "Dann steht dem Start ja nichts mehr im Weg. 👍", author: "team" }, { sender: "Murat Kaya", text: "Bin gespannt, wird ein schönes Projekt.", author: "team" }, ], }, { id: "bad", name: "Bad-Renovierung Fischer", meta: "3 Mitglieder · 1 online", unread: 3, seed: [ { id: "b1", sender: "Lea Brandt", text: "Fliesen sind heute früh angekommen, alles vollständig.", time: "08:40", author: "team" }, { id: "b2", sender: "Tom Berger", text: "Alte Wanne ist raus, der Estrich muss aber noch trocknen.", time: "08:52", author: "team" }, { id: "b3", sender: "Du", text: "Top. Ab wann kann der Fliesenleger ran?", time: "09:03", author: "self" }, { id: "b4", sender: "Tom Berger", text: "Ab Donnerstag, dann ist der Estrich durch.", time: "09:05", author: "team" }, { id: "b5", sender: "Daniel Reiter", text: "Erinnerung: Die Sonderanfertigung für die Dusche muss bis Mittwoch bestellt sein.", time: "09:08", author: "assistant" }, ], followups: [ { sender: "Tom Berger", text: "Der Kunde war heute kurz da und ist echt zufrieden mit dem Fortschritt.", author: "team" }, { sender: "Lea Brandt", text: "Die Armaturen sind übrigens auch schon im Lager angekommen.", author: "team" }, { sender: "Murat Kaya", text: "Fugenfarbe wird Anthrazit, da hat sich der Kunde festgelegt.", author: "team" }, { sender: "Sara Möller", text: "Dann liegen wir ja voll im Zeitplan – sauber.", author: "team" }, { sender: "Tom Berger", text: "👍 Läuft rund hier.", author: "team" }, ], }, { id: "team", name: "Team Allgemein", meta: "12 Mitglieder · 5 online", unread: 0, seed: [ { id: "t1", sender: "Sara Möller", text: "Morgen um 8 kurzes Teammeeting zur Wochenplanung.", time: "07:30", author: "team" }, { id: "t2", sender: "Jonas Weiß", text: "Bin ab 10 auf der Baustelle Weber, danach im Büro.", time: "07:45", author: "team" }, { id: "t3", sender: "Du", text: "Passt. Die Kaffeekasse ist übrigens wieder leer 😅", time: "07:50", author: "self" }, { id: "t4", sender: "Lea Brandt", text: "😄 Ich kümmere mich drum, bring gleich was mit.", time: "07:52", author: "team" }, ], followups: [ { sender: "Jonas Weiß", text: "Danke Lea! 🙌", author: "team" }, { sender: "Sara Möller", text: "Kurze Info fürs Team: Der neue Transporter ist ab Freitag da.", author: "team" }, { sender: "Murat Kaya", text: "Oh nice, wurde auch Zeit. 😄", author: "team" }, { sender: "Sara Möller", text: "Details und Schlüsselübergabe kommen noch per Mail.", author: "team" }, { sender: "Tom Berger", text: "Top, danke fürs Update! 👍", author: "team" }, ], }, { id: "wartung", name: "Wartung & Service", meta: "5 Mitglieder · 3 online", unread: 1, seed: [ { id: "w1", sender: "Murat Kaya", text: "Notdienst-Anruf: Heizung bei Familie Krause ausgefallen.", time: "11:02", author: "team" }, { id: "w2", sender: "Du", text: "Wer kann heute noch hin?", time: "11:04", author: "self" }, { id: "w3", sender: "Tom Berger", text: "Ich fahre direkt nach dem Mittag raus.", time: "11:06", author: "team" }, { id: "w4", sender: "Daniel Reiter", text: "Neuer Wartungsvertrag Bäckerei Nowak startet am 01.08. – Ersttermin einplanen.", time: "11:10", author: "assistant" }, ], followups: [ { sender: "Sara Möller", text: "Für die Bäckerei Nowak wäre Montagvormittag ein guter Ersttermin, oder?", author: "team" }, { sender: "Lea Brandt", text: "Klingt gut, der Kunde ist da erfahrungsgemäß flexibel.", author: "team" }, { sender: "Tom Berger", text: "Bei Familie Krause war's vorhin übrigens nur die Umwälzpumpe – läuft wieder.", author: "team" }, { sender: "Murat Kaya", text: "Ah, gut zu wissen. Die war ja schon länger auffällig.", author: "team" }, { sender: "Sara Möller", text: "Dann haben wir für heute ja alles im Griff. 👍", author: "team" }, ], }, ]; // Neutral team continuations once a channel's scripted follow-ups run out. const GENERIC: ScriptMsg[] = [ { sender: "Lea Brandt", text: "Alles klar, machen wir so.", author: "team" }, { sender: "Murat Kaya", text: "👍", author: "team" }, { sender: "Tom Berger", text: "Passt für mich.", author: "team" }, { sender: "Sara Möller", text: "Notiert, danke!", author: "team" }, { sender: "Daniel Reiter", text: "Ich halte alles im Projekt fest.", author: "assistant" }, ]; function nowTime(): string { return new Intl.DateTimeFormat("de-DE", { hour: "2-digit", minute: "2-digit" }).format(new Date()); } function newId(): string { if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID(); return `web-${Date.now()}-${Math.random().toString(16).slice(2)}`; } export default function WebChatDemo() { const [activeId, setActiveId] = useState(CHANNELS[0].id); const [threads, setThreads] = useState>(() => Object.fromEntries(CHANNELS.map((c) => [c.id, c.seed])) ); const [unread, setUnread] = useState>(() => Object.fromEntries(CHANNELS.map((c) => [c.id, c.unread])) ); const [draft, setDraft] = useState(""); const [replyingIn, setReplyingIn] = useState(null); const scrollRef = useRef(null); // how many follow-ups a channel has already revealed const followIdx = useRef>({}); const active = CHANNELS.find((c) => c.id === activeId) ?? CHANNELS[0]; const messages = threads[activeId] ?? []; const busy = replyingIn === activeId; useEffect(() => { const el = scrollRef.current; if (el) el.scrollTop = el.scrollHeight; }, [messages, activeId, replyingIn]); function selectChannel(id: string) { setActiveId(id); setUnread((u) => (u[id] ? { ...u, [id]: 0 } : u)); setDraft(""); } async function handleSubmit(event: FormEvent) { event.preventDefault(); const trimmed = draft.trim(); if (!trimmed || busy) return; const channelId = activeId; const channel = CHANNELS.find((c) => c.id === channelId) ?? CHANNELS[0]; const userMsg: Message = { id: newId(), sender: "Du", text: trimmed, time: nowTime(), author: "self" }; setThreads((t) => ({ ...t, [channelId]: [...(t[channelId] ?? []), userMsg] })); setDraft(""); setReplyingIn(channelId); // The conversation just continues — reveal the next scripted line (which // answers the previous thread, not the user's message). const i = followIdx.current[channelId] ?? 0; const next = channel.followups[i] ?? GENERIC[(i - channel.followups.length) % GENERIC.length]; followIdx.current[channelId] = i + 1; await new Promise((r) => setTimeout(r, 750)); setThreads((t) => ({ ...t, [channelId]: [...(t[channelId] ?? []), { id: newId(), sender: next.sender, text: next.text, time: nowTime(), author: next.author }], })); setReplyingIn((prev) => (prev === channelId ? null : prev)); } return (
{/* Desktop chat workspace */}
{/* Sidebar — clickable channels */} {/* Main thread */}
{/* Channel header */}
{active.name} {active.meta}
{/* Messages */}
{messages.map((m) => (
{m.author !== "self" && ( )}
{m.author !== "self" && (

{m.sender}

)} {m.text}

{m.time}

))} {busy && (
{[0, 1, 2].map((i) => ( ))}
)}
{/* Input */}
void handleSubmit(e)} className="flex items-center gap-2.5 shrink-0" style={{ padding: "12px 16px", borderTop: "1px solid var(--border-light)" }}> setDraft(e.target.value)} placeholder={`Nachricht an #${active.name} …`} className="flex-1 min-w-0 rounded-full text-[14px]" style={{ background: "var(--container-bg)", height: 42, padding: "0 18px", color: "#111827", outline: "none", border: "1px solid var(--border-light)" }} />
); }