import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	preprocess: vitePreprocess(),
	kit: {
		adapter: adapter({
			pages: 'build',
			assets: 'build',
			fallback: undefined,
			precompress: false,
			strict: true
		}),
		prerender: {
			handleHttpError: 'fail',
			handleMissingId: 'fail'
		},
		// CSP : SvelteKit hache ses scripts inline (bootstrap d'hydratation) et injecte
		// une balise <meta>. Les directives d'en-tête (frame-ancestors, HSTS…) sont dans
		// static/_headers et static/.htaccess. Tout est auto-hébergé → 'self' partout.
		csp: {
			mode: 'hash',
			directives: {
				'default-src': ['self'],
				'script-src': ['self'],
				'style-src': ['self', 'unsafe-inline'],
				'img-src': ['self', 'data:'],
				'font-src': ['self'],
				'connect-src': ['self'],
				'base-uri': ['self'],
				'form-action': ['self'],
				'object-src': ['none'],
				'manifest-src': ['self']
			}
		},
		// URLs historiques avec slash final (o2switch/statique)
		paths: {
			relative: false
		}
	}
};

export default config;
