Files

528 lines
19 KiB
TypeScript

"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 (
<div className="absolute inset-0 overflow-hidden rounded-[36px]" aria-hidden style={{ pointerEvents: "none" }}>
<div
className="absolute left-1/2 top-1/2 flex items-center justify-center gap-5"
style={{
width: "175%",
transform: "translate(-50%, -50%) rotate(-13deg)",
background: "var(--accent-yellow)",
borderTop: "2px solid #171106",
borderBottom: "2px solid #171106",
boxShadow: "0 16px 34px -10px rgba(0,0,0,0.45)",
padding: "9px 0",
}}
>
{Array.from({ length: 6 }).map((_, i) => (
<span
key={i}
className="inline-flex items-center gap-2 text-[12.5px] font-extrabold uppercase tracking-[0.16em] whitespace-nowrap"
style={{ color: "#171106" }}
>
<HardHat size={14} strokeWidth={2.6} /> Bald verfügbar
</span>
))}
</div>
</div>
);
}
// Construction-themed copy that fills the whitespace next to the phone.
function ComingSoonAside() {
return (
<div className="flex w-full max-w-[400px] flex-col gap-5">
<style>{`@keyframes chat-hazard{from{background-position:0 0}to{background-position:28px 0}}@media(prefers-reduced-motion:reduce){.chat-hazard-anim{animation:none!important}}`}</style>
{/* mini Absperrband accent */}
<span
className="chat-hazard-anim"
style={{ width: 84, height: 8, borderRadius: 4, background: HAZARD_STRIPES, backgroundSize: "28px 28px", animation: "chat-hazard 1.1s linear infinite" }}
/>
<h2 className="text-[30px] md:text-[38px] font-extrabold leading-[1.1]" style={{ color: "var(--text-primary)", letterSpacing: "-0.02em" }}>
Der Chat für unterwegs <span style={{ color: "var(--accent-yellow)" }}>wird gerade gebaut.</span>
</h2>
<p className="text-[16px] leading-relaxed" style={{ color: "var(--text-secondary)" }}>
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.
</p>
<div className="flex items-center gap-3 text-[13px] font-medium" style={{ color: "var(--text-tertiary)" }}>
<TrafficCone size={18} strokeWidth={2} style={{ color: "var(--accent-yellow-dark)" }} />
<span>In Arbeit · noch ohne Termin, aber unterwegs.</span>
</div>
</div>
);
}
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<string> {
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<HTMLDivElement>(null);
const [messages, setMessages] = useState(seedMessages);
const [draft, setDraft] = useState("");
const [isReplying, setIsReplying] = useState(false);
const [sendError, setSendError] = useState<string | null>(null);
const scrollRef = useRef<HTMLDivElement>(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<HTMLFormElement>) {
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 (
<section
className="section-full"
style={{ background: "var(--surface)", paddingBlock: 80 }}
>
<div
className={`flex flex-col items-center justify-center gap-12 lg:gap-20 mx-auto ${showSideContent || comingSoon ? "lg:flex-row" : ""}`}
style={{ maxWidth: showSideContent ? "var(--content-width)" : comingSoon ? 860 : 420 }}
>
{comingSoon ? <ComingSoonAside /> : null}
{showSideContent ? (
<div className="flex w-full max-w-[420px] flex-col gap-4 lg:hidden">
<span
className="self-start text-[12px] font-semibold tracking-widest chamfer-badge px-2 py-0.5"
style={{ background: "var(--accent-yellow-light)", color: "var(--accent-yellow-dark)" }}
>
KOMMUNIKATION
</span>
<h2
className="text-[32px] font-bold leading-[1.15]"
style={{ color: "var(--text-primary)" }}
>
Ihr Team bleibt vernetzt, <span style={{ color: "var(--accent-yellow)" }}>informiert</span> und abgestimmt.
</h2>
</div>
) : null}
{/* Phone mockup (wrapped so the coming-soon overlay can sit on top) */}
<div className="relative shrink-0">
<div
ref={phoneRef}
className="rounded-[40px] overflow-hidden flex flex-col"
style={{
width: 300,
height: 600,
background: "#FFFFFF",
border: "4px solid #D1D5DB",
boxShadow: "0 12px 40px -4px rgba(0,0,0,0.13), 0 4px 12px rgba(0,0,0,0.06)",
...(comingSoon ? { filter: "blur(3px) saturate(0.92)", pointerEvents: "none", userSelect: "none" } : null),
}}
aria-hidden={comingSoon || undefined}
>
{/* Status bar */}
<div
className="flex items-center justify-between px-6 shrink-0"
style={{ height: 44, background: "#FFFFFF", fontSize: 13, fontWeight: 600 }}
>
<span style={{ color: "var(--text-primary)" }}>9:41</span>
</div>
{/* Chat header */}
<div
className="flex items-center gap-3 shrink-0"
style={{
height: 56,
background: "#FFFFFF",
padding: "0 16px",
borderBottom: "1px solid #E5E7EB",
}}
>
<div
className="flex items-center justify-center rounded-full shrink-0 text-[14px] font-semibold text-white"
style={{ width: 36, height: 36, background: "#F3E4C2" }}
>
<Building2 size={16} color="#8A6116" strokeWidth={2.2} />
</div>
<div>
<p className="text-[14px] font-semibold" style={{ color: "var(--text-primary)" }}>
Heizungsprojekt Schulz
</p>
<p className="text-[11px]" style={{ color: "var(--text-secondary)" }}>
4 Mitglieder · 2 online
</p>
</div>
</div>
{/* Messages */}
<div
ref={scrollRef}
className="chat-scroll-hidden flex flex-col gap-2 flex-1 overflow-y-auto"
style={{
background: CHAT_BACKGROUND,
backgroundImage: CHAT_MONOGRAM_PATTERN,
backgroundRepeat: "repeat",
backgroundSize: "28px 28px",
padding: "12px 12px",
overscrollBehaviorY: "contain",
WebkitOverflowScrolling: "touch",
}}
>
{messages.map((msg) => (
<div
key={msg.id}
className={`flex items-end gap-2 ${msg.author === "self" ? "justify-end" : "justify-start"}`}
>
{msg.author !== "self" && (
<div
className="flex items-center justify-center rounded-full shrink-0"
style={{ width: 26, height: 26, background: "#E8DDCE" }}
>
<UserRound size={12} color="#7F6D58" strokeWidth={2.3} />
</div>
)}
<div
className="text-[12px] leading-snug max-w-[72%]"
style={{
backgroundColor: msg.author === "self" ? OWN_BUBBLE_BACKGROUND : OTHER_BUBBLE_BACKGROUND,
borderRadius: msg.author === "self" ? "16px 16px 4px 16px" : "16px 16px 16px 4px",
padding: "8px 12px",
color: msg.author === "self" ? "#FFFFFF" : "var(--text-primary)",
boxShadow: "0 1px 2px rgba(0,0,0,0.06)",
border: msg.author === "self" ? `1px solid ${OWN_BUBBLE_BORDER}` : `1px solid ${OTHER_BUBBLE_BORDER}`,
}}
>
{msg.author !== "self" ? (
<p className="mb-1 text-[11px] font-semibold" style={{ color: OTHER_BUBBLE_SENDER }}>
{msg.sender}
</p>
) : null}
{msg.text}
<p className="mt-1 text-[10px]" style={{ color: msg.author === "self" ? "rgba(255,255,255,0.82)" : OTHER_BUBBLE_TIME }}>
{msg.time}
</p>
</div>
</div>
))}
</div>
{sendError ? (
<div className="px-3 py-1 text-[11px]" style={{ color: "#B91C1C", background: "#FEF2F2" }}>
{sendError}
</div>
) : null}
{/* Input */}
<form
onSubmit={(event) => {
void handleSubmit(event);
}}
className="flex items-center gap-2 shrink-0"
style={{
height: 56,
background: "#FFFFFF",
padding: "0 12px",
borderTop: "1px solid #E5E7EB",
}}
>
<input
value={draft}
onChange={(event) => 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",
}}
/>
<button
type="submit"
disabled={!draft.trim() || isReplying}
className="flex items-center justify-center rounded-full shrink-0 transition-opacity"
style={{
width: 34,
height: 34,
background: !draft.trim() || isReplying ? "#DCCFB8" : "var(--accent-yellow)",
opacity: !draft.trim() || isReplying ? 0.8 : 1,
}}
>
<SendHorizontal size={14} color="#1A1A1A" />
</button>
</form>
{/* Home indicator */}
<div className="flex items-center justify-center" style={{ height: 20, background: "#FFFFFF" }}>
<div className="rounded-full" style={{ width: 120, height: 4, background: "#D1D5DB" }} />
</div>
</div>
{comingSoon ? <ComingSoonTape /> : null}
</div>
{showSideContent ? (
<>
<div className="hidden flex-col gap-6 lg:flex" style={{ maxWidth: 420 }}>
<span
className="self-start text-[12px] font-semibold tracking-widest chamfer-badge px-2 py-0.5"
style={{ background: "var(--accent-yellow-light)", color: "var(--accent-yellow-dark)" }}
>
KOMMUNIKATION
</span>
<h2
className="text-[32px] md:text-[42px] font-bold leading-[1.15]"
style={{ color: "var(--text-primary)" }}
>
Ihr Team bleibt vernetzt, <span style={{ color: "var(--accent-yellow)" }}>informiert</span> und abgestimmt.
</h2>
<p className="text-[16px] leading-relaxed" style={{ color: "var(--text-secondary)" }}>
So vertraut wie WhatsApp, aber fürs Handwerk gebaut: Alle Fotos, Aufgaben und
Absprachen sind projektbezogen und zentral dokumentiert.
</p>
<ul className="flex flex-col gap-3">
{bullets.map((b) => (
<li key={b} className="flex items-center gap-3">
<Check size={18} style={{ color: "var(--accent-yellow)", flexShrink: 0 }} strokeWidth={2.5} />
<span className="text-[14px] font-medium" style={{ color: "var(--text-primary)" }}>
{b}
</span>
</li>
))}
</ul>
<Link
href="/produkt/chat"
className="self-start text-[14px] font-semibold hover:underline"
style={{ color: "var(--accent-yellow-dark)" }}
>
Chat App entdecken →
</Link>
</div>
<div className="flex w-full max-w-[420px] flex-col gap-4 lg:hidden">
<p className="text-[16px] leading-relaxed" style={{ color: "var(--text-secondary)" }}>
So vertraut wie WhatsApp, aber fürs Handwerk gebaut: Alle Fotos, Aufgaben und
Absprachen sind projektbezogen und zentral dokumentiert.
</p>
<ul className="flex flex-col gap-3">
{bullets.map((b) => (
<li key={b} className="flex items-center gap-3">
<Check size={18} style={{ color: "var(--accent-yellow)", flexShrink: 0 }} strokeWidth={2.5} />
<span className="text-[14px] font-medium" style={{ color: "var(--text-primary)" }}>
{b}
</span>
</li>
))}
</ul>
<Link
href="/produkt/chat"
className="self-start text-[14px] font-semibold hover:underline"
style={{ color: "var(--accent-yellow-dark)" }}
>
Chat App entdecken →
</Link>
</div>
</>
) : null}
</div>
</section>
);
}