import tseslint from "typescript-eslint";
import reactPlugin from "eslint-plugin-react";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import nextPlugin from "@next/eslint-plugin-next";

export default tseslint.config(
    ...tseslint.configs.recommended,

    {
      files: ["**/*.{js,jsx,ts,tsx}"],
      rules: {
        "@typescript-eslint/no-unused-vars": "warn",
        "@typescript-eslint/no-unused-expressions": "warn",
        "@typescript-eslint/no-explicit-any": "warn",
      },
    },

    // React and Next.js specific rules
    {
      files: ["**/*.{js,jsx,ts,tsx}"],
      plugins: {
        react: reactPlugin,
        "react-hooks": reactHooksPlugin,
        "@next/next": nextPlugin,
      },
      languageOptions: {
        ecmaVersion: "latest",
        sourceType: "module",
        parserOptions: {
          ecmaFeatures: {
            jsx: true,
          },
        },
      },
      settings: {
        react: {
          version: "detect",
        },
      },
      rules: {
        // React rules
        "react/react-in-jsx-scope": "off", // Not needed in Next.js
        "react/prop-types": "off", // TypeScript handles this
        "react/no-unescaped-entities": "off",

        // React Hooks rules
        "react-hooks/rules-of-hooks": "error",
        "react-hooks/exhaustive-deps": "warn",

        // Next.js rules
        "@next/next/no-html-link-for-pages": "error",
        "@next/next/no-img-element": "warn",
      },
    },

    // Ignore patterns
    {
      ignores: [
        "node_modules/**",
        ".next/**",
        "out/**",
        "build/**",
        "dist/**",
        "next-env.d.ts",
        "*.config.js",
        "*.config.mjs",
      ],
    }
);
