import storybook from "eslint-plugin-storybook";
import betterTailwindcss from "eslint-plugin-better-tailwindcss";
import prettier from "eslint-config-prettier";
import path from "node:path";
import js from "@eslint/js";
import svelte from "eslint-plugin-svelte";
import { defineConfig, includeIgnoreFile } from "eslint/config";
import globals from "globals";
import ts from "typescript-eslint";

const gitignorePath = path.resolve(import.meta.dirname, ".gitignore");

export default defineConfig(
	{ ignores: ["src/lib/api/lexicons/"] },
	includeIgnoreFile(gitignorePath),
	js.configs.recommended,
	ts.configs.recommended,
	svelte.configs.recommended,
	storybook.configs["flat/recommended"],
	prettier,
	svelte.configs.prettier,
	{
		languageOptions: { globals: { ...globals.browser, ...globals.node } },
		rules: {
			// typescript owns undefined-name checks.
			"no-undef": "off"
		}
	},
	{
		files: ["**/*.svelte", "**/*.svelte.ts", "**/*.svelte.js"],
		languageOptions: {
			parserOptions: {
				projectService: { allowDefaultProject: [".storybook/StoryAuthProvider.svelte"] },
				extraFileExtensions: [".svelte"],
				parser: ts.parser
			}
		}
	},
	{
		files: ["**/*.svelte", "**/*.svelte.ts", "**/*.svelte.js", "**/*.ts", "**/*.js"],
		plugins: { "better-tailwindcss": betterTailwindcss },
		settings: {
			"better-tailwindcss": {
				entryPoint: "src/app.css",
				// without this the rule silently skips px -> spacing-scale rewrites.
				rootFontSize: 16
			}
		},
		rules: {
			"better-tailwindcss/enforce-canonical-classes": "warn",
			"better-tailwindcss/no-deprecated-classes": "warn"
		}
	},
	{
		rules: {}
	}
);
