const globals = require("globals");

// Lints only the hand-authored widget/gateway/thankyoupage-status/admin JS
// sources — never the webpack/terser build OUTPUT (public/*/front.js,
// status.js, etc. are generated, not source) and never node_modules/vendor/
// build tooling.
module.exports = [
  {
    files: [
      "public/widget/src/js/**/*.js",
      "public/gateway/src/js/**/*.js",
      "public/thankyoupage/status/src/js/**/*.js",
      "public/admin/admin.js",
    ],
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "script",
      globals: {
        ...globals.browser,
        ...globals.jquery,
        // simplyin deliberately NOT listed here: it's declared locally
        // (`const simplyin = window.simplyin;`) in the one file that uses it —
        // adding it as a global would blunt no-undef's ability to catch a
        // future file/edit that forgets that declaration (Copilot, PR #267).
        // Assigned via `window.X = ...` earlier in the same file, then read as
        // a bare identifier later — valid browser-global semantics, but ESLint's
        // scope analysis doesn't treat a `window.X =` property assignment as a
        // declaration the way `var X` would.
        SimplyIn: "readonly",
        simplyin_apaczka_change_react_input: "readonly",
        // Injected by the third-party Apaczka WooCommerce shipping plugin's own
        // enqueued script — not something this plugin declares or controls.
        apaczka_points_map: "readonly",
        apaczka_block: "readonly",
        // Injected by the card-tokenization iframe SDK (external payment
        // provider script), guarded with `if (window.CCIframe)` before use.
        CCIframe: "readonly",
      },
    },
    rules: {
      "no-undef": "error",
      "no-unused-vars": "warn",
      "no-cond-assign": "error",
      "no-dupe-keys": "error",
      "no-duplicate-case": "error",
      "no-unreachable": "error",
      "no-fallthrough": "error",
      "no-const-assign": "error",
      "no-self-compare": "warn",
      eqeqeq: ["warn", "smart"],
    },
  },
];
