import svelte from "eslint-plugin-svelte";
import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";

export default [
  js.configs.recommended,
  ...svelte.configs["flat/recommended"],

  // Global language options (applies to all files)
  {
    languageOptions: {
      globals: { ...globals.browser, ...globals.node },
    },
  },

  // .svelte.ts files (Svelte 5 rune stores/models) — parse as TypeScript
  {
    files: ["**/*.svelte.ts"],
    languageOptions: {
      parser: tseslint.parser,
      globals: {
        $state: "readonly",
        $derived: "readonly",
        $effect: "readonly",
        $props: "readonly",
        $bindable: "readonly",
        $inspect: "readonly",
      },
    },
  },

  // .svelte files with <script lang="ts"> — use TS parser inside Svelte
  {
    files: ["**/*.svelte"],
    languageOptions: {
      parserOptions: {
        parser: tseslint.parser,
      },
    },
  },

  // Global rules — ainative-осознанные настройки
  {
    rules: {
      // CoT-логирование — intentional, не блокировать
      "no-console": "off",

      // Неиспользуемые переменные — error с игнором _префикса
      "no-unused-vars": ["error", { argsIgnorePattern: "^_" }],

      // {#each key} — warn вместо error для быстрых итераций
      "svelte/require-each-key": "warn",

      // goto/href без resolve() — warn вместо error
      "svelte/no-navigation-without-resolve": "warn",
    },
  },

  // Игноры
  {
    ignores: [
      "node_modules/",
      "dist/",
      "build/",
      ".svelte-kit/",
      ".vite/",
      "coverage/",
      "playwright-report/",
      "test-results/",
      "e2e/",
      "scripts/",
    ],
  },
];
