/**
* The homepage sections after the hero (WEBSITE-1.0-PLAN §3), each in its variants. Templates
* restyle the same markup through globals.css (cc-* classes) and the `t()` choices here.
*/
import { MessagePlayer } from "../MessagePlayer";
import { media, str, t } from "../load";
import { Button, cx, DateBadge, dayName, fmtDate, fmtTime, Img, Paragraphs, SectionHeading, type ButtonData } from "../parts";
import type { SectionProps, SiteEvent } from "../types";
import { Hero } from "./Hero";
const Section = ({ children, className, id }: { children: React.ReactNode; className?: string; id?: string }) => (
);
const tz = (p: SectionProps) => p.site.church?.timezone ?? "Africa/Johannesburg";
// ─── Service times and location: Panel · Inline strip · With map ─────────────────
function addressLines(p: SectionProps): string[] {
const a = p.site.church?.contact.address;
return a ? [a.line1, a.line2, [a.suburb, a.city].filter(Boolean).join(", ")].filter((x): x is string => !!x) : [];
}
function directions(p: SectionProps): string | null {
const a = p.site.church?.contact.address;
if (!a) return null;
return a.geo ? `https://www.openstreetmap.org/?mlat=${a.geo.lat}&mlon=${a.geo.lng}#map=17/${a.geo.lat}/${a.geo.lng}` : `https://www.openstreetmap.org/search?query=${encodeURIComponent([a.line1, a.suburb, a.city].filter(Boolean).join(", "))}`;
}
function Times({ p, className }: { p: SectionProps; className?: string }) {
const times = p.site.church?.serviceTimes ?? [];
if (!times.length) return
Service times are coming soon.
;
return (
{times.map((s, i) => (
{s.time}
{dayName(s.day)}{s.label && <> · {s.label}>}
{s.note && {s.note} }
))}
);
}
function ServiceTimes(p: SectionProps) {
const d = p.section.data as { heading: string | null; note: string | null };
const lines = addressLines(p);
const dir = directions(p);
const heading = d.heading ?? "Service times";
if (p.section.variant === "strip") {
const sundays = (p.site.church?.serviceTimes ?? []).filter((s) => s.day === "sunday").map((s) => s.time);
return (
{heading}: {sundays.length ? `Sundays ${sundays.join(" & ")}` : "see below"}{lines[0] && <> · {lines.join(", ")}>}
{dir &&
Get directions }
);
}
const panel = (
{heading}
{d.note &&
{d.note}
}
{lines.length > 0 && (
{lines.map((l) => {l} )}
{dir && Get directions }
)}
);
if (p.section.variant === "map") {
const geo = p.site.church?.contact.address?.geo;
return (
{panel}
{geo ? (
{/* OpenStreetMap, loaded only when scrolled to (no Google, no cookies). */}
) :
}
);
}
return ;
}
// ─── Welcome: Text · Image and text · With pastor's photo and quote ────────────────
function Welcome(p: SectionProps) {
const d = p.section.data as { heading: string | null; mission: string | null; body: string; imageId: string | null; pastor: { name: string; role: string | null; quote: string | null; photoId: string | null } | null };
const centred = p.template === "heritage";
const words = (
{d.mission &&
{d.mission}
}
{d.heading &&
{d.heading} }
);
if (p.section.variant === "pastor" && d.pastor) {
const photo = media(p.site, d.pastor.photoId);
return (
{d.pastor.quote && “{d.pastor.quote}” }
{d.pastor.name}{d.pastor.role && <>, {d.pastor.role}>}
{words}
);
}
if (p.section.variant === "image-text") {
return (
{words}
);
}
return ;
}
// ─── Ministries: Cards · List · Alternating bands ───────────────────────────────
function Ministries(p: SectionProps) {
const d = p.section.data as { heading: string | null; intro: string | null };
const list = p.site.snapshot.ministries;
if (!list.length) return null;
const page = p.site.snapshot.pages.find((x) => x.kind === "ministries");
const href = (slug: string) => (page ? `${page.path}#${slug}` : `#${slug}`);
const head = ;
if (p.section.variant === "bands") {
return (
{head}
{list.map((m, i) => (
))}
);
}
if (p.section.variant === "list") {
return (
{head}
{list.map((m) => (
{m.name}
{m.summary && {m.summary} }
))}
);
}
return (
{head}
3 ? "sm:grid-cols-2 lg:grid-cols-4" : "sm:grid-cols-3")}>
{list.map((m) => (
))}
);
}
// ─── Team: Faces grid · List · Featured ─────────────────────────────────────────
function Team(p: SectionProps) {
const d = p.section.data as { heading: string | null; intro: string | null };
const people = p.site.snapshot.leaders;
if (!people.length) return null;
const head = ;
const face = (l: (typeof people)[number], big = false) => (
{l.name}
{l.role && {l.role} }
);
if (p.section.variant === "list") {
return (
{head}
{people.map((l) => {l.name} {l.role} )}
);
}
if (p.section.variant === "featured") {
const [lead, ...rest] = people;
return (
{head}
{face(lead!, true)}
{rest.length > 0 &&
{rest.map((l) => face(l))}
}
);
}
return {head}
{people.map((l) => face(l))}
;
}
// ─── Upcoming events: Cards · List · Calendar strip ─────────────────────────────
export function EventLine({ e, timeZone }: { e: SiteEvent; timeZone: string }) {
const when = e.allDay ? fmtDate(e.startsAt, timeZone, { weekday: "long", day: "numeric", month: "long" }) : `${fmtDate(e.startsAt, timeZone, { weekday: "long", day: "numeric", month: "long" })}, ${fmtTime(e.startsAt, timeZone)}`;
return (
<>
{when}
{e.location && {e.location} }
{e.registration && e.registration.status === "open" && Register on our Events site }
>
);
}
function Events(p: SectionProps) {
const d = p.section.data as { heading: string | null; count: number };
const list = p.site.events.slice(0, d.count ?? 3);
const zone = tz(p);
const page = p.site.snapshot.pages.find((x) => x.kind === "events");
const head = ;
const more = page && All events
;
if (!list.length) {
return {head}
Nothing on the calendar just now. Check back soon.
;
}
if (p.section.variant === "cards") {
return (
);
}
if (p.section.variant === "calendar") {
return (
{head}
{list.map((e) => (
{fmtDate(e.startsAt, zone, { day: "numeric" })}
{fmtDate(e.startsAt, zone, { month: "long", weekday: "short" })}
{!e.allDay && {fmtTime(e.startsAt, zone)}
}
))}
{more}
);
}
return (
);
}
// ─── Latest message: Large video · Card · Compact ───────────────────────────────
function LatestMessage(p: SectionProps) {
const d = p.section.data as { heading: string | null };
const m = p.site.messages[0];
if (!m) return null;
const zone = tz(p);
const page = p.site.snapshot.pages.find((x) => x.kind === "messages");
const meta = [m.speaker, m.passage, fmtDate(m.date, zone, { day: "numeric", month: "long", year: "numeric" })].filter(Boolean).join(" · ");
const head = ;
const words = (
{m.series &&
{m.series}
}
{m.title}
{meta}
{page &&
All messages }
);
if (p.section.variant === "compact") {
return (
);
}
if (p.section.variant === "video") {
return (
);
}
return (
);
}
// ─── Invitation: Banner · Centred · Image background ────────────────────────────
function Invitation(p: SectionProps) {
const d = p.section.data as { heading: string; text: string | null; button: ButtonData; imageId: string | null };
if (p.section.variant === "image") {
const img = media(p.site, d.imageId);
return (
{img && }
{d.heading}
{d.text &&
{d.text}
}
);
}
if (p.section.variant === "banner") {
return (
{d.heading} {d.text &&
{d.text}
}
);
}
return (
{d.heading}
{d.text &&
{d.text}
}
);
}
// ─── Blocks on the other pages ──────────────────────────────────────────────────
function TextBlock(p: SectionProps) {
const d = p.section.data as { heading: string | null; body: string };
return {d.heading &&
{d.heading} }
;
}
function ImageTextBlock(p: SectionProps) {
const d = p.section.data as { heading: string | null; body: string; imageId: string | null; button: ButtonData };
return (
{d.heading &&
{d.heading} }
);
}
function QuoteBlock(p: SectionProps) {
const d = p.section.data as { quote: string; by: string | null };
return (
“{d.quote}”
{str(d.by) && {d.by} }
);
}
function CtaBlock(p: SectionProps) {
return ;
}
const SECTIONS: Record React.ReactNode> = {
hero: Hero, serviceTimes: ServiceTimes, welcome: Welcome, ministries: Ministries, team: Team, events: Events, latestMessage: LatestMessage, invitation: Invitation,
text: TextBlock, "image-text": ImageTextBlock, quote: QuoteBlock, cta: CtaBlock,
};
export function Sections({ site, sections }: { site: SectionProps["site"]; sections: SectionProps["section"][] }) {
const template = site.snapshot.design.template;
return (
<>
{sections.map((section, i) => {
const S = SECTIONS[section.type];
return S ? : null;
})}
>
);
}