import { jsx as e } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import o from "../../../../internal/Typography/Typography.js";
import { TypographyElement as l, TypographyVariant as p } from "../../../../internal/Typography/types.js";
import { useModalContext as w } from "../../../../internal/Modal/Modal.js";
import P from "../../../../internal/Button/ButtonActions/ButtonActions.js";
import { ButtonVariant as g } from "../../../../internal/Button/types.js";
import { useRef as c, useState as R, useCallback as f, useMemo as V, useEffect as H } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useDisputeFlow as j } from "../../context/dispute/context.js";
import J from "../../../../../hooks/useMutation/useMutation.js";
import { SuccessIcon as Q } from "../../../../internal/SuccessIcon/SuccessIcon.js";
/* empty css                       */
import U from "../../../../../core/Context/preact/useCoreContext.js";
import { Icon as h } from "../../../../internal/Icon/Icon.js";
import { Fragment as B } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
import z from "../../../../internal/Button/Button.js";
import { useConfigContext as G } from "../../../../../core/ConfigContext/preact/context.js";
import { EMPTY_OBJECT as K } from "../../../../../utils/value/constants.js";
import W from "../../../../../utils/random/uniqueId.js";
import { isFunction as X } from "../../../../../utils/value/is.js";
const _e = ({ onDisputeAccept: m }) => {
  const { i18n: t } = U(), { acceptDispute: E } = G().endpoints, { dispute: y, clearStates: _, goBack: u } = j(), { withinModal: q } = w(), T = c(y).current ?? y, M = q ? l.H2 : l.DIV, s = T?.dispute.pspReference, I = T?.dispute.type === "REQUEST_FOR_INFORMATION", b = c("disputes.management.accept.chargeback.accepted"), k = c("disputes.management.accept.chargeback.disclaimer"), v = c("disputes.management.accept.chargeback.title"), N = c("disputes.management.accept.chargeback.actions.accept"), O = c(I);
  (O.current ||= I) && (b.current = "disputes.management.accept.requestForInformation.accepted", k.current = "disputes.management.accept.requestForInformation.disclaimer", v.current = "disputes.management.accept.requestForInformation.title", N.current = "disputes.management.accept.requestForInformation.actions.accept");
  const [D, S] = R(!1), [a, L] = R(!1), n = J({
    queryFn: E,
    options: {
      onSuccess: f(() => {
        _(), L(!0);
      }, [_])
    }
  }), i = n.isLoading || a, r = D && !i, F = f(() => {
    r && n.mutate(K, { path: { disputePspReference: s } });
  }, [r, s, n]), x = f(() => {
    i || S((d) => !d);
  }, [i]), Y = V(() => [
    {
      title: t.get(N.current),
      disabled: !r,
      state: n.isLoading ? "loading" : "default",
      variant: g.PRIMARY,
      event: F,
      classNames: a ? ["adyen-pe-accept-dispute__accepted-btn"] : void 0,
      renderTitle: (d) => a ? /* @__PURE__ */ e(B, { children: [
        /* @__PURE__ */ e(h, { name: "checkmark-circle-fill", className: "adyen-pe-accept-dispute__accepted-icon" }),
        t.get("disputes.management.accept.common.accepted")
      ] }) : d
    },
    {
      title: t.get("disputes.management.common.actions.goBack"),
      disabled: n.isLoading,
      variant: g.SECONDARY,
      event: u
    }
  ], [t, F, n.isLoading, r, u, a]), A = c(!1), C = c(W()).current;
  return H(() => {
    A.current || a && s && X(m) && (A.current = !0, m({ id: s }));
  }, [a, s, m]), /* @__PURE__ */ e("div", { className: "adyen-pe-accept-dispute__container", children: a ? /* @__PURE__ */ e("div", { className: "adyen-pe-accept-dispute__success", children: [
    /* @__PURE__ */ e(Q, { className: "adyen-pe-accept-dispute__success-icon" }),
    /* @__PURE__ */ e(o, { variant: p.TITLE, children: t.get(b.current) }),
    /* @__PURE__ */ e(z, { variant: g.SECONDARY, onClick: u, children: t.get("disputes.management.common.actions.showDetails") })
  ] }) : /* @__PURE__ */ e(B, { children: [
    /* @__PURE__ */ e(o, { className: "adyen-pe-accept-dispute__title", el: M, variant: p.TITLE, medium: !0, children: t.get(v.current) }),
    /* @__PURE__ */ e(o, { variant: p.BODY, medium: !0, children: t.get(k.current) }),
    /* @__PURE__ */ e("div", { className: "adyen-pe-accept-dispute__input", children: [
      /* @__PURE__ */ e(
        "input",
        {
          type: "checkbox",
          disabled: i,
          className: "adyen-pe-visually-hidden",
          id: C,
          onInput: x
        }
      ),
      /* @__PURE__ */ e("label", { className: "adyen-pe-accept-dispute__label", htmlFor: C, children: [
        D ? /* @__PURE__ */ e(h, { name: "checkmark-square-fill" }) : /* @__PURE__ */ e(h, { name: "square" }),
        /* @__PURE__ */ e(o, { el: l.SPAN, variant: p.BODY, children: t.get("disputes.management.accept.common.agree") })
      ] })
    ] }),
    /* @__PURE__ */ e("div", { className: "adyen-pe-accept-dispute__actions", children: /* @__PURE__ */ e(P, { actions: Y }) })
  ] }) });
};
export {
  _e as AcceptDisputeFlow
};
