import { FlatCompat } from "@eslint/eslintrc"
import eslintPlugin from "@eslint/js"
import type { Linter } from "eslint"

const compat = new FlatCompat()

const eslintConfig = [
  {
    name: "custom/eslint/recommended",
    files: ["**/*.ts?(x)"],
    ...eslintPlugin.configs.recommended,
  },
]

const ignoresConfig = [
  {
    name: "custom/eslint/ignores",
    // the ignores option needs to be in a separate configuration object
    // replaces the .eslintignore file
    ignores: [
      ".next/",
      ".vscode/",
      "public/",
      "src/generated/",
      "node_modules/",
      "src/components/ui/",
    ],
  },
] as Linter.Config[]

export default [
  ...compat.extends(
    "next/core-web-vitals",
    "next/typescript",
    "plugin:import/recommended",
    "plugin:playwright/recommended",
    "plugin:prettier/recommended",
  ),
  ...compat.config({
    rules: {
      "no-unused-vars": "error",
      "simple-import-sort/exports": "error",
      "simple-import-sort/imports": "error",
      "@typescript-eslint/no-unused-vars": "off",
      "@typescript-eslint/no-explicit-any": "off",
      "@typescript-eslint/no-empty-object-type": "off",
      "@typescript-eslint/no-empty-interface": "off",
    },
    plugins: ["simple-import-sort"],
    globals: { React: true, Prisma: true },
    settings: {
      react: {
        version: "detect",
      },
    },
  }),
  ...eslintConfig,
  ...ignoresConfig,
] satisfies Linter.Config[]
