import js from '@eslint/js'
import globals from 'globals'
import pluginVue from 'eslint-plugin-vue'

export default [
  {
    ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**', '**/node_modules/**', '.nuxt/**']
  },
  // Load Vue recommended rules first (sets up parser etc.)
  ...pluginVue.configs['flat/recommended'],

  // General Configuration for all JS/Vue files
  {
    files: ['**/*.{js,mjs,jsx,vue}'],
    languageOptions: {
      globals: {
        ...globals.browser
      },
      ecmaVersion: 'latest',
      sourceType: 'module'
    },
    rules: {
      // Import standard JS recommended rules
      ...js.configs.recommended.rules,

      // --- Logic & Best Practices ---
      'no-unused-vars': ['warn', {
        argsIgnorePattern: '^_',
        varsIgnorePattern: '^_',
        caughtErrorsIgnorePattern: '^_'
      }],
      'no-undef': 'error',
      'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
      'no-debugger': 'warn',
      'eqeqeq': ['error', 'always', { null: 'ignore' }],
      'curly': ['error', 'all'],
      'prefer-const': 'warn',
      'no-var': 'error',

      // --- Formatting & Style (User requested warnings) ---
      'indent': ['error', 2, { SwitchCase: 1 }],
      'quotes': ['error', 'single', { avoidEscape: true }],
      'semi': ['error', 'never'],
      'comma-dangle': ['error', 'never'],
      'no-trailing-spaces': 'error',
      'no-multiple-empty-lines': ['error', { max: 1 }],
      'space-before-function-paren': ['error', 'always'],
      'object-curly-spacing': ['error', 'always'],
      'array-bracket-spacing': ['error', 'never']
    }
  },

  // Vue Specific Overrides
  {
    files: ['**/*.vue'],
    rules: {
      'vue/multi-word-component-names': 'off',
      'vue/no-v-html': 'warn',

      // Turn off standard indent for Vue files to avoid conflicts with vue/html-indent
      // or script indentation issues. Vue plugin handles this better.
      'indent': 'off',
      // Ensure Vue's own indentation rules are active (they are in 'recommended' but let's be explicit if needed)
      'vue/html-indent': ['error', 2],
      'vue/script-indent': ['error', 2, {
        baseIndent: 0,
        switchCase: 1,
        ignores: []
      }]
    }
  },

  // Service Worker specific globals
  {
    files: ['**/service-worker.js', '**/src/registerServiceWorker.js'],
    languageOptions: {
      globals: {
        ...globals.serviceworker
      }
    }
  }
]
