const commonEslintConfig = ({
  ignorePatterns = [],
  extendsOverrides = [],
  overrideRules = {},
  tsconfigRootDir = "",
}) => {
  return {
    ignorePatterns,
    env: { browser: true, es2021: true, node: true },
    extends: [
      "eslint:recommended",
      "plugin:@typescript-eslint/recommended",
      "plugin:playwright/recommended",
      ...extendsOverrides,
    ],
    overrides: [
      {
        env: { node: true },
        files: [".eslintrc.{js,cjs}"],
        parserOptions: { sourceType: "script", requireConfigFile: false },
        rules: { "@typescript-eslint/no-var-requires": "off" },
      },
      {
        env: { node: true },
        files: ["*.ts", "*.spec.ts"],
        parser: "@typescript-eslint/parser",
        parserOptions: {
          ecmaVersion: "latest",
          sourceType: "module",
          tsconfigRootDir,
          project: ["./tsconfig.json"],
        },
        plugins: ["@typescript-eslint", "import"],
        rules: {
          "@bigbinary/neeto/use-dayjs-from-neeto-commons-fronted": "off",
          "@bigbinary/neeto/use-array-methods": "off",
          "@typescript-eslint/no-floating-promises": "error",
          "no-unused-vars": "off",
          "@typescript-eslint/no-unused-vars": ["error"],
          "@typescript-eslint/no-explicit-any": [
            "error",
            { ignoreRestArgs: true },
          ],

          "playwright/expect-expect": "off",
          "playwright/no-conditional-in-test": "warn",
          "playwright/no-nth-methods": "error",
          "playwright/no-page-pause": "error",
          "playwright/no-raw-locators": "warn",
          "playwright/no-useless-await": "error",
          "playwright/no-useless-not": "error",
          "playwright/no-wait-for-timeout": "error",
          "playwright/prefer-strict-equal": "warn",
          "playwright/prefer-to-be": "warn",
          "playwright/prefer-to-contain": "error",
          "playwright/prefer-to-have-count": "error",
          "playwright/prefer-to-have-length": "error",
          "playwright/prefer-web-first-assertions": "error",
          "playwright/require-top-level-describe": "error",
          "playwright/require-soft-assertions": "off",
          "playwright/valid-expect": "error",
          "playwright/prefer-lowercase-title": [
            "error",
            { ignoreTopLevelDescribe: true, allowedPrefixes: ["Step"] },
          ],
          "import/order": [
            "error",
            {
              "newlines-between": "always",
              alphabetize: { order: "asc", caseInsensitive: true },
              warnOnUnassignedImports: true,
              groups: [
                "builtin",
                "external",
                "internal",
                "index",
                "sibling",
                "parent",
                "object",
                "type",
              ],
            },
          ],
          ...overrideRules,
        },
      },
    ],
  };
};

module.exports = commonEslintConfig;
