import localRulesPlugin from "eslint-plugin-local-rules";
import reactHooks from "eslint-plugin-react-hooks";
import importPlugin from "eslint-plugin-import";
import jsoncParser from "jsonc-eslint-parser";
import jsxA11y from "eslint-plugin-jsx-a11y";
import tseslint from "typescript-eslint";
import react from "eslint-plugin-react";
import jsonc from "eslint-plugin-jsonc";
import globals from "globals";
import js from "@eslint/js";

export default tseslint.config(
    {
        ignores: [
            "node_modules",
            "version.mjs",
            ".history",
            "dist",
            "lib"
        ]
    },
    js.configs.recommended,
    ...tseslint.configs.recommended,
    {
        rules: {
            "local-rules/multiline-import-specifiers": "error",
            "local-rules/multiline-object-properties": "error",
            "local-rules/multiline-jsx-attributes": "error",
            "local-rules/multiline-array-elements": "error",
            "@typescript-eslint/no-empty-object-type": [
                "error",
                {
                    "allowInterfaces": "with-single-extends"
                }
            ],
            "object-property-newline": [
                "error",
                {
                    "allowAllPropertiesOnSameLine": false
                }
            ],
            "local-rules/custom-import-order": "error",
            "@typescript-eslint/no-namespace": "off",
            "react/react-in-jsx-scope": "off",
            "object-curly-newline": [
                "error",
                {
                    "ObjectExpression": {
                        "minProperties": 1,
                        "consistent": true,
                        "multiline": true
                    },
                    "ObjectPattern": {
                        "minProperties": 1,
                        "consistent": true,
                        "multiline": true
                    },
                    "ImportDeclaration": {
                        "minProperties": 1,
                        "consistent": true,
                        "multiline": true
                    },
                    "ExportDeclaration": {
                        "minProperties": 1,
                        "consistent": true,
                        "multiline": true
                    }
                }
            ],
            "no-trailing-spaces": [
                "error",
                {
                    "skipBlankLines": false
                }
            ],
            "quotes": [
                "error",
                "double",
                {
                    "avoidEscape": true
                }
            ],
            "react/jsx-indent-props": [
                "error",
                4
            ],
            "array-element-newline": [
                "error",
                {
                    "multiline": true,
                    "minItems": 1
                }
            ],
            "array-bracket-newline": [
                "error",
                "consistent"
            ],
            "object-curly-spacing": [
                "error",
                "always"
            ],
            "prefer-const": "error",
            "comma-spacing": [
                "error",
                {
                    "before": false,
                    "after": true
                }
            ],
            "indent": [
                "error",
                4,
                {
                    "SwitchCase": 1
                }
            ],
            "react/jsx-indent": [
                "error",
                4
            ],
            "no-var": "error",
            "eol-last": [
                "error",
                "always"
            ],
            "semi": [
                "error",
                "always"
            ]
        },
        settings: {
            "import/resolver": {
                typescript: {
                    project: "./tsconfig.json",
                    alwaysTryTypes: true
                }
            },
            react: {
                version: "detect"
            }
        },
        plugins: {
            "local-rules": {
                rules: localRulesPlugin.rules
            },
            "react-hooks": reactHooks,
            import: importPlugin,
            "jsx-a11y": jsxA11y,
            react
        },
        languageOptions: {
            globals: {
                "clearInterval": "readonly",
                "clearTimeout": "readonly",
                "setInterval": "readonly",
                "setTimeout": "readonly",
                "FormData": "readonly",
                "__DEV__": "readonly",
                "console": "readonly",
                "fetch": "readonly"
            },
            parser: tseslint.parser,
            ecmaVersion: "latest",
            sourceType: "module",
            parserOptions: {
                ecmaFeatures: {
                    jsx: true
                }
            }
        },
        files: [
            "**/*.{ts,tsx,js,jsx}"
        ]
    },
    {
        files: [
            "eslint-local-rules/**/*.js",
            "babel.config.js",
            "**/*.config.mjs",
            "**/*.config.js"
        ],
        languageOptions: {
            globals: {
                ...globals.node
            }
        }
    },
    {
        rules: {
            "jsonc/object-property-newline": [
                "error",
                {
                    "allowAllPropertiesOnSameLine": false
                }
            ],
            "jsonc/object-curly-newline": [
                "error",
                {
                    "minProperties": 0,
                    "consistent": true,
                    "multiline": true
                }
            ],
            "jsonc/array-element-newline": [
                "error",
                {
                    "multiline": true,
                    "minItems": 1
                }
            ],
            "jsonc/array-bracket-newline": [
                "error",
                "always"
            ],
            "jsonc/indent": [
                "error",
                4
            ]
        },
        languageOptions: {
            parser: jsoncParser
        },
        files: [
            "**/*.json"
        ],
        plugins: {
            jsonc
        }
    }
);
