import { jsx as t, Fragment as m, jsxs as u } from "react/jsx-runtime";
import { p as v, o as T, q as _, s as a, W as L, t as V, d as W, S as x } from "./index-C62tPk5p.js";
import { useMemo as $, useState as p } from "react";
import { A as j } from "./AppCard-CQEg94Y3.js";
import { c as g, i as R, a as C } from "./currencyOptions-r01lKGBF.js";
const I = function({ app: S, eventType: A, onAppInstallSuccess: P }) {
  var f, h;
  const i = v.useSearchParams(), d = v.usePathname(), k = $(
    () => `${d}${i ? `?${i.toString()}` : ""}`,
    [d, i]
  ), { t: n } = T(), { getAppData: r, setAppData: c } = _(), y = r("price"), l = r("currency"), N = r("paymentOption"), O = r("enabled"), [s, w] = p(g.find((e) => e.value === l)), [E, q] = p(
    R(l) ? C[l] : ""
  ), [b, D] = p(O), o = ((f = a) == null ? void 0 : f.find((e) => N === e.value)) || {
    label: a[0].label,
    value: a[0].value
  }, F = ((h = A.recurringEvent) == null ? void 0 : h.count) !== void 0;
  return /* @__PURE__ */ t(
    j,
    {
      onAppInstallSuccess: P,
      returnTo: L + k,
      app: S,
      switchChecked: b,
      switchOnClick: (e) => {
        D(e);
      },
      description: /* @__PURE__ */ t(m, { children: "Add a mock payment to your events" }),
      children: /* @__PURE__ */ t(m, { children: F ? /* @__PURE__ */ t(V, { className: "mt-2", severity: "warning", title: n("warning_recurring_event_payment") }) : b && /* @__PURE__ */ u(m, { children: [
        /* @__PURE__ */ t("div", { className: "mt-2 block items-center sm:flex", children: /* @__PURE__ */ t(
          W,
          {
            id: "test-mock-payment-app-price",
            label: "Price",
            labelSrOnly: !0,
            addOnLeading: E,
            addOnSuffix: l,
            step: "0.01",
            min: "0.5",
            type: "number",
            required: !0,
            className: "block w-full rounded-sm pl-2 text-sm",
            placeholder: "Price",
            onChange: (e) => {
              c("price", Number(e.target.value) * 100), s && c("currency", s.value);
            },
            value: y > 0 ? y / 100 : void 0
          }
        ) }),
        /* @__PURE__ */ u("div", { className: "mt-5 w-60", children: [
          /* @__PURE__ */ t("label", { className: "text-default mb-1 block text-sm font-medium", htmlFor: "currency", children: n("currency") }),
          /* @__PURE__ */ t(
            x,
            {
              id: "test-mock-payment-app-currency-id",
              variant: "default",
              options: g,
              value: s,
              className: "text-black",
              defaultValue: s,
              onChange: (e) => {
                e && (w(e), q(C[e.value]), c("currency", e.value));
              }
            }
          )
        ] }),
        /* @__PURE__ */ u("div", { className: "mt-4 w-60", children: [
          /* @__PURE__ */ t("label", { className: "text-default mb-1 block text-sm font-medium", htmlFor: "currency", children: "Payment option" }),
          /* @__PURE__ */ t(
            x,
            {
              defaultValue: o ? { ...o, label: n(o.label) } : { ...a[0], label: n(a[0].label) },
              options: a.map((e) => ({ ...e, label: n(e.label) || e.label })),
              onChange: (e) => {
                e && c("paymentOption", e.value);
              },
              className: "mb-1 h-[38px] w-full",
              isDisabled: !1
            }
          )
        ] })
      ] }) })
    }
  );
};
export {
  I as default
};
