import type { NextConfig } from "next";

// 다층 캐시·SEO 차단(§4)의 응답 헤더 계층. immutable 정적 자산(_next/static, _next/image)은
// Next.js가 자체적으로 Cache-Control을 강제하므로 대상에서 제외해 자산 캐싱을 보존한다.
const SECURITY_HEADERS = [
  {
    key: "X-Robots-Tag",
    value: "noindex, nofollow, noarchive, nosnippet, noimageindex",
  },
  { key: "Cache-Control", value: "no-store, no-cache, must-revalidate" },
  { key: "Pragma", value: "no-cache" },
  { key: "X-Content-Type-Options", value: "nosniff" },
  { key: "X-Frame-Options", value: "DENY" },
  { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
  {
    key: "Permissions-Policy",
    value: "camera=(), microphone=(), geolocation=()",
  },
];

const nextConfig: NextConfig = {
  // 라우트 전환 애니메이션(React `<ViewTransition>`, app/layout.tsx) 활성화 — Next.js 공식
  // 가이드(view-transitions.md) 권장 방식. 미지원 브라우저에서는 애니메이션 없이 정상 동작한다.
  experimental: {
    viewTransition: true,
  },
  async headers() {
    return [
      {
        source: "/((?!_next/static|_next/image).*)",
        headers: SECURITY_HEADERS,
      },
    ];
  },
};

export default nextConfig;
