import path from "node:path";
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { VitePWA } from "vite-plugin-pwa";
import { defineConfig } from "vitest/config";

// Multi-page entries: desktop + mobile
type InputMap = Record<string, string>;

function resolveHtmlPage(name: string): string {
	return path.resolve(__dirname, `${name}.html`);
}

export default defineConfig({
	plugins: [
		react(),
		tailwindcss(),
		VitePWA({
			registerType: "autoUpdate",
			includeAssets: ["icon.svg"],
			manifest: {
				name: "Zosma Cowork",
				short_name: "Zosma",
				description: "Desktop AI coworker — accessible from your phone",
				theme_color: "#1a1a2e",
				background_color: "#0f0f1a",
				display: "standalone",
				scope: "/",
				start_url: "/",
				icons: [
					{
						src: "icon.svg",
						sizes: "any",
						type: "image/svg+xml",
						purpose: "any maskable",
					},
				],
			},
		}),
	],
	build: {
		rollupOptions: {
			input: {
				main: resolveHtmlPage("index"),
				mobile: resolveHtmlPage("mobile"),
			} as InputMap,
		},
	},
	test: {
		environment: "jsdom",
		globals: true,
		setupFiles: ["./src/test/setup.ts"],
		include: ["src/**/*.{test,spec}.{ts,tsx}"],
		coverage: {
			provider: "v8",
			reporter: ["text", "html", "json-summary"],
			exclude: ["node_modules/", "src/test/", "src/**/*.d.ts", "src/main.tsx"],
		},
	},
	resolve: {
		alias: {
			"@": path.resolve(__dirname, "./src"),
		},
	},
	clearScreen: false,
	server: {
		port: 1420,
		strictPort: true,
		watch: {
			ignored: ["**/src-tauri/**", "**/target/**", "**/agent-sidecar/**", "**/node_modules/**"],
		},
	},
});
