// The Lucia project.
// Copyright 2026-2026 DSP, inc.  All rights reserved.
// Authors:
//   imacat.yang@dsp.im (imacat), 2026/3/6
/**
 * @module eslint.config
 *   ESLint flat configuration for Vue, Cypress, and
 *   Prettier integration.
 */

import js from "@eslint/js";
import pluginVue from "eslint-plugin-vue";
import pluginCypress from "eslint-plugin-cypress";
import skipFormatting from "@vue/eslint-config-prettier";

/** Browser runtime globals used across app and jsdom tests. */
const browserGlobals = {
  window: "readonly",
  document: "readonly",
  navigator: "readonly",
  location: "readonly",
  localStorage: "readonly",
  sessionStorage: "readonly",
  console: "readonly",
  setTimeout: "readonly",
  clearTimeout: "readonly",
  setInterval: "readonly",
  clearInterval: "readonly",
  FormData: "readonly",
  Blob: "readonly",
  URL: "readonly",
  atob: "readonly",
  btoa: "readonly",
};

/** Node.js globals used in config files. */
const nodeGlobals = {
  process: "readonly",
  require: "readonly",
  module: "readonly",
  __dirname: "readonly",
};

/** Vitest globals used by unit tests. */
const vitestGlobals = {
  describe: "readonly",
  it: "readonly",
  test: "readonly",
  expect: "readonly",
  beforeEach: "readonly",
  afterEach: "readonly",
  beforeAll: "readonly",
  afterAll: "readonly",
  vi: "readonly",
};

export default [
  {
    ignores: [
      "node_modules/**",
      "dist/**",
      "coverage/**",
      "cypress/videos/**",
      "cypress/screenshots/**",
      "excludes/**",
      "**/*.ts",
      "**/*.d.ts",
    ],
  },
  {
    files: ["**/*.{js,mjs,cjs,vue}"],
    ...js.configs.recommended,
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module",
      globals: {
        ...browserGlobals,
      },
    },
    rules: {
      "vue/multi-word-component-names": "error",
    },
  },
  ...pluginVue.configs["flat/essential"],
  skipFormatting,
  {
    files: ["tests/**/*.{js,mjs,cjs}"],
    languageOptions: {
      globals: {
        ...browserGlobals,
        ...nodeGlobals,
        ...vitestGlobals,
      },
    },
  },
  {
    files: ["cypress/**/*.{js,mjs,cjs}"],
    ...pluginCypress.configs.recommended,
    languageOptions: {
      globals: {
        ...browserGlobals,
        ...nodeGlobals,
        cy: "readonly",
        Cypress: "readonly",
      },
    },
  },
  {
    files: ["*.{js,mjs,cjs}", "**/*.config.{js,mjs,cjs}"],
    languageOptions: {
      globals: {
        ...nodeGlobals,
      },
    },
  },
  {
    files: ["src/**/*.vue", "src/views/**/*.vue", "src/components/**/*.vue"],
    rules: {
      "vue/multi-word-component-names": "error",
      "vue/no-side-effects-in-computed-properties": "error",
      "vue/return-in-computed-property": "error",
      "vue/no-parsing-error": "error",
      "vue/valid-v-else": "error",
      "vue/no-deprecated-v-on-native-modifier": "error",
      "vue/require-valid-default-prop": "error",
      "vue/no-unused-vars": "error",
    },
  },
];
