import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import tailwindcss from "@tailwindcss/vite";

// SSL-Konfiguration - für Entwicklung ohne echte Zertifikate
const httpsConfig =
    process.env.NODE_ENV === "production"
        ? {
              // In Produktion: echte Zertifikate verwenden
              key: process.env.SSL_KEY_PATH,
              cert: process.env.SSL_CERT_PATH,
          }
        : true; // Self-signed für Entwicklung

export default defineConfig({
    plugins: [
        laravel({
            input: [
                // Web Theme CSS Dateien
                "resources/css/web/theme-markemacht.css",
                "resources/css/web/theme-brand-rules.css",
                "resources/js/app.js",
            ],
            refresh: ["resources/views/web/**/*.blade.php"],
        }),
        tailwindcss({
            config: "./tailwind.web.config.js",
        }),
    ],
    server: {
        https: false, // Traefik übernimmt SSL, Vite läuft intern auf HTTP
        cors: {
            origin: [
                "https://markemacht.test",
                "https://brand-rules.test",
                "https://assets.brand-rules.test",
            ],
            credentials: true,
        },
        host: "0.0.0.0",
        port: 5178, // Web-spezifischer Port
        strictPort: true,
        allowedHosts: [
            "assets.markemacht.test",
            "markemacht.test",
            "assets.brand-rules.test",
            "brand-rules.test",
            "localhost",
            "0.0.0.0",
        ],
        hmr: {
            host: "assets.brand-rules.test",
            protocol: "wss",
        },
        origin: "https://assets.brand-rules.test", // Ohne Port!
    },
    build: {
        outDir: `public/build/web`,
        assetsDir: "",
        manifest: "manifest.json",
        rollupOptions: {
            output: {
                manualChunks: undefined,
            },
        },
    },
});
