import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { VitePWA } from 'vite-plugin-pwa';

export default defineConfig({
  plugins: [
    react(),
    VitePWA({
      registerType: 'autoUpdate',
      strategies: 'injectManifest',
      srcDir: 'src',
      filename: 'sw.js',
      injectRegister: 'auto',
      devOptions: {
        enabled: true,
        type: 'module',
        navigateFallback: 'index.html',
      },
      manifest: {
        name: 'FarmaClic',
        short_name: 'FarmaClic',
        description: 'Encuentra medicamentos en farmacias cercanas',
        theme_color: '#c0dde9',
        background_color: '#f8fafb',
        display: 'standalone',
        start_url: '/',
        lang: 'es',
        scope: '/',
        id: 'farmaclic_app',
        dir: 'auto',
        orientation: 'natural',
        categories: ['health', 'utilities'],
        icons: [
          { src: '/farmaclic_logo.png', sizes: '512x512', type: 'image/png', purpose: 'any maskable' },
        ],
      },
    }),
  ],
  test: {
    environment: 'jsdom',
    setupFiles: ['./src/test/setup.js'],
    globals: true,
  },
  server: {
    allowedHosts: ['localhost', 'farmacias.hacecalor.net'],
    port: 3000,
    proxy: {
      '/api': {
        target: 'http://localhost:3001',
        changeOrigin: true,
        credentials: true,
      },
    },
  },
});

