import base from "./base.js";

/**
 * Shared Oxlint config for erp-kit application frontends.
 * Consumers: `import erpKit from "@tailor-platform/erp-kit/oxlint/frontend"`.
 */
export default {
  extends: [base],
  // `react` (native) is merged with base's plugins; react-x / react-dom are JS plugins.
  plugins: ["react"],
  jsPlugins: [
    "eslint-plugin-react-x",
    "eslint-plugin-react-dom",
    // Scoped to test files in the overrides below.
    "eslint-plugin-testing-library",
    "eslint-plugin-jest-dom",
    // Scoped to E2E spec files in the overrides below.
    "eslint-plugin-playwright",
  ],
  overrides: [
    {
      files: ["**/*.{ts,tsx}"],
      env: {
        es2020: true,
        browser: true,
      },
      rules: {
        "no-restricted-imports": [
          "error",
          {
            paths: [
              {
                name: "@tailor-platform/app-shell",
                importNames: ["useToast"],
                message: "Import useToast from '@/hooks/use-toast' instead.",
              },
            ],
          },
        ],
        // Native react plugin (exhaustive-deps already enabled by correctness)
        "react/rules-of-hooks": "error",
        // React Compiler (babel-plugin-react-compiler)
        "react-x/error-boundaries": "error",
        "react-x/purity": "warn",
        "react-x/set-state-in-effect": "warn",
        "react-x/set-state-in-render": "error",
        "react-x/unsupported-syntax": "error",
        "react-x/use-memo": "error",
        // General React
        "react-x/no-nested-component-definitions": "error",
        "react-x/no-nested-lazy-component-declarations": "error",
        "react-x/no-context-provider": "warn",
        "react-x/no-use-context": "warn",
        "react-x/no-unnecessary-use-prefix": "warn",
        "react-x/use-state": "warn",
        // React DOM
        "react-dom/no-dangerously-set-innerhtml": "warn",
        "react-dom/no-dangerously-set-innerhtml-with-children": "error",
        "react-dom/no-flush-sync": "error",
        "react-dom/no-script-url": "warn",
        "react-dom/no-unsafe-iframe-sandbox": "warn",
        "react-dom/no-void-elements-with-children": "error",
        // Deprecated APIs (React 19)
        "react-dom/no-hydrate": "error",
        "react-dom/no-render": "error",
        "react-dom/no-use-form-state": "error",
      },
    },
    {
      files: ["e2e/**/*.ts"],
      rules: {
        "react/rules-of-hooks": "off",
        "react-x/purity": "off",
      },
    },
    {
      // Component and unit tests.
      files: ["**/*.test.{ts,tsx}"],
      rules: {
        "testing-library/await-async-queries": "error",
        "testing-library/await-async-utils": "error",
        "testing-library/no-await-sync-queries": "error",
        "testing-library/no-debugging-utils": "warn",
        "testing-library/no-dom-import": ["error", "react"],
        "testing-library/prefer-find-by": "error",
        "testing-library/prefer-screen-queries": "error",
        "testing-library/no-wait-for-multiple-assertions": "error",
        "testing-library/render-result-naming-convention": "error",
        "jest-dom/prefer-checked": "error",
        "jest-dom/prefer-enabled-disabled": "error",
        "jest-dom/prefer-in-document": "error",
        "jest-dom/prefer-required": "error",
        "jest-dom/prefer-to-have-attribute": "error",
        "jest-dom/prefer-to-have-text-content": "error",
      },
    },
    {
      // Scoped to spec files so page objects and fixtures are untouched.
      // no-conditional-in-test is omitted: specs branch on optional UI.
      files: ["e2e/**/*.spec.ts"],
      rules: {
        "playwright/expect-expect": "warn",
        "playwright/no-element-handle": "error",
        "playwright/no-eval": "error",
        "playwright/no-focused-test": "error",
        "playwright/no-nested-step": "error",
        "playwright/no-networkidle": "error",
        "playwright/no-page-pause": "error",
        "playwright/no-skipped-test": "warn",
        "playwright/no-standalone-expect": "error",
        "playwright/no-useless-await": "error",
        "playwright/no-useless-not": "error",
        "playwright/no-wait-for-timeout": "warn",
        "playwright/prefer-web-first-assertions": "error",
        "playwright/valid-expect": "error",
      },
    },
  ],
};
