import Image from "next/image"; import createApolloServerClient from "@/graphql/server-client"; import { GET_PAGE_METADATA_BY_SLUG, type PageMetadataResponse, } from "@/graphql/queries/getHeroMetadata"; export const FeaturesStrip = async ({ slug, className, }: { slug?: string; className?: string; }) => { // Fetch page metadata for features-strip let meta: Record = {}; if (process.env.NEXT_PUBLIC_API_URL) { try { const client = createApolloServerClient(); const { data } = await client.query({ query: GET_PAGE_METADATA_BY_SLUG, variables: { slug: slug || "features-strip" }, fetchPolicy: "network-only", errorPolicy: "ignore", }); const items = data?.page?.metadata ?? []; meta = Object.fromEntries(items.map((m) => [m.key, m.value ?? ""])); } catch { // Silent fallback to defaults below } } const extractIconSrc = (raw?: string | null): string => { const fallback = "/star.svg"; if (!raw) return fallback; const val = raw.trim(); // Strip leading 'background-image:' if present const withoutProp = val.replace(/^background-image\s*:\s*/i, ""); const match = withoutProp.match(/url\(([^)]+)\)/i); if (match) { let url = match[1].trim(); if ( (url.startsWith('"') && url.endsWith('"')) || (url.startsWith("'") && url.endsWith("'")) ) { url = url.slice(1, -1); } return url || fallback; } // If it's already a direct url/path/data uri if ( val.startsWith("/") || val.startsWith("http") || val.startsWith("data:") ) return val; return fallback; }; const h1 = meta["feature_1_heading"] || "Original Products"; const t1 = meta["feature_1_text"] || "Creative designs that elevate daily items."; const i1 = extractIconSrc(meta["feature_1_icon"]) || "/star.svg"; const h2 = meta["feature_2_heading"] || "Affordable Rates"; const t2 = meta["feature_2_text"] || "Explore affordable prices for everyone here!"; const i2 = extractIconSrc(meta["feature_2_icon"]) || "/star.svg"; const h3 = meta["feature_3_heading"] || "Wide variety"; const t3 = meta["feature_3_text"] || "Explore a range of unique offerings."; const i3 = extractIconSrc(meta["feature_3_icon"]) || "/star.svg"; return (
{/* Texture overlays */} {/* Content */}
{/* Feature 1 */}
{`${h1}

{h1}

{t1}

{/* Feature 2 */}
{`${h2}

{h2}

{t2}

{/* Feature 3 */}
{`${h3}

{h3}

{t3}

); };