import { jsxs as H, jsx as g } from "react/jsx-runtime";
import f, { useState as R, useEffect as Z } from "react";
import { am as S, q as ee, b as Ce, r as G, W as Oe } from "./index-ZQlxzdt5.js";
function Y(n, e) {
  var t = Object.keys(n);
  if (Object.getOwnPropertySymbols) {
    var r = Object.getOwnPropertySymbols(n);
    e && (r = r.filter(function(i) {
      return Object.getOwnPropertyDescriptor(n, i).enumerable;
    })), t.push.apply(t, r);
  }
  return t;
}
function V(n) {
  for (var e = 1; e < arguments.length; e++) {
    var t = arguments[e] != null ? arguments[e] : {};
    e % 2 ? Y(Object(t), !0).forEach(function(r) {
      te(n, r, t[r]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(n, Object.getOwnPropertyDescriptors(t)) : Y(Object(t)).forEach(function(r) {
      Object.defineProperty(n, r, Object.getOwnPropertyDescriptor(t, r));
    });
  }
  return n;
}
function A(n) {
  "@babel/helpers - typeof";
  return typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? A = function(e) {
    return typeof e;
  } : A = function(e) {
    return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
  }, A(n);
}
function te(n, e, t) {
  return e in n ? Object.defineProperty(n, e, {
    value: t,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : n[e] = t, n;
}
function Pe(n, e) {
  return we(n) || je(n, e) || xe(n, e) || Ae();
}
function we(n) {
  if (Array.isArray(n))
    return n;
}
function je(n, e) {
  var t = n && (typeof Symbol < "u" && n[Symbol.iterator] || n["@@iterator"]);
  if (t != null) {
    var r = [], i = !0, a = !1, d, l;
    try {
      for (t = t.call(n); !(i = (d = t.next()).done) && (r.push(d.value), !(e && r.length === e)); i = !0)
        ;
    } catch (o) {
      a = !0, l = o;
    } finally {
      try {
        !i && t.return != null && t.return();
      } finally {
        if (a)
          throw l;
      }
    }
    return r;
  }
}
function xe(n, e) {
  if (n) {
    if (typeof n == "string")
      return X(n, e);
    var t = Object.prototype.toString.call(n).slice(8, -1);
    if (t === "Object" && n.constructor && (t = n.constructor.name), t === "Map" || t === "Set")
      return Array.from(n);
    if (t === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))
      return X(n, e);
  }
}
function X(n, e) {
  (e == null || e > n.length) && (e = n.length);
  for (var t = 0, r = new Array(e); t < e; t++)
    r[t] = n[t];
  return r;
}
function Ae() {
  throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
}
var T = function(e) {
  var t = f.useRef(e);
  return f.useEffect(function() {
    t.current = e;
  }, [e]), t.current;
}, P = function(e) {
  return e !== null && A(e) === "object";
}, Le = function(e) {
  return P(e) && typeof e.then == "function";
}, Re = function(e) {
  return P(e) && typeof e.elements == "function" && typeof e.createToken == "function" && typeof e.createPaymentMethod == "function" && typeof e.confirmCardPayment == "function";
}, z = "[object Object]", Ie = function n(e, t) {
  if (!P(e) || !P(t))
    return e === t;
  var r = Array.isArray(e), i = Array.isArray(t);
  if (r !== i)
    return !1;
  var a = Object.prototype.toString.call(e) === z, d = Object.prototype.toString.call(t) === z;
  if (a !== d)
    return !1;
  if (!a && !r)
    return e === t;
  var l = Object.keys(e), o = Object.keys(t);
  if (l.length !== o.length)
    return !1;
  for (var s = {}, c = 0; c < l.length; c += 1)
    s[l[c]] = !0;
  for (var y = 0; y < o.length; y += 1)
    s[o[y]] = !0;
  var u = Object.keys(s);
  if (u.length !== l.length)
    return !1;
  var b = e, _ = t, C = function(j) {
    return n(b[j], _[j]);
  };
  return u.every(C);
}, ne = function(e, t, r) {
  return P(e) ? Object.keys(e).reduce(function(i, a) {
    var d = !P(t) || !Ie(e[a], t[a]);
    return r.includes(a) ? (d && console.warn("Unsupported prop change: options.".concat(a, " is not a mutable property.")), i) : d ? V(V({}, i || {}), {}, te({}, a, e[a])) : i;
  }, null) : null;
}, ke = "Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.", J = function(e) {
  if (e === null || Re(e))
    return e;
  throw new Error(ke);
}, Ne = function(e) {
  if (Le(e))
    return {
      tag: "async",
      stripePromise: Promise.resolve(e).then(J)
    };
  var t = J(e);
  return t === null ? {
    tag: "empty"
  } : {
    tag: "sync",
    stripe: t
  };
}, $ = /* @__PURE__ */ f.createContext(null);
$.displayName = "ElementsContext";
var Te = function(e, t) {
  if (!e)
    throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(t, " in an <Elements> provider."));
  return e;
}, re = function(e) {
  var t = e.stripe, r = e.options, i = e.children, a = f.useMemo(function() {
    return Ne(t);
  }, [t]), d = f.useState(function() {
    return {
      stripe: a.tag === "sync" ? a.stripe : null,
      elements: a.tag === "sync" ? a.stripe.elements(r) : null
    };
  }), l = Pe(d, 2), o = l[0], s = l[1];
  f.useEffect(function() {
    var u = !0, b = function(C) {
      s(function(w) {
        return w.stripe ? w : {
          stripe: C,
          elements: C.elements(r)
        };
      });
    };
    return a.tag === "async" && !o.stripe ? a.stripePromise.then(function(_) {
      _ && u && b(_);
    }) : a.tag === "sync" && !o.stripe && b(a.stripe), function() {
      u = !1;
    };
  }, [a, o, r]);
  var c = T(t);
  f.useEffect(function() {
    c !== null && c !== t && console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.");
  }, [c, t]);
  var y = T(r);
  return f.useEffect(function() {
    if (o.elements) {
      var u = ne(r, y, ["clientSecret", "fonts"]);
      u && o.elements.update(u);
    }
  }, [r, y, o.elements]), f.useEffect(function() {
    var u = o.stripe;
    !u || !u._registerWrapper || !u.registerAppInfo || (u._registerWrapper({
      name: "react-stripe-js",
      version: "1.10.0"
    }), u.registerAppInfo({
      name: "react-stripe-js",
      version: "1.10.0",
      url: "https://stripe.com/docs/stripe-js/react"
    }));
  }, [o.stripe]), /* @__PURE__ */ f.createElement($.Provider, {
    value: o
  }, i);
};
re.propTypes = {
  stripe: S.any,
  options: S.object
};
var I = function(e) {
  var t = f.useContext($);
  return Te(t, e);
}, $e = function() {
  var e = I("calls useElements()"), t = e.elements;
  return t;
}, Be = function() {
  var e = I("calls useStripe()"), t = e.stripe;
  return t;
};
S.func.isRequired;
var h = function(e) {
  var t = f.useRef(e);
  return f.useEffect(function() {
    t.current = e;
  }, [e]), function() {
    t.current && t.current.apply(t, arguments);
  };
}, E = function() {
}, Ue = function(e) {
  return e.charAt(0).toUpperCase() + e.slice(1);
}, p = function(e, t) {
  var r = "".concat(Ue(e), "Element"), i = function(o) {
    var s = o.id, c = o.className, y = o.options, u = y === void 0 ? {} : y, b = o.onBlur, _ = b === void 0 ? E : b, C = o.onFocus, w = C === void 0 ? E : C, j = o.onReady, ce = j === void 0 ? E : j, U = o.onChange, ue = U === void 0 ? E : U, W = o.onEscape, le = W === void 0 ? E : W, F = o.onClick, fe = F === void 0 ? E : F, q = o.onLoadError, de = q === void 0 ? E : q, D = o.onLoaderStart, pe = D === void 0 ? E : D, me = I("mounts <".concat(r, ">")), M = me.elements, O = f.useRef(null), k = f.useRef(null), ye = h(ce), ve = h(_), ge = h(w), Se = h(fe), be = h(ue), he = h(le), Ee = h(de), _e = h(pe);
    f.useLayoutEffect(function() {
      if (O.current == null && M && k.current != null) {
        var v = M.create(e, u);
        O.current = v, v.mount(k.current), v.on("ready", function() {
          return ye(v);
        }), v.on("change", be), v.on("blur", ve), v.on("focus", ge), v.on("escape", he), v.on("loaderror", Ee), v.on("loaderstart", _e), v.on("click", Se);
      }
    });
    var K = T(u);
    return f.useEffect(function() {
      if (O.current) {
        var v = ne(u, K, ["paymentRequest"]);
        v && O.current.update(v);
      }
    }, [u, K]), f.useLayoutEffect(function() {
      return function() {
        O.current && (O.current.destroy(), O.current = null);
      };
    }, []), /* @__PURE__ */ f.createElement("div", {
      id: s,
      className: c,
      ref: k
    });
  }, a = function(o) {
    I("mounts <".concat(r, ">"));
    var s = o.id, c = o.className;
    return /* @__PURE__ */ f.createElement("div", {
      id: s,
      className: c
    });
  }, d = t ? a : i;
  return d.propTypes = {
    id: S.string,
    className: S.string,
    onChange: S.func,
    onBlur: S.func,
    onFocus: S.func,
    onReady: S.func,
    onClick: S.func,
    onLoadError: S.func,
    onLoaderStart: S.func,
    options: S.object
  }, d.displayName = r, d.__elementType = e, d;
}, m = typeof window > "u";
p("auBankAccount", m);
p("card", m);
p("cardNumber", m);
p("cardExpiry", m);
p("cardCvc", m);
p("fpxBank", m);
p("iban", m);
p("idealBank", m);
p("p24Bank", m);
p("epsBank", m);
var We = p("payment", m);
p("paymentRequestButton", m);
p("linkAuthentication", m);
p("shippingAddress", m);
p("affirmMessage", m);
p("afterpayClearpayMessage", m);
var B = {};
Object.defineProperty(B, "__esModule", { value: !0 });
function L(n) {
  "@babel/helpers - typeof";
  return typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? L = function(e) {
    return typeof e;
  } : L = function(e) {
    return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
  }, L(n);
}
var ae = "https://js.stripe.com/v3", Fe = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/, Q = "loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used", qe = function() {
  for (var e = document.querySelectorAll('script[src^="'.concat(ae, '"]')), t = 0; t < e.length; t++) {
    var r = e[t];
    if (Fe.test(r.src))
      return r;
  }
  return null;
}, De = function(e) {
  var t = e && !e.advancedFraudSignals ? "?advancedFraudSignals=false" : "", r = document.createElement("script");
  r.src = "".concat(ae).concat(t);
  var i = document.head || document.body;
  if (!i)
    throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");
  return i.appendChild(r), r;
}, Me = function(e, t) {
  !e || !e._registerWrapper || e._registerWrapper({
    name: "stripe-js",
    version: "1.35.0",
    startTime: t
  });
}, x = null, Ke = function(e) {
  return x !== null || (x = new Promise(function(t, r) {
    if (typeof window > "u") {
      t(null);
      return;
    }
    if (window.Stripe && e && console.warn(Q), window.Stripe) {
      t(window.Stripe);
      return;
    }
    try {
      var i = qe();
      i && e ? console.warn(Q) : i || (i = De(e)), i.addEventListener("load", function() {
        window.Stripe ? t(window.Stripe) : r(new Error("Stripe.js not available"));
      }), i.addEventListener("error", function() {
        r(new Error("Failed to load Stripe.js"));
      });
    } catch (a) {
      r(a);
      return;
    }
  })), x;
}, He = function(e, t, r) {
  if (e === null)
    return null;
  var i = e.apply(void 0, t);
  return Me(i, r), i;
}, Ge = function(e) {
  var t = `invalid load parameters; expected object of shape

    {advancedFraudSignals: boolean}

but received

    `.concat(JSON.stringify(e), `
`);
  if (e === null || L(e) !== "object")
    throw new Error(t);
  if (Object.keys(e).length === 1 && typeof e.advancedFraudSignals == "boolean")
    return e;
  throw new Error(t);
}, oe, ie = !1, se = function() {
  for (var e = arguments.length, t = new Array(e), r = 0; r < e; r++)
    t[r] = arguments[r];
  ie = !0;
  var i = Date.now();
  return Ke(oe).then(function(a) {
    return He(a, t, i);
  });
};
se.setLoadParameters = function(n) {
  if (ie)
    throw new Error("You cannot change load parameters after calling loadStripe");
  oe = Ge(n);
};
B.loadStripe = se;
var Ye = B;
const Ve = process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY || "";
let N;
const Xe = (n) => (N || (N = Ye.loadStripe(
  n || Ve
  /* , {
    locale: "es-419" TODO: Handle multiple locales,
  } */
)), N), ze = Xe, Je = (n) => {
  const { t: e, i18n: t } = ee(), { paymentOption: r, elements: i, state: a, onPaymentElementChange: d } = n, [l, o] = R(!1), [s, c] = R(r !== "HOLD"), y = l || !s || ["processing", "error"].includes(a.status), u = {
    layout: "accordion"
  };
  return Z(() => {
    i == null || i.update({ locale: t.language });
  }, [i, t.language]), /* @__PURE__ */ H("form", { id: "payment-form", className: "bg-subtle mt-4 rounded-md p-6", onSubmit: n.onSubmit, children: [
    /* @__PURE__ */ g("div", { children: /* @__PURE__ */ g(We, { options: u, onChange: (b) => d() }) }),
    r === "HOLD" && /* @__PURE__ */ g("div", { className: "bg-info mb-5 mt-2 rounded-md p-3", children: /* @__PURE__ */ g(
      Ce,
      {
        description: e("acknowledge_booking_no_show_fee", {
          amount: n.payment.amount / 100,
          formatParams: { amount: { currency: n.payment.currency } }
        }),
        onChange: (b) => c(b.target.checked),
        descriptionClassName: "text-info font-semibold"
      }
    ) }),
    /* @__PURE__ */ H("div", { className: "mt-2 flex justify-end space-x-2", children: [
      /* @__PURE__ */ g(
        G,
        {
          color: "minimal",
          disabled: y,
          id: "cancel",
          type: "button",
          loading: l,
          onClick: () => {
            o(!0), n.onCancel();
          },
          children: /* @__PURE__ */ g("span", { id: "button-text", children: e("cancel") })
        }
      ),
      /* @__PURE__ */ g(
        G,
        {
          type: "submit",
          disabled: y,
          loading: a.status === "processing",
          id: "submit",
          color: "secondary",
          children: /* @__PURE__ */ g("span", { id: "button-text", children: a.status === "processing" ? /* @__PURE__ */ g("div", { className: "spinner", id: "spinner" }) : e(r === "HOLD" ? "submit_card" : "pay_now") })
        }
      )
    ] }),
    a.status === "error" && /* @__PURE__ */ g("div", { className: "mt-4 text-center text-red-900 dark:text-gray-300", role: "alert", children: a.error.message })
  ] });
}, Qe = (n) => {
  const { t: e } = ee(), t = $e(), r = n.payment.paymentOption, i = n.booking.attendees[0].email, a = Be(), [d, l] = R({ status: "idle" });
  return /* @__PURE__ */ g(
    Je,
    {
      ...n,
      elements: t,
      paymentOption: r,
      state: d,
      onSubmit: async (o) => {
        var y;
        if (o.preventDefault(), !a || !t)
          return;
        l({ status: "processing" });
        let s;
        const c = {
          uid: n.booking.uid,
          email: i
        };
        r === "HOLD" && "setupIntent" in n.payment.data ? (s = await a.confirmSetup({
          elements: t,
          redirect: "if_required"
        }), s.setupIntent && (c.payment_intent = s.setupIntent.id, c.payment_intent_client_secret = s.setupIntent.client_secret || void 0, c.redirect_status = s.setupIntent.status)) : r === "ON_BOOKING" && (s = await a.confirmPayment({
          elements: t,
          redirect: "if_required",
          confirmParams: {
            return_url: `${Oe}/booking/${c.uid}`
          }
        }), s.paymentIntent && (c.payment_intent = s.paymentIntent.id, c.payment_intent_client_secret = s.paymentIntent.client_secret || void 0, c.redirect_status = s.paymentIntent.status)), s != null && s.error ? l({
          status: "error",
          error: new Error(`Payment failed: ${s.error.message}`)
        }) : (l({ status: "idle" }), (y = n.onPaymentSuccess) == null || y.call(n, n), n.location && (n.location.includes("integration") ? c.location = e("web_conferencing_details_to_follow") : c.location = n.location));
      },
      onCancel: () => {
        var o;
        (o = n.onPaymentCancellation) == null || o.call(n, n);
      },
      onPaymentElementChange: () => {
        l({ status: "idle" });
      }
    }
  );
}, nt = (n) => {
  const e = ze(n.payment.data.stripe_publishable_key), [t, r] = R("stripe");
  return Z(() => {
    document.documentElement.classList.contains("dark") && r("night");
  }, []), /* @__PURE__ */ g(
    re,
    {
      stripe: e,
      options: {
        clientSecret: n.clientSecret,
        appearance: {
          theme: t
        }
      },
      children: /* @__PURE__ */ g(Qe, { ...n })
    }
  );
};
export {
  nt as default
};
