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

    {advancedFraudSignals: boolean}

but received

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