'use client'; import { useEffect, useState } from 'react'; import { getClient } from '@/core/lib/brainerce'; /** * Whether the merchant has published a PAGE with this slug (Content → Page). * * `false` only on a genuine 404. While loading, or if the lookup fails for any * other reason, it stays `null`, so callers keep rendering the link: a flaky * network must not strip the policy link off a consent checkbox. * * Why it exists: a brand-new store has no `privacy` page, and the required * privacy checkbox at register and checkout linked straight to a 404. * Callers show the policy name as plain text until the * merchant creates the page. */ export function usePageExists(slug: string): boolean | null { const [exists, setExists] = useState(null); useEffect(() => { let cancelled = false; getClient() .content.page.getBySlug(slug) .then((page) => { if (!cancelled) setExists(page !== null); }) .catch(() => { // Not a 404: unknown, keep the link. }); return () => { cancelled = true; }; }, [slug]); return exists; }