import { globalIgnores } from 'eslint/config';
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript';
import pluginVue from 'eslint-plugin-vue';
// import pluginVitest from '@vitest/eslint-plugin';
import js from '@eslint/js';
import globals from 'globals';
import stylistic from '@stylistic/eslint-plugin';
import jsdoc from 'eslint-plugin-jsdoc';

export default defineConfigWithVueTs(
    {
        name: 'app/files-to-lint',
        files: ['**/*.{vue,ts,js,mts,tsx}'],
    },

    js.configs.recommended,
    jsdoc.configs['flat/recommended-mixed'],

    // Add @stylistic configuration
    stylistic.configs.customize({
        indent: 4,
        quotes: 'single',
        semi: true,
        // Add any other stylistic preferences here
    }),

    ...pluginVue.configs['flat/essential'],
    vueTsConfigs.recommended,
    {
        name: 'app/global-rules',
        files: ['**/*.{js,ts,vue}'],
        rules: {
            'eqeqeq': ['error', 'smart'],
            'no-nested-ternary': 'error',
            'no-param-reassign': 'error',
            'jsdoc/require-jsdoc': 'off',
            '@stylistic/comma-dangle': 'off',
            '@stylistic/max-len': ['error', {
                code: 160,
                tabWidth: 4,
                ignoreUrls: true,
                ignoreStrings: true,
                ignoreTemplateLiterals: true
            }],

            'vue/max-len': ['error', {
                code: 160,
                template: 160,
                tabWidth: 4,
                ignoreUrls: true,
                ignoreStrings: true,
                ignoreTemplateLiterals: true,
                ignoreHTMLTextContents: false
            }],
        }
    },

    {
        name: 'app/custom-vue-rules',
        files: ['**/*.vue'],
        rules: {
            'vue/block-lang': ['error', {
                script: {
                    lang: ['js', 'ts'],
                    allowNoLang: true // Still allow <script> without a lang tag
                },
                style: {
                    lang: 'scss',
                    allowNoLang: false // Disallow <style> without lang="scss"
                }
            }]
        }
    },

    {
        name: 'app/custom-js-rules',
        files: ['**/*.{js,ts}'],
        languageOptions: {
            globals: {
                ...globals.browser,
                ...globals.node,
                ...globals.vitest,
                ...globals.vue,
                ...globals.jest
            }
        }
    },

    // Additional test globals (object) — applies only to test files
    // {
    //     files: ['**/*.spec.*', '**/*.test.*', '**/unit-test-helper.js'],
    //     ...pluginVitest.configs.recommended,
    // },

    {
        name: 'app/temp-rules',
        rules: {
            // Temp rules until we make a pass at fixing all of them.
            '@stylistic/arrow-parens': 'off',
            '@stylistic/brace-style': 'off',
            '@stylistic/eol-last': 'off',
            '@stylistic/indent': 'off',
            '@stylistic/indent-binary-ops': 'off',
            '@stylistic/max-len': 'off',
            '@stylistic/max-statements-per-line': 'off',
            '@stylistic/multiline-ternary': 'off',
            '@stylistic/no-trailing-spaces': 'off',
            '@stylistic/object-curly-spacing': 'off',
            '@stylistic/operator-linebreak': 'off',
            '@stylistic/quote-props': 'off',
            '@stylistic/quotes': 'off',
            '@stylistic/semi': 'off',
            '@typescript-eslint/no-unused-expressions': 'off',
            '@typescript-eslint/no-unused-vars': 'off',
            'jsdoc/reject-any-type': 'off',
            'jsdoc/require-param-description': 'off',
            'jsdoc/require-param-type': 'off',
            'jsdoc/require-returns-description': 'off',
            'jsdoc/require-returns': 'off',
            'jsdoc/require-returns-type': 'off',
            'jsdoc/ts-no-empty-object-type': 'off',
            'no-case-declarations': 'off',
            'no-constant-binary-expression': 'off',
            'no-dupe-keys': 'off',
            'no-import-assign': 'off',
            'no-shadow': 'off',
            'vitest/no-conditional-expect': 'off',
            'vitest/no-identical-title': 'off',
            'vitest/valid-expect': 'off',
            'vitest/valid-expect-in-promise': 'off',
            'vitest/valid-title': 'off',
            'vue/max-len': 'off',
            'vue/multi-word-component-names': 'off',
            'vue/no-reserved-component-names': 'off',
            'vue/no-side-effects-in-computed-properties': 'off',
            '@typescript-eslint/no-require-imports': 'off',
            'vitest/no-commented-out-tests': 'off',
            'vitest/no-focused-tests': 'off',
            'no-undef': 'off',
            'vue/require-toggle-inside-transition': 'off',
            'vue/no-dupe-keys': 'off',
            '@typescript-eslint/no-this-alias': 'off',
            'vitest/expect-expect': 'off',
            'no-param-reassign': 'off',
        }
    },

    globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**', 'playwright-tests', '**/*.snap']),
);
