import type { NextConfig } from "next";

// STATIC_EXPORT=1 builds the storefront on its own as plain HTML/CSS/JS in `out/`,
// for hosts with no Node runtime. The Square API routes need a server, so they are
// excluded from that build (see scripts/build-static.mjs).
//
// A static export can only ever be a point-in-time snapshot of the catalogue:
// prices and stock freeze at build time. The live site needs the Node runtime.
const isStaticExport = process.env.STATIC_EXPORT === "1";

const nextConfig: NextConfig = {
  // Required for the `use cache` directive in src/lib/storefront/payload.ts,
  // which lets a Square sync invalidate the whole storefront by tag instead of
  // every visitor triggering a catalogue query.
  cacheComponents: true,
  ...(isStaticExport ? { output: "export" as const, trailingSlash: true } : {}),
};

export default nextConfig;
