{"version":3,"file":"useAdminRoles-t0VegNFc.mjs","sources":["../../admin/src/hooks/useAdminRoles.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useCollator } from '@strapi/helper-plugin';\nimport { useIntl } from 'react-intl';\n\nimport { GetRolesParams, useGetRolesQuery } from '../services/users';\n\nimport type { FindRoles } from '../../../shared/contracts/roles';\n\nexport type AdminRole = FindRoles.Response['data'][number];\n\nexport const useAdminRoles = (\n  params: GetRolesParams = {},\n  queryOptions?: Parameters<typeof useGetRolesQuery>[1]\n) => {\n  const { locale } = useIntl();\n  const formatter = useCollator(locale, {\n    sensitivity: 'base',\n  });\n\n  const { data, error, isError, isLoading, refetch } = useGetRolesQuery(params, queryOptions);\n\n  // the return value needs to be memoized, because intantiating\n  // an empty array as default value would lead to an unstable return\n  // value, which later on triggers infinite loops if used in the\n  // dependency arrays of other hooks\n  const roles = React.useMemo(\n    () =>\n      [...(data ?? [])].sort((a, b) =>\n        formatter.compare(a.name, b.name)\n      ) as FindRoles.Response['data'],\n    [data, formatter]\n  );\n\n  return {\n    roles,\n    error,\n    isError,\n    isLoading,\n    refetch,\n  };\n};\n"],"names":[],"mappings":";;;;AAWO,MAAM,gBAAgB,CAC3B,SAAyB,IACzB,iBACG;AACG,QAAA,EAAE,WAAW;AACb,QAAA,YAAY,YAAY,QAAQ;AAAA,IACpC,aAAa;AAAA,EAAA,CACd;AAEK,QAAA,EAAE,MAAM,OAAO,SAAS,WAAW,QAAQ,IAAI,iBAAiB,QAAQ,YAAY;AAM1F,QAAM,QAAQ,MAAM;AAAA,IAClB,MACE,CAAC,GAAI,QAAQ,CAAG,CAAA,EAAE;AAAA,MAAK,CAAC,GAAG,MACzB,UAAU,QAAQ,EAAE,MAAM,EAAE,IAAI;AAAA,IAClC;AAAA,IACF,CAAC,MAAM,SAAS;AAAA,EAAA;AAGX,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}