import path from "path"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
import { inspectAttr } from 'kimi-plugin-inspect-react'
import { viteStaticCopy } from 'vite-plugin-static-copy'

/**
 * Plugin que adiciona X-Robots-Tag: noindex, nofollow no dev server
 * Garante que ambiente de desenvolvimento nunca seja indexado
 */
const devNoIndexPlugin = () => ({
  name: 'dev-noindex',
  configureServer(server: any) {
    server.middlewares.use((_req: any, res: any, next: any) => {
      res.setHeader('X-Robots-Tag', 'noindex, nofollow');
      next();
    });
  },
});

// https://vite.dev/config/
export default defineConfig({
  base: '/',
  plugins: [
    inspectAttr(), 
    react(),
    devNoIndexPlugin(),
    viteStaticCopy({
      targets: [
        {
          src: 'public/.htaccess',
          dest: '.'
        },
        {
          src: 'public/_redirects',
          dest: '.'
        },
        {
          src: 'public/vercel.json',
          dest: '.'
        },
        {
          src: 'HTACCESS-GUIA.md',
          dest: '.'
        },
        {
          src: 'nginx.conf',
          dest: '.'
        }
      ]
    })
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
});
