import { defineNuxtConfig } from "nuxt/config";
import { resolve } from "node:path";
import { getI18n } from "./i18n.config";

export default defineNuxtConfig({
  app: {
    head: {
      viewport: "width=device-width, initial-scale=1, maximum-scale=5",
      script: [
        {
          type: "text/javascript",
          src: process.env.STOVE_GNB,
        },
        {
          type: "text/javascript",
          src: process.env.STOVE_81PLUG,
        },
        {
          type: "text/javascript",
          src: process.env.STOVE_LAUNCHER_SCRIPT,
          async: true,
          defer: true,
        },
      ],
    },
  },
  modules: [
    "@vueuse/nuxt",
    "@nuxtjs/i18n",
    "@pinia/nuxt",
    "@nuxtjs/tailwindcss",
  ],
  imports: {
    dirs: [
      "layers/types",
      "layers/components",
      "layers/composables",
      "layers/layouts",
      "layers/middleware",
      "layers/plugins",
      "layers/registry",
      "layers/server",
      "layers/stores",
      "layers/utils",
    ],
    global: true,
  },
  components: {
    dirs: ["~/components", "layers/components"],
    global: true,
  },
  alias: {
    "@": resolve(__dirname, "."),
    "#layers": resolve(__dirname, "layers"),
  },
  extends: [resolve(__dirname, "layers")],

  // i18n 설정 - 런타임에 동적으로 설정됨
  i18n: getI18n(),

  experimental: {
    payloadExtraction: false,
  },
  typescript: {
    // [test] 타입 체크 비활성화
    typeCheck: false,
    strict: true,
  },
  nitro: {
    prerender: { routes: [] },
  },
  // [test] Nuxt가 pages 스캔하도록 명시
  pages: true,

  // 런타임 환경 변수 설정
  runtimeConfig: {
    public: {
      runType: process.env.RUN_TYPE,
      baseDomain: process.env.BASE_DOMAIN,

      baseApiUrl: process.env.BASE_API_URL,
      staticUrl: process.env.STATIC_URL,

      stoveApiUrl: process.env.STOVE_API_URL,
      stoveMaintenanceApiUrl: process.env.STOVE_M_API_URL,

      stoveGnb: process.env.STOVE_GNB,

      stoveLauncherScript: process.env.STOVE_LAUNCHER_SCRIPT,
      stoveClientDownloadUrl: process.env.STOVE_CLIENT_DOWNLOAD_URL,
      stoveLoginUrl: process.env.STOVE_LOGIN_URL,

      stove81Plug: process.env.STOVE_81PLUG,
    },
  },
  vite: {
    server: {
      // 개발 환경에서는 모든 호스트 허용
      allowedHosts: true,
    },
    base: "/",
  },
});
