import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';

export default defineConfig({
	plugins: [
		sveltekit(),
		VitePWA({
			registerType: 'autoUpdate',
			manifest: {
				name: 'checkflo — HACCP-Protokolle',
				short_name: 'checkflo',
				description: 'Digitale HACCP-Dokumentation für die Gastronomie',
				theme_color: '#0B1023',
				background_color: '#ffffff',
				display: 'standalone',
				start_url: '/',
				icons: [
					{ src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png' },
					{ src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png', purpose: 'any maskable' }
				]
			},
			workbox: {
				globPatterns: ['**/*.{js,css,html,svg,png,ico}'],
				runtimeCaching: [
					{
						urlPattern: /^https:\/\/api\.checkflo\.de\/.*/i,
						handler: 'NetworkFirst',
						options: {
							cacheName: 'pocketbase-api',
							expiration: { maxEntries: 50, maxAgeSeconds: 60 * 60 * 24 }
						}
					}
				]
			}
		})
	]
});
