import { jsx as t } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useCallback as g } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useFetch as d } from "../../../../../hooks/useFetch.js";
import { GrantActionsEmbedded as f } from "../GrantActionsEmbedded/GrantActionsEmbedded.js";
import { GrantActionsHosted as u } from "../GrantActionsHosted/GrantActionsHosted.js";
import { AlertTypeOption as A } from "../../../../internal/Alert/types.js";
import { Alert as y } from "../../../../internal/Alert/Alert.js";
/* empty css                  */
import { useMissingActionsPolling as C } from "./hooks/useMissingActionsPolling.js";
import { useConfigContext as k } from "../../../../../core/ConfigContext/preact/context.js";
import { EMPTY_OBJECT as S } from "../../../../../utils/value/constants.js";
const a = {
  actionsTitleSkeleton: "adyen-pe-grant-actions__actions-title-skeleton",
  actionsDescriptionSkeleton: "adyen-pe-grant-actions__actions-description-skeleton"
}, I = ({
  grantId: l,
  missingActions: c,
  offerExpiresAt: e,
  className: n,
  onComplete: m
}) => {
  const { getOnboardingConfiguration: r } = k().endpoints, { missingActions: o, isPollingComplete: s, forcePollingComplete: p } = C({ grantId: l, initialMissingActions: c }), i = d({
    fetchOptions: {
      enabled: s && !!o.length,
      onError: p
    },
    queryFn: g(async () => r?.(S), [r])
  });
  return o.length ? !s || i.isFetching ? /* @__PURE__ */ t(
    y,
    {
      className: n,
      type: A.WARNING,
      title: /* @__PURE__ */ t("div", { className: a.actionsTitleSkeleton }),
      description: /* @__PURE__ */ t("div", { className: a.actionsDescriptionSkeleton })
    }
  ) : i.data ? /* @__PURE__ */ t(
    f,
    {
      className: n,
      expirationDate: e,
      legalEntityId: i.data.legalEntityId,
      missingActions: o,
      onComplete: m
    }
  ) : /* @__PURE__ */ t(u, { missingActions: o, expirationDate: e, className: n }) : null;
};
export {
  I as GrantActions
};
