import js from "@eslint/js";
import globals from "globals";
import reactPlugin from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import importPlugin from "eslint-plugin-import";
import unusedImports from "eslint-plugin-unused-imports";
import prettierPlugin from "eslint-plugin-prettier";
import tseslint from "typescript-eslint";

export const config = tseslint.config(
	{ ignores: ["dist"] },
	// Основная конфигурация для всех файлов
	{
		extends: [js.configs.recommended, ...tseslint.configs.recommended],
		files: ["**/*.{ts,tsx}"],
		languageOptions: {
			ecmaVersion: 2022,
			globals: {
				...globals.browser,
			},
			parserOptions: {
				ecmaFeatures: {
					jsx: true,
				},
			},
		},
		plugins: {
			react: reactPlugin,
			"react-hooks": reactHooks,
			"react-refresh": reactRefresh,
			import: importPlugin,
			"unused-imports": unusedImports,
			prettier: prettierPlugin,
		},
		settings: {
			react: {
				version: "detect",
			},
			"import/resolver": {
				typescript: {},
			},
		},
		rules: {
			...reactHooks.configs.recommended.rules,
			"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
			"unused-imports/no-unused-imports": "error",
			"import/order": [
				"error",
				{
					groups: ["builtin", "external", "internal", "parent", "sibling", "index"],
					"newlines-between": "always",
					alphabetize: { order: "asc", caseInsensitive: true },
				},
			],
			"@typescript-eslint/no-unused-vars": [
				"error",
				{
					vars: "all",
					args: "after-used",
					ignoreRestSiblings: true,
				},
			],
		},
	},
	// Отдельная конфигурация для .d.ts файлов
	{
		files: ["**/*.d.ts"],
		rules: {
			"unused-imports/no-unused-imports": "off",
			"@typescript-eslint/no-unused-vars": "off",
		},
	}
);

export default config;
