const devPort = Number(process.env.PORT || 5700)
const devHost = process.env.HOST || '0.0.0.0'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: '2025-06-10',
  devtools: { enabled: false }, // DevTools 비활성화로 성능 향상

  // SSR 활성화 - 새로고침/초기 렌더링 성능 개선
  ssr: true,

  // Dev server configuration
  devServer: {
    port: devPort,
    host: devHost // 모든 네트워크 인터페이스에서 수신
  },

  modules: [
    '@nuxtjs/tailwindcss',
    '@pinia/nuxt',
    '@element-plus/nuxt',
    '@vueuse/nuxt'
  ],

  css: [
    'element-plus/dist/index.css',
    '~/assets/styles/main.scss'
  ],

  app: {
    head: {
      title: 'FineCure - 법무업무도 토스하듯 간편하게',
      charset: 'utf-8',
      viewport: 'width=device-width, initial-scale=1',
      htmlAttrs: {
        lang: 'ko'
      },
      meta: [
        { name: 'description', content: '법무업무 자동화 플랫폼. 개인회생, 파산신청서 작성부터 사건관리까지 토스하듯 간편하게.' },
        { name: 'keywords', content: '법무업무, 개인회생, 파산신청, 법률문서, 법률 자동화, 법무ERP' },
        { name: 'author', content: 'FineCure' },
        { name: 'application-name', content: 'FineCure' },
        { name: 'apple-mobile-web-app-title', content: 'FineCure' },
        { name: 'theme-color', content: '#0f5f75' },
        { name: 'robots', content: 'index, follow' },
        { name: 'format-detection', content: 'telephone=no' },
        { name: 'twitter:card', content: 'summary' },
        { name: 'twitter:title', content: 'FineCure - 법무업무도 토스하듯 간편하게' },
        { name: 'twitter:description', content: '법무업무 자동화 플랫폼. 개인회생, 파산신청서 작성부터 사건관리까지 간편하게.' },
        { name: 'twitter:image', content: 'https://fincure.officialsite.kr/finecure-logo.png' },

        // Open Graph
        { property: 'og:type', content: 'website' },
        { property: 'og:site_name', content: 'FineCure' },
        { property: 'og:title', content: 'FineCure - 법무업무도 토스하듯 간편하게' },
        { property: 'og:description', content: '법무업무 자동화 플랫폼' },
        { property: 'og:locale', content: 'ko_KR' },
        { property: 'og:url', content: 'https://fincure.officialsite.kr' },
        { property: 'og:image', content: 'https://fincure.officialsite.kr/finecure-logo.png' },
        { property: 'og:image:alt', content: 'FineCure 로고' }
      ],
      link: [
        { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
        { rel: 'shortcut icon', href: '/favicon.ico' },
        { rel: 'icon', type: 'image/png', sizes: '32x32', href: '/favicon-32x32.png' },
        { rel: 'icon', type: 'image/png', sizes: '192x192', href: '/favicon-192x192.png' },
        { rel: 'icon', type: 'image/png', sizes: '512x512', href: '/favicon-512x512.png' },
        { rel: 'apple-touch-icon', sizes: '180x180', href: '/apple-touch-icon.png' },
        { rel: 'manifest', href: '/site.webmanifest' },
        { rel: 'canonical', href: 'https://fincure.officialsite.kr' },
        {
          rel: 'stylesheet',
          href: 'https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.8/dist/web/static/pretendard.css'
        },
        {
          rel: 'stylesheet',
          href: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css',
          integrity: 'sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==',
          crossorigin: 'anonymous',
          referrerpolicy: 'no-referrer'
        }
      ],
      script: [
        {
          src: '//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js',
          defer: true
        }
      ]
    },
    pageTransition: { name: 'page', mode: 'out-in' }
  },

  elementPlus: {
    themes: ['dark']
  },

  runtimeConfig: {
    public: {
      apiBase: process.env.API_BASE || 'https://api.fincure.officialsite.kr/api',
      tossClientKey: process.env.TOSS_CLIENT_KEY || ''
    }
  },

  // Vite 최적화
  vite: {
    server: {
      port: devPort,
      strictPort: true,
      host: devHost,
      hmr: {
        port: devPort,
        protocol: 'ws',
        host: process.env.NODE_ENV === 'production' ? 'fincure.officialsite.kr' : 'localhost',
        clientPort: devPort
      }
    },
    optimizeDeps: {
      include: ['vue', 'vue-router', 'pinia', 'element-plus']
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `
            :root {
              --header-height: 70px;
            }
          `
        }
      }
    }
  },

  // Tailwind 최적화
  tailwindcss: {
    viewer: false,
    exposeConfig: false
  },

  // 빌드 최적화
  build: {
    transpile: []
  }
})
