/** * 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 { LazyMap } from "../LazyMap"; import { MessagePlayer } from "../MessagePlayer"; import { media, str, t } from "../load"; import { Button, cx, DateBadge, dayName, fmtDate, fmtTime, Img, Paragraphs, Picture, 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 }) => (
{children}
); 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 ( ); } 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 ? ( ) : }
); } return
{panel}
; } // ─── 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, p.section.data); 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
{words}
; } // ─── 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) => (

{m.name}

{m.summary &&

{m.summary}

} Find out more
))}
); } 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) => (
  • 3 ? "(min-width: 1024px) 25vw, (min-width: 640px) 50vw, 100vw" : "(min-width: 640px) 33vw, 100vw"} ratio="aspect-[4/3]" className="rounded-none" />

    {m.name}

    {m.summary &&

    {m.summary}

    } Find out more about {m.name}
  • ))}
); } // ─── 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 ( <> {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 (
{head} {more}
); } if (p.section.variant === "calendar") { return (
{head}
    {list.map((e) => (
  1. {fmtDate(e.startsAt, zone, { day: "numeric" })}

    {/* A weekday and month without a day is "Sun (month: November)" to Intl: two parts. */}

    {fmtDate(e.startsAt, zone, { weekday: "short" })} · {fmtDate(e.startsAt, zone, { month: "long" })}

    {e.title}

    {!e.allDay &&

    {fmtTime(e.startsAt, zone)}

    }
  2. ))}
{more}
); } return (
{head} {more}
); } // ─── 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 (

{d.heading ?? "Latest message"}

{m.title}

{meta}

{m.source === "spotify" ? "Listen" : "Watch"}
); } if (p.section.variant === "video") { return (
{head}
{words}
); } return (
{head}
{words}
); } // ─── 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, p.section.data); return (
{img && }
); } 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; })} ); }