import Link from "next/link"; import { db } from "@/lib/db"; import { formatPrice } from "@/lib/money"; import { NOTICE, PUBLIC_ADVISOR, fmtDateTime, freeSlots, getConsultingSettings } from "@/lib/consulting"; import { Icon } from "@/components/Icon"; import { CardReadingGuide, CardReadingHero } from "@/components/shop/CardReadingGuide"; import { KlEffects } from "@/components/shop/CardReadingEffects"; import "@/styles/kartenlegen.css"; export async function generateMetadata() { const s = await getConsultingSettings(); return { title: s.navLabel, description: "Kartenlegen per Video- oder Audio-Call: Beraterin wählen, Wunschtermin anfragen, nach der Bestätigung bezahlen." }; } export default async function ConsultingPortal({ searchParams }: { searchParams: Promise<{ thema?: string; methode?: string; sprache?: string; frei?: string }> }) { const q = await searchParams; const settings = await getConsultingSettings(); const all = await db.advisor.findMany({ where: PUBLIC_ADVISOR, orderBy: { displayName: "asc" }, include: { offers: { where: { active: true, approved: true }, orderBy: { price: "asc" } }, rules: true, exceptions: true }, }); // Nächster freier Termin je Beraterin (kürzestes Angebot, nächste 14 Tage) const withNext = await Promise.all( all.map(async (a) => { const shortest = [...a.offers].sort((x, y) => x.duration - y.duration)[0]; const slots = shortest ? await freeSlots(a, shortest, { days: 14 }) : new Map(); const first = [...slots.values()][0]?.[0] as Date | undefined; return { a, next: first ?? null }; }), ); const facet = (k: "topics" | "methods" | "languages") => [...new Set(all.flatMap((a) => a[k]))].sort((x, y) => x.localeCompare(y, "de")); const weekEnd = Date.now() + 7 * 86400e3; const list = withNext.filter(({ a, next }) => (!q.thema || a.topics.includes(q.thema)) && (!q.methode || a.methods.includes(q.methode)) && (!q.sprache || a.languages.includes(q.sprache)) && (!q.frei || (next && next.getTime() < weekEnd)), ); const link = (patch: Record) => { const p = new URLSearchParams(Object.entries({ ...q, ...patch }).filter(([, v]) => v) as [string, string][]); return `/beratung${p.size ? `?${p}` : ""}`; }; const Chips = ({ k, label, values }: { k: "thema" | "methode" | "sprache"; label: string; values: string[] }) => values.length > 1 ? (
{label} {values.map((v) => {v})}
) : null; return ( // Der Bereich ist eine eigene Nachtwelt und bleibt auch im hellen Shop-Theme dunkel
Beraterinnen

Finde die Beraterin, die zu dir passt

Wähle deine Beraterin, frag einen Wunschtermin an und bezahle erst, wenn sie bestätigt hat.

{all.length > 0 && (
Diese Woche frei {(q.thema || q.methode || q.sprache || q.frei) && Filter zurücksetzen}
)} {list.length === 0 ? (

{all.length ? "Keine Beraterin passt zu diesen Filtern." : "Hier stellen sich bald unsere Beraterinnen vor."}

) : (
{list.map(({ a, next }) => { const from = a.offers[0]; return (
{a.photo ? ( // eslint-disable-next-line @next/next/no-img-element {`Porträt ) : ( )} {next && next.getTime() < weekEnd && Diese Woche frei}
{a.displayName} {a.tagline &&

{a.tagline}

} {(a.topics.length > 0 || a.methods.length > 0) && (
{[...a.topics, ...a.methods].slice(0, 4).map((t) => {t})}
)}
{from &&
Preis
ab {formatPrice(from.price)} / {from.duration} Min.
} {a.languages.length > 0 &&
Sprache
{a.languages.join(", ")}
}

{next ? <>Nächster Termin: {fmtDateTime(next)} : "Gerade keine freien Termine"}

Profil & Termine
); })}
)}

{NOTICE}

); }