import js from "@eslint/js";
import ts from "typescript-eslint";
import svelte from "eslint-plugin-svelte";
import prettier from "eslint-config-prettier";
import globals from "globals";

export default ts.config(
  js.configs.recommended,
  ...ts.configs.recommended,
  ...svelte.configs["flat/recommended"],
  prettier,
  ...svelte.configs["flat/prettier"],
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
      },
    },
  },
  {
    files: ["**/*.svelte"],
    languageOptions: {
      parserOptions: {
        parser: ts.parser,
      },
    },
  },
  {
    rules: {
      // Allow unused vars prefixed with _ (common pattern for intentional ignores)
      "@typescript-eslint/no-unused-vars": [
        "error",
        { argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
      ],
      // Enforce consistent type imports
      "@typescript-eslint/consistent-type-imports": [
        "error",
        { prefer: "type-imports", fixStyle: "inline-type-imports" },
      ],
      // This rule is meant for onNavigate() callbacks only; standard SvelteKit href/goto is fine
      "svelte/no-navigation-without-resolve": "off",
      // {@html} is used intentionally for trusted content (e.g. legal page)
      "svelte/no-at-html-tags": "warn",
    },
  },
  {
    ignores: [
      "**/build/",
      "**/.svelte-kit/",
      "**/dist/",
      "**/node_modules/",
      "**/migrations/",
      "**/wasm/",
    ],
  },
);
