import { jsx as o } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import E from "classnames";
import { memo as D } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/compat/dist/compat.module.js";
import { useMemo as n } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { ActiveView as P } from "../../types.js";
import { ButtonVariant as s } from "../../../../internal/Button/types.js";
import { ButtonActionsLayoutBasic as h } from "../../../../internal/Button/ButtonActions/types.js";
import { sharedTransactionDetailsEventProperties as O, TX_DATA_CONTAINER as _, TX_DATA_ACTION_BAR as I } from "../../constants.js";
import w from "../../../../internal/Button/ButtonActions/ButtonActions.js";
import x from "../../../../../core/Context/analytics/preact/useAnalyticsContext.js";
import L from "../../../../../core/Context/preact/useCoreContext.js";
import { Icon as M } from "../../../../internal/Icon/Icon.js";
import { Fragment as S } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
const X = ({
  extraFields: c,
  refundAvailable: m,
  refundDisabled: r,
  setActiveView: l,
  transaction: f,
  transactionNavigator: B
}) => {
  const u = x(), { currentTransaction: d, canNavigateBackward: p, canNavigateForward: T, backward: v, forward: g } = B, { i18n: a } = L(), e = n(
    () => ({
      backToRefund: { title: a.get("transactions.details.actions.backToRefund"), eventLabel: "Return to refund" },
      goToPayment: { title: a.get("transactions.details.actions.goToPayment"), eventLabel: "Go to payment" },
      refund: { title: a.get("transactions.details.actions.refund") }
    }),
    [a]
  ), i = n(() => {
    if (d === f.id) {
      if (p) return "backToRefund";
      if (T) return "goToPayment";
    }
  }, [p, T, d, f.id]), A = n(() => {
    if (m)
      return {
        disabled: r,
        event: () => {
          r || l(P.REFUND);
        },
        title: e.refund.title,
        variant: s.PRIMARY
      };
  }, [e, m, r, l]), N = n(() => {
    if (i) {
      const t = e[i], b = i === "backToRefund", k = b ? v : g;
      return {
        disabled: !1,
        event: () => {
          try {
            k();
          } finally {
            u.addEvent?.("Clicked button", {
              ...O,
              label: t.eventLabel
            });
          }
        },
        renderTitle: (C) => /* @__PURE__ */ o(S, { children: [
          /* @__PURE__ */ o(M, { name: "angle-right", style: { transform: `scaleX(${b ? -1 : 1})` } }),
          /* @__PURE__ */ o("span", { children: C })
        ] }),
        title: t.title,
        variant: s.SECONDARY
      };
    }
  }, [e, v, g, i, u]), y = n(
    () => Object.values(c || []).filter((t) => t?.type === "button").map((t) => ({
      title: t.value,
      variant: s.SECONDARY,
      event: t.config?.action,
      classNames: t.config?.className ? [t.config.className] : []
    })),
    [c]
  ), R = n(
    () => [A, N, ...y].filter(Boolean),
    [A, N, y]
  );
  return R.length > 0 ? /* @__PURE__ */ o("div", { className: E(_, I), children: /* @__PURE__ */ o(w, { actions: R, layout: h.BUTTONS_END }) }) : null;
}, W = D(X);
export {
  W as default
};
