import { VitePWA } from "vite-plugin-pwa";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        react(),
        VitePWA({
            strategies: "injectManifest",
            srcDir: "src",
            filename: "sw.js",
            registerType: "autoUpdate",
            injectRegister: false,
            manifest: {
                name: "Salona",
                short_name: "Salona",
                theme_color: '#000000',
                // "background_color": "#96E6B3",
                dir: "rtl",
                lang: "fa",
                description: "Salona is a platform to provide innovative tools to hairdressers and beauty salons.",
                display_override: ["standalone", "fullscreen", "window-controls-overlay", "browser"],
                icons: [
                    {
                        src: "pwa-64x64.png",
                        sizes: "64x64",
                        type: "image/png",
                    },
                    {
                        src: "pwa-192x192.png",
                        sizes: "192x192",
                        type: "image/png",
                    },
                    {
                        src: "pwa-512x512.png",
                        sizes: "512x512",
                        type: "image/png",
                    },
                    {
                        src: "maskable-icon-512x512.png",
                        sizes: "512x512",
                        type: "image/png",
                        purpose: "maskable",
                    },
                ],
            },

            injectManifest: {
                globPatterns: ["**/*.{js,css,html,svg,png,ico}"],
                maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
            },

            devOptions: {
                enabled: false,
                navigateFallback: "index.html",
                suppressWarnings: true,
                type: "module",
            },
        }),
    ],
    resolve: {
        alias: {
            "@": path.resolve(__dirname, "./src"),
            "@package.json": path.resolve(__dirname, "./package.json"),
            "@appointment": path.resolve(__dirname, "./src/apps/appointment"),
            "@card": path.resolve(__dirname, "./src/apps/card"),
            "@new-ui": path.resolve(__dirname, "./src/apps/new-ui"),
        },
    },
    // مهم: server settings برای dev/tunnel
    server: {
        host: true, // bind به 0.0.0.0 (مهم برای تونل)
        port: 5173, // مطمئن شو با پورتی که تونل بهش متصل میشه یکیه
        
    },
    build: {
        rollupOptions: {
            external: ["workbox-window"],
        },
    },
});
