;
{
  try {
    let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
    n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "0ed34ccb-7d96-44b8-9b77-34fbd41baa9e", e._sentryDebugIdIdentifier = "sentry-dbid-0ed34ccb-7d96-44b8-9b77-34fbd41baa9e");
  } catch (e) {
  }
}
;
import { useQuery } from "@tanstack/preact-query";
import { q as TaskStatuses, a3 as createLogger, b as useApiContext, k as httpGet } from "./StoreProvider-CqQrndhS.js";
const logger = createLogger();
const normalizeTaskStatuses = (taskStatuses) => {
  return taskStatuses?.statuses?.reduce((acc, currentTask) => {
    const status = TaskStatuses[currentTask.status];
    const statusEntries = currentTask.taskStatusEntries;
    acc[currentTask.type] = {
      status: status ?? TaskStatuses.DETAILS_REQUIRED,
      taskStatusEntries: statusEntries
    };
    return acc;
  }, {});
};
const getAccountTaskStatus = (accountId, payinPayoutTaskStatus) => {
  const taskStatusEntries = payinPayoutTaskStatus?.taskStatusEntries;
  const taskStatusEntry = taskStatusEntries?.find((entry) => entry.id.includes(accountId));
  if (!taskStatusEntry) {
    logger.warn(`No task status for this account: ${accountId}`);
    return payinPayoutTaskStatus?.status ?? TaskStatuses.PROCESSING;
  }
  return TaskStatuses[taskStatusEntry.status];
};
const getTaskStatus = async (legalEntityId, baseUrl) => {
  return httpGet({
    baseUrl,
    path: `legalEntities/${legalEntityId}/taskStatus`
  });
};
const useTaskStatus = (options) => {
  const { rootLegalEntityId, baseUrl } = useApiContext();
  return useQuery({
    queryKey: ["taskStatus"],
    queryFn: () => getTaskStatus(rootLegalEntityId.value, baseUrl.value),
    select: (data) => normalizeTaskStatuses(data),
    ...options
  });
};
export {
  getAccountTaskStatus as g,
  useTaskStatus as u
};
