import nuxt from '@nuxt/eslint-config';

const globals = {
  defineNuxtConfig: 'readonly',
  defineNuxtRouteMiddleware: 'readonly',
  navigateTo: 'readonly',
  useRuntimeConfig: 'readonly',
  $fetch: 'readonly',
};

const relaxedRules = {
  // Vue rules — relaxed for legacy code
  'vue/no-parsing-error': 'off',
  'vue/no-required-prop-with-default': 'off',
  'vue/no-mutating-props': 'off',
  'vue/html-self-closing': 'off',
  'vue/singleline-html-element-content-newline': 'off',
  'vue/multiline-html-element-content-newline': 'off',
  'vue/html-indent': 'off',
  'vue/attributes-order': 'off',
  'vue/multi-word-component-names': 'off',
  'vue/no-multiple-template-root': 'off',
  'vue/v-on-event-hyphenation': 'off',
  'vue/require-default-prop': 'off',

  // Console — allow console.error only
  'no-console': ['warn', { allow: ['error'] }],

  // Unused vars — warn, ignore underscore-prefixed
  'no-unused-vars': 'off',
  '@typescript-eslint/no-unused-vars': ['warn', {
    argsIgnorePattern: '^_',
    varsIgnorePattern: '^_',
    caughtErrorsIgnorePattern: '^_',
  }],

  // TypeScript — progressive strictness
  '@typescript-eslint/no-explicit-any': 'warn',
  '@typescript-eslint/no-dynamic-delete': 'off',
  '@typescript-eslint/no-invalid-void-type': 'off',
  '@typescript-eslint/unified-signatures': 'off',

  // Formatting — handled by Prettier/stylistic
  'require-await': 'off',
  'comma-dangle': 'off',
  curly: 'off',
  'operator-linebreak': 'off',
  'space-before-function-paren': 'off',
  'arrow-parens': 'off',
  semi: 'off',
  '@typescript-eslint/semi': 'off',
  quotes: 'off',
  'func-call-spacing': 'off',
  'no-trailing-spaces': 'off',
  indent: 'off',
  'no-multiple-empty-lines': 'off',
  'import/order': 'off',
  'no-irregular-whitespace': 'off',
  'no-useless-escape': 'off',
  'nuxt/prefer-import-meta': 'off',
};

export default await nuxt(
  {
    features: {
      stylistic: false,
      typescript: true,
      nuxt: {
        sortConfigKeys: false,
      },
    },
    dirs: {
      root: ['.', './app'],
    },
  },
  {
    name: 'project/custom-overrides',
    languageOptions: {
      globals,
    },
    rules: relaxedRules,
  }
);
