import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import { defineConfig, globalIgnores } from 'eslint/config';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
  baseDirectory: __dirname,
  recommendedConfig: js.configs.recommended,
  allConfig: js.configs.all,
});

export default defineConfig([
  globalIgnores(['**/node_modules/', '**/*.js']),
  {
    extends: compat.extends(
      'eslint:recommended',
      'plugin:@typescript-eslint/recommended'
    ),

    plugins: {
      '@typescript-eslint': typescriptEslint,
    },

    languageOptions: {
      parser: tsParser,
    },

    rules: {
      '@typescript-eslint/no-non-null-assertion': 'off',
      'no-restricted-imports': [
        'error',
        {
          patterns: [
            {
              group: [
                '@/ui/*',
                '../ui/*',
                '../../ui/*',
                '../../../ui/*',
                '../../../../ui/*',
                './components/ui/*',
                '../components/ui/*',
                '../../components/ui/*',
                '../../../components/ui/*',
                '../../../../components/ui/*',
              ],
              message:
                'Use the canonical component library import style: @/components/ui/*.',
            },
          ],
        },
      ],
    },
    ignores: ['node_modules', 'dist', 'build', 'coverage', '**/*.js'],
  },
]);
