import tseslint from 'typescript-eslint';
import angular from 'angular-eslint';
import prettier from 'eslint-config-prettier';
import { defineConfig } from 'eslint/config';

export default defineConfig([
  {
    // ESLint resolves a config per linted file by walking up from that file, so this config — not
    // the workspace root one — owns everything under `packages/angular`. That means the root's
    // `.gitignore`-derived ignores do not apply here and generated output must be listed by hand.
    ignores: [
      'dist',
      'build',
      'coverage',
      'out-tsc',
      '.angular',
      'src/icons', // Generated by `pnpm build:icons`.
      'eslint.config.mjs',
    ],
  },
  {
    files: ['**/*.ts'],
    extends: [tseslint.configs.recommended, angular.configs.tsRecommended],
    languageOptions: {
      parserOptions: {
        // `tsconfig.json` here is solution-style (`files: []` plus `references`), so `project: true`
        // resolves to a project that contains no source file. The project service follows the
        // references the way `tsc` and the editor do.
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
    rules: {
      ...prettier.rules,
      '@angular-eslint/directive-selector': [
        'error',
        {
          type: 'attribute',
          prefix: 'lucide',
          style: 'camelCase',
        },
      ],
      '@angular-eslint/component-selector': [
        'error',
        {
          type: 'attribute',
          prefix: ['lucide'],
          style: 'camelCase',
        },
      ],
    },
  },
  {
    // Build scripts belong to no tsconfig, so they get the untyped ruleset.
    files: ['**/*.mts', '**/*.cts'],
    extends: [tseslint.configs.recommended],
    languageOptions: {
      parserOptions: {
        tsconfigRootDir: import.meta.dirname,
      },
    },
    rules: prettier.rules,
  },
  {
    files: ['**/*.html'],
    extends: [angular.configs.templateRecommended],
  },
]);
