import { FlaskConical, Smartphone } from "lucide-react" import Link from "next/link" type Offering = { id: number | string title: string description: string info_footer: string svg?: string | null // Fallback icon key (not used when svg exists) icon?: typeof FlaskConical } async function fetchOfferings(): Promise { try { // For server components, we can fetch directly from Strapi since there's no CORS issue // But for consistency, we'll use the API route const baseUrl = process.env.NEXT_PUBLIC_STRAPI_BASE_URL || "http://160.187.167.213" const apiUrl = `${baseUrl.replace(/\/+$/, "")}/api/offerings` const res = await fetch(apiUrl, { headers: { Accept: "application/json" }, next: { revalidate: 300 }, }) if (!res.ok) throw new Error(`Offerings API status ${res.status}`) const json = await res.json() const items = Array.isArray(json?.data) ? [...json.data].reverse() : [] return items.map((item: any, index: number) => { // Strapi v4: attributes, but sample payload has fields at root; handle both const attrs = item?.attributes ?? item ?? {} // Optional fallback icon rotation if SVG missing const fallbackIcons = [FlaskConical, Smartphone] return { id: item?.id ?? attrs?.id ?? index, title: attrs?.title ?? "", description: attrs?.description ?? "", info_footer: attrs?.info_footer ?? "", svg: attrs?.svg_icon ?? null, icon: fallbackIcons[index % fallbackIcons.length], } satisfies Offering }) } catch (error) { console.error("Failed to load offerings:", error) // Fallback to empty array if API fails return [] } } async function fetchOfferingHeading() { try { // For server components, we can fetch directly from Strapi since there's no CORS issue const baseUrl = process.env.NEXT_PUBLIC_STRAPI_BASE_URL || "http://160.187.167.213" const apiUrl = `${baseUrl.replace(/\/+$/, "")}/api/offering-text` const res = await fetch(apiUrl, { headers: { Accept: "application/json" }, next: { revalidate: 300 }, }) if (!res.ok) throw new Error(`Offering heading API status ${res.status}`) const json = await res.json() // Handle both Strapi shapes (with or without attributes wrapper) const attrs = json?.data?.attributes ?? json?.data ?? {} return attrs?.offering || "Our Offerings" } catch (error) { console.error("Failed to load offering heading:", error) return "Our Offerings" } } export default async function OurOfferings() { const heading = await fetchOfferingHeading() const offerings = await fetchOfferings() return (

{heading}

{offerings.map((offering) => (
{/* Icon */}
{offering.svg ? ( ) : ( offering.icon && ( ) )}
{/* Title */}

{offering.title}

{/* Description */}

{offering.description}

{/* Info footer / link text */} {offering.info_footer}
))}
) }