import { defineConfig, mergeConfig } from "vite";
import { createBuildConfig } from "./vite.config.common.mts";

export default defineConfig(async () => {
  const baseConfig = await createBuildConfig('electron');
  
  return mergeConfig(baseConfig, {
    plugins: [{
      name: 'remove-sw-imports',
      transform(code: string, id: string) {
        if (
          id.includes('registerServiceWorker') ||
          id.includes('register-service-worker') ||
          id.includes('sw_scripts') ||
          id.includes('PushNotificationPermission') ||
          code.includes('navigator.serviceWorker')
        ) {
          return {
            code: code
              .replace(/import.*registerServiceWorker.*$/mg, '')
              .replace(/import.*register-service-worker.*$/mg, '')
              .replace(/navigator\.serviceWorker/g, 'undefined')
              .replace(/if\s*\([^)]*serviceWorker[^)]*\)\s*{[^}]*}/g, '')
          };
        }
      }
    }]
  });
}); 