import type { NextConfig } from "next";

// Allow Shopify to embed the merchant admin in its iframe. Without a
// frame-ancestors CSP the browser blocks the app inside Shopify admin.
const SHOPIFY_FRAME_ANCESTORS =
  "frame-ancestors https://admin.shopify.com https://*.myshopify.com;";

const nextConfig: NextConfig = {
  // Pin the workspace root to this app (a sibling lockfile in the monorepo root
  // otherwise makes Turbopack scan the whole repo — huge compiles + RSC bugs).
  turbopack: {
    root: import.meta.dirname,
  },
  async headers() {
    return [
      // Only the embedded merchant admin needs to be framed by Shopify.
      {
        source: "/admin/:path*",
        headers: [{ key: "Content-Security-Policy", value: SHOPIFY_FRAME_ANCESTORS }],
      },
      {
        source: "/admin",
        headers: [{ key: "Content-Security-Policy", value: SHOPIFY_FRAME_ANCESTORS }],
      },
    ];
  },
};

export default nextConfig;
