// @ts-check

import eslint from '@eslint/js';
import { configs as tsEslintConfigs } from '@typescript-eslint/eslint-plugin';
import reactPlugin from 'eslint-plugin-react';
import reactPluginHooks from 'eslint-plugin-react-hooks';
import nextPlugin from '@next/eslint-plugin-next';
import globals from 'globals';

export default [
  // Base ESLint configuration
  eslint.configs.recommended,

  // TypeScript ESLint configurations
  tsEslintConfigs.recommended,
  tsEslintConfigs['recommended-type-checked'],

  {
    languageOptions: {
      parserOptions: {
        ecmaVersion: 'latest',
        project: ['./tsconfig.json', './tsconfig.node.json', './tsconfig.app.json'],
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },

  // React configuration
  {
    files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
    ...reactPlugin.configs.recommended,
    ...reactPlugin.configs['jsx-runtime'], // For React 17+ with JSX runtime
    languageOptions: {
      globals: {
        ...globals.serviceworker,
        ...globals.browser,
      },
    },
    rules: {
      'jsx-quotes': ['error', 'prefer-double'],
      'react/jsx-curly-brace-presence': [
        'error',
        {
          props: 'never',
          children: 'never',
        },
      ],
      '@typescript-eslint/no-misused-promises': 'off',
      '@typescript-eslint/no-unused-vars': [
        'error',
        {
          args: 'all',
          argsIgnorePattern: '^_',
          caughtErrors: 'all',
          caughtErrorsIgnorePattern: '^_',
          destructuredArrayIgnorePattern: '^_',
          varsIgnorePattern: '^_',
          ignoreRestSiblings: true,
        },
      ],
    },
  },

  // React Hooks configuration
  {
    plugins: {
      'react-hooks': reactPluginHooks,
    },
    rules: {
      ...reactPluginHooks.configs.recommended.rules,
    },
  },

  // Next.js configuration
  {
    plugins: {
      '@next/next': nextPlugin,
    },
    rules: {
      ...nextPlugin.configs.recommended.rules,
      ...nextPlugin.configs['core-web-vitals'].rules,
    },
  },

  // Ignore specific files and folders
  {
    ignores: ['tailwind.config.js', 'postcss.config.js', 'eslint.config.mjs', '.next/*'],
  },
];
