// @ts-check
import { defineConfig } from 'astro/config';
import tailwindcss from '@tailwindcss/vite';
import { fileURLToPath } from 'node:url';

// Canonical origin used for absolute URLs (sitemap, OG, hreflang, JSON-LD).
// Overridable at build time so staging emits its own origin. See DOCKER_SPEC §3.
const SITE = process.env.PUBLIC_SITE_URL ?? 'https://cesnimda.co.uk';

const r = (p) => fileURLToPath(new URL(p, import.meta.url));

// https://astro.build/config
export default defineConfig({
  site: SITE,
  // ROUTING_SPEC §1: trailing-slash canonical, directory output.
  trailingSlash: 'always',
  build: { format: 'directory', inlineStylesheets: 'auto' },
  // I18N_SPEC §1: en at root, no prefixed. Localised slugs are handled by explicit
  // page files + the slug map module (ARCHITECTURE A5), not automatic locale routing.
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'no'],
    routing: { prefixDefaultLocale: false, redirectToDefaultLocale: false },
  },
  prefetch: false,
  compressHTML: true,
  vite: {
    plugins: [tailwindcss()],
    resolve: {
      alias: {
        '@': r('./src'),
        '@i18n': r('./src/i18n'),
        '@components': r('./src/components'),
        '@layouts': r('./src/layouts'),
        '@styles': r('./src/styles'),
        '@scripts': r('./src/scripts'),
        '@lib': r('./src/lib'),
      },
    },
  },
});
