import type {QueryResponseInitial} from '@sanity/react-loader'; import type {SanityContext} from 'hydrogen-sanity'; import footerEmblemSrc from '~/assets/footer/footer-emblem.png'; import footerWordmarkSrc from '~/assets/footer/footer-wordmark.png'; import footerCertificationBadgesSrc from '~/assets/footer/footer-certification-badges.png'; export type AbiirFooterLink = { label: string; href: string; }; export type AbiirFooterColumn = { title: string; links: AbiirFooterLink[]; }; export type AbiirFooterCms = { tagline: string; brandLinkPath: string; emblemUrl: string; emblemAlt: string; emblemWidth: number; emblemHeight: number; wordmarkUrl: string; wordmarkAlt: string; wordmarkWidth: number; wordmarkHeight: number; certificationBadgesUrl: string; certificationBadgesAlt: string; certificationBadgesWidth?: number; certificationBadgesHeight?: number; socialInstagramUrl: string; socialYoutubeUrl: string; socialXUrl: string; columnGroups: AbiirFooterColumn[]; copyrightLine: string; legalLinks: AbiirFooterLink[]; }; const TRACK_MY_ORDER_LABEL = 'track my order'; const TRACK_MY_ORDER_HREF = 'https://www.ups.com/track?loc=en_US&requester=ST/'; type SanityImage = { alt?: string | null; asset?: { url?: string | null; metadata?: { dimensions?: {width?: number | null; height?: number | null} | null; } | null; } | null; } | null; type SanityFooterPayload = { tagline?: string | null; brandLinkPath?: string | null; emblem?: SanityImage; wordmark?: SanityImage; certificationBadges?: SanityImage; socialInstagramUrl?: string | null; socialYoutubeUrl?: string | null; socialXUrl?: string | null; columnGroups?: Array<{ title?: string | null; links?: Array<{label?: string | null; path?: string | null} | null> | null; } | null> | null; copyrightLine?: string | null; legalLinks?: Array<{label?: string | null; path?: string | null} | null> | null; } | null; function pathToHref(path: string): string { const p = path.trim(); if (!p) return '/'; if (/^https?:\/\//i.test(p)) return p; return p.startsWith('/') ? p : `/${p}`; } /** Omitted from footer (product decision). Also applied to Sanity payload. */ function isRemovedFooterLink(link: AbiirFooterLink): boolean { const label = link.label.trim().toLowerCase(); const h = link.href.trim().toLowerCase(); if (h === '/sustainability' || h.endsWith('/sustainability')) return true; if ( label === 'sustainability' || label === 'careers' || label === 'career' ) { return true; } return false; } function mapLinkRow( row: {label?: string | null; path?: string | null} | null | undefined, ): AbiirFooterLink | null { if (!row?.label || !row.path) return null; if (row.label.trim().toLowerCase() === TRACK_MY_ORDER_LABEL) { return {label: row.label, href: TRACK_MY_ORDER_HREF}; } return {label: row.label, href: pathToHref(row.path)}; } function imageFromSanity( img: SanityImage, fallbackW: number, fallbackH: number, ): {url: string; alt: string; w: number; h: number} | null { const url = img?.asset?.url?.trim(); if (!url) return null; const w = img?.asset?.metadata?.dimensions?.width ?? fallbackW; const h = img?.asset?.metadata?.dimensions?.height ?? fallbackH; return { url, alt: img?.alt ?? '', w, h, }; } /** Copied from `React/src/assets` (Figma exports) — same filenames as reference `figma:asset/*`. */ export const MOCK_ABIIR_FOOTER_CMS: AbiirFooterCms = { tagline: 'Skincare rooted in Ayurveda. Formulated with rare botanicals and modern science. Beauty without compromise.', brandLinkPath: '/', emblemUrl: footerEmblemSrc, emblemAlt: '', emblemWidth: 59, emblemHeight: 60, wordmarkUrl: footerWordmarkSrc, wordmarkAlt: '', wordmarkWidth: 77, wordmarkHeight: 25, certificationBadgesUrl: footerCertificationBadgesSrc, certificationBadgesAlt: 'Paraben Free · Recyclable · Cruelty Free · For All Skin Types', certificationBadgesWidth: 320, certificationBadgesHeight: 80, socialInstagramUrl: 'https://www.instagram.com/abiir_skincare/', socialYoutubeUrl: 'https://www.youtube.com/', socialXUrl: 'https://x.com/', columnGroups: [ { title: 'Shop', links: [ {label: 'All Products', href: '/collections/all'}, {label: 'Ritual Sets', href: '/collections/ritual'}, {label: 'Bestsellers', href: '/collections/bestsellers'}, {label: 'New Arrivals', href: '/collections/new-arrivals'}, {label: 'Spring Glow Bundle', href: '/products/glow-with-love-bundle'}, ], }, { title: 'Help', links: [ {label: 'FAQ', href: '/faq'}, {label: 'Shipping & Returns', href: '/shipping'}, {label: 'Contact Us', href: '/contact'}, {label: 'Track My Order', href: TRACK_MY_ORDER_HREF}, {label: 'Skincare Quiz', href: '/skincare-quiz'}, ], }, { title: 'Company', links: [ {label: 'Our Story', href: '/about'}, // {label: 'Journal', href: '/journal'}, {label: 'Press', href: '/press'}, ], }, ], copyrightLine: '© 2026 ABiiR Skincare. All rights reserved.', legalLinks: [ {label: 'Privacy Policy', href: '/privacy'}, {label: 'Terms of Service', href: '/terms'}, ], }; export function normalizeAbiirFooterSanityPayload( raw: unknown, ): AbiirFooterCms | null { if (raw == null || typeof raw !== 'object') return null; const b = raw as SanityFooterPayload; if (!b?.tagline || !b?.columnGroups?.length || !b?.copyrightLine) { return null; } const emblem = imageFromSanity(b.emblem ?? null, 59, 60); const wordmark = imageFromSanity(b.wordmark ?? null, 77, 25); const badges = imageFromSanity(b.certificationBadges ?? null, 320, 80); const m = MOCK_ABIIR_FOOTER_CMS; const emblemUrl = emblem?.url ?? m.emblemUrl; const wordmarkUrl = wordmark?.url ?? m.wordmarkUrl; const badgesUrl = badges?.url ?? m.certificationBadgesUrl; const columnGroups: AbiirFooterColumn[] = []; for (const col of b.columnGroups) { if (!col?.title) continue; const links: AbiirFooterLink[] = []; for (const row of col.links ?? []) { const l = mapLinkRow(row); if (l && !isRemovedFooterLink(l)) links.push(l); } if (links.length) columnGroups.push({title: col.title, links}); } if (!columnGroups.length) return null; const legalLinks: AbiirFooterLink[] = []; for (const row of b.legalLinks ?? []) { const l = mapLinkRow(row); if (l && !isRemovedFooterLink(l)) legalLinks.push(l); } if (!legalLinks.length) return null; return { tagline: b.tagline, brandLinkPath: (b.brandLinkPath ?? '/').trim() || '/', emblemUrl, emblemAlt: emblem?.alt ?? m.emblemAlt, emblemWidth: emblem?.w ?? m.emblemWidth, emblemHeight: emblem?.h ?? m.emblemHeight, wordmarkUrl, wordmarkAlt: wordmark?.alt ?? m.wordmarkAlt, wordmarkWidth: wordmark?.w ?? m.wordmarkWidth, wordmarkHeight: wordmark?.h ?? m.wordmarkHeight, certificationBadgesUrl: badgesUrl, certificationBadgesAlt: badges?.alt ?? m.certificationBadgesAlt, certificationBadgesWidth: badges?.w ?? m.certificationBadgesWidth, certificationBadgesHeight: badges?.h ?? m.certificationBadgesHeight, socialInstagramUrl: b.socialInstagramUrl?.trim() || m.socialInstagramUrl, socialYoutubeUrl: b.socialYoutubeUrl ?? '#', socialXUrl: b.socialXUrl ?? '#', columnGroups, copyrightLine: b.copyrightLine, legalLinks, }; } export async function loadFooterFromSanity(args: { sanity: SanityContext; groq: string; }): Promise<{footerCms: AbiirFooterCms}> { const initial: QueryResponseInitial = await args.sanity.loadQuery(args.groq).catch( (): QueryResponseInitial => ({ data: null, sourceMap: undefined, }), ); const normalized = normalizeAbiirFooterSanityPayload(initial.data); return { footerCms: normalized ?? MOCK_ABIIR_FOOTER_CMS, }; }