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