import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
  globalIgnores(['dist', 'pb_migrations', 'pb_hooks']),
  {
    files: ['**/*.{js,jsx}'],
    extends: [
      js.configs.recommended,
      reactHooks.configs.flat.recommended,
      reactRefresh.configs.vite,
    ],
    languageOptions: {
      globals: {
        ...globals.browser,
        __BUILD_SHA__: 'readonly',
        __BUILD_TIME__: 'readonly',
      },
      parserOptions: { ecmaFeatures: { jsx: true } },
    },
    rules: {
      // Conventional initial-load pattern across the admin/chat surface;
      // refactoring every effect is out of scope and not currently
      // observed to cause cascading renders in practice.
      'react-hooks/set-state-in-effect': 'off',
    },
  },
  {
    files: ['src/store/AppContext.jsx'],
    rules: {
      'react-refresh/only-export-components': 'off',
    },
  },
  {
    files: ['vite.config.js'],
    languageOptions: { globals: { ...globals.node } },
  },
  {
    files: ['src/lib/__tests__/**/*.{js,jsx}'],
    languageOptions: { globals: { ...globals.node } },
  },
])
