/**
 * ============================================
 * SERVER-ONLY init for shopware-api
 * ============================================
 * `next/headers` is RSC-only and can't be imported from any file that's
 * bundled for the client (and shopware-api.ts is — many client components
 * import it). So this file imports it and registers reader functions on the
 * shared module. Importing it from the root server layout runs the
 * registration once per server process.
 *
 * Do NOT import this file from a client component.
 */

import { cookies, headers } from 'next/headers';
import { _registerServerReaders } from './shopware-api';

_registerServerReaders(
  (name) => {
    try {
      return cookies().get(name)?.value ?? null;
    } catch {
      // Outside a request scope (e.g. build-time prerender)
      return null;
    }
  },
  (name) => {
    try {
      return headers().get(name) ?? null;
    } catch {
      return null;
    }
  }
);
