import { defineConfig } from "eslint/config";

import buildPathGroupsBasedOnWebpackAliases from "../../../eslint/helpers/index.mjs";

const pathGroups =
  buildPathGroupsBasedOnWebpackAliases.buildPathGroupsBasedOnWebpackAliases({
    customAliasPath: "resolve.js",
    commonAliasPath:
      "node_modules/@bigbinary/neeto-commons-frontend/configs/nanos/webpack/resolve.js",
  });

const pathGroupForKeepingReactImportsAtTop = {
  pattern: "react+(-native|)",
  group: "external",
  position: "before",
};
pathGroups.push(pathGroupForKeepingReactImportsAtTop);

export default defineConfig([
  {
    rules: {
      "import/order": [
        "error",
        {
          "newlines-between": "always",
          alphabetize: { order: "asc", caseInsensitive: true },
          warnOnUnassignedImports: true,
          groups: [
            "builtin",
            "external",
            "internal",
            "index",
            "sibling",
            "parent",
            "object",
            "type",
          ],
          pathGroups,
          pathGroupsExcludedImportTypes: ["react", "react-native"],
        },
      ],
    },
  },
]);
