import { bb as g, aL as Q, aK as v, k as Ce, e as H } from "./index-GTnBs7av.js";
import l, { useState as R, useEffect as Z } from "react";
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 ee = "https://js.stripe.com/v3", Oe = /^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/, G = "loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used", we = function() {
  for (var e = document.querySelectorAll('script[src^="'.concat(ee, '"]')), t = 0; t < e.length; t++) {
    var r = e[t];
    if (Oe.test(r.src))
      return r;
  }
  return null;
}, Pe = function(e) {
  var t = e && !e.advancedFraudSignals ? "?advancedFraudSignals=false" : "", r = document.createElement("script");
  r.src = "".concat(ee).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;
}, je = function(e, t) {
  !e || !e._registerWrapper || e._registerWrapper({
    name: "stripe-js",
    version: "1.35.0",
    startTime: t
  });
}, x = null, _e = function(e) {
  return x !== null || (x = new Promise(function(t, r) {
    if (typeof window > "u") {
      t(null);
      return;
    }
    if (window.Stripe && e && console.warn(G), window.Stripe) {
      t(window.Stripe);
      return;
    }
    try {
      var i = we();
      i && e ? console.warn(G) : i || (i = Pe(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;
}, xe = function(e, t, r) {
  if (e === null)
    return null;
  var i = e.apply(void 0, t);
  return je(i, r), i;
}, Le = 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);
}, te, ne = !1, re = function() {
  for (var e = arguments.length, t = new Array(e), r = 0; r < e; r++)
    t[r] = arguments[r];
  ne = !0;
  var i = Date.now();
  return _e(te).then(function(a) {
    return xe(a, t, i);
  });
};
re.setLoadParameters = function(n) {
  if (ne)
    throw new Error("You cannot change load parameters after calling loadStripe");
  te = Le(n);
};
B.loadStripe = re;
var Ae = B;
const Re = process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY || "";
let N;
const Ie = (n) => (N || (N = Ae.loadStripe(
  n || Re
  /* , {
    locale: "es-419" TODO: Handle multiple locales,
  } */
)), N), ke = Ie;
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) {
      ae(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 ae(n, e, t) {
  return e in n ? Object.defineProperty(n, e, {
    value: t,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : n[e] = t, n;
}
function Ne(n, e) {
  return Te(n) || Be(n, e) || $e(n, e) || Ue();
}
function Te(n) {
  if (Array.isArray(n))
    return n;
}
function Be(n, e) {
  var t = n && (typeof Symbol < "u" && n[Symbol.iterator] || n["@@iterator"]);
  if (t != null) {
    var r = [], i = !0, a = !1, f, u;
    try {
      for (t = t.call(n); !(i = (f = t.next()).done) && (r.push(f.value), !(e && r.length === e)); i = !0)
        ;
    } catch (o) {
      a = !0, u = o;
    } finally {
      try {
        !i && t.return != null && t.return();
      } finally {
        if (a)
          throw u;
      }
    }
    return r;
  }
}
function $e(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 Ue() {
  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 = l.useRef(e);
  return l.useEffect(function() {
    t.current = e;
  }, [e]), t.current;
}, P = function(e) {
  return e !== null && A(e) === "object";
}, Fe = function(e) {
  return P(e) && typeof e.then == "function";
}, We = function(e) {
  return P(e) && typeof e.elements == "function" && typeof e.createToken == "function" && typeof e.createPaymentMethod == "function" && typeof e.confirmCardPayment == "function";
}, z = "[object Object]", De = 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, f = Object.prototype.toString.call(t) === z;
  if (a !== f)
    return !1;
  if (!a && !r)
    return e === t;
  var u = Object.keys(e), o = Object.keys(t);
  if (u.length !== o.length)
    return !1;
  for (var s = {}, d = 0; d < u.length; d += 1)
    s[u[d]] = !0;
  for (var S = 0; S < o.length; S += 1)
    s[o[S]] = !0;
  var c = Object.keys(s);
  if (c.length !== u.length)
    return !1;
  var b = e, C = t, O = function(_) {
    return n(b[_], C[_]);
  };
  return c.every(O);
}, oe = function(e, t, r) {
  return P(e) ? Object.keys(e).reduce(function(i, a) {
    var f = !P(t) || !De(e[a], t[a]);
    return r.includes(a) ? (f && console.warn("Unsupported prop change: options.".concat(a, " is not a mutable property.")), i) : f ? V(V({}, i || {}), {}, ae({}, a, e[a])) : i;
  }, null) : null;
}, qe = "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 || We(e))
    return e;
  throw new Error(qe);
}, Me = function(e) {
  if (Fe(e))
    return {
      tag: "async",
      stripePromise: Promise.resolve(e).then(J)
    };
  var t = J(e);
  return t === null ? {
    tag: "empty"
  } : {
    tag: "sync",
    stripe: t
  };
}, $ = /* @__PURE__ */ l.createContext(null);
$.displayName = "ElementsContext";
var Ke = 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;
}, ie = function(e) {
  var t = e.stripe, r = e.options, i = e.children, a = l.useMemo(function() {
    return Me(t);
  }, [t]), f = l.useState(function() {
    return {
      stripe: a.tag === "sync" ? a.stripe : null,
      elements: a.tag === "sync" ? a.stripe.elements(r) : null
    };
  }), u = Ne(f, 2), o = u[0], s = u[1];
  l.useEffect(function() {
    var c = !0, b = function(O) {
      s(function(j) {
        return j.stripe ? j : {
          stripe: O,
          elements: O.elements(r)
        };
      });
    };
    return a.tag === "async" && !o.stripe ? a.stripePromise.then(function(C) {
      C && c && b(C);
    }) : a.tag === "sync" && !o.stripe && b(a.stripe), function() {
      c = !1;
    };
  }, [a, o, r]);
  var d = T(t);
  l.useEffect(function() {
    d !== null && d !== t && console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.");
  }, [d, t]);
  var S = T(r);
  return l.useEffect(function() {
    if (o.elements) {
      var c = oe(r, S, ["clientSecret", "fonts"]);
      c && o.elements.update(c);
    }
  }, [r, S, o.elements]), l.useEffect(function() {
    var c = o.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"
    }));
  }, [o.stripe]), /* @__PURE__ */ l.createElement($.Provider, {
    value: o
  }, i);
};
ie.propTypes = {
  stripe: g.any,
  options: g.object
};
var I = function(e) {
  var t = l.useContext($);
  return Ke(t, e);
}, He = function() {
  var e = I("calls useElements()"), t = e.elements;
  return t;
}, Ge = function() {
  var e = I("calls useStripe()"), t = e.stripe;
  return t;
};
g.func.isRequired;
var h = function(e) {
  var t = l.useRef(e);
  return l.useEffect(function() {
    t.current = e;
  }, [e]), function() {
    t.current && t.current.apply(t, arguments);
  };
}, E = function() {
}, Ye = function(e) {
  return e.charAt(0).toUpperCase() + e.slice(1);
}, p = function(e, t) {
  var r = "".concat(Ye(e), "Element"), i = function(o) {
    var s = o.id, d = o.className, S = o.options, c = S === void 0 ? {} : S, b = o.onBlur, C = b === void 0 ? E : b, O = o.onFocus, j = O === void 0 ? E : O, _ = o.onReady, se = _ === void 0 ? E : _, U = o.onChange, ce = U === void 0 ? E : U, F = o.onEscape, ue = F === void 0 ? E : F, W = o.onClick, le = W === void 0 ? E : W, D = o.onLoadError, fe = D === void 0 ? E : D, q = o.onLoaderStart, de = q === void 0 ? E : q, pe = I("mounts <".concat(r, ">")), M = pe.elements, w = l.useRef(null), k = l.useRef(null), me = h(se), ve = h(C), ye = h(j), ge = h(le), Se = h(ce), be = h(ue), he = h(fe), Ee = h(de);
    l.useLayoutEffect(function() {
      if (w.current == null && M && k.current != null) {
        var y = M.create(e, c);
        w.current = y, y.mount(k.current), y.on("ready", function() {
          return me(y);
        }), y.on("change", Se), y.on("blur", ve), y.on("focus", ye), y.on("escape", be), y.on("loaderror", he), y.on("loaderstart", Ee), y.on("click", ge);
      }
    });
    var K = T(c);
    return l.useEffect(function() {
      if (w.current) {
        var y = oe(c, K, ["paymentRequest"]);
        y && w.current.update(y);
      }
    }, [c, K]), l.useLayoutEffect(function() {
      return function() {
        w.current && (w.current.destroy(), w.current = null);
      };
    }, []), /* @__PURE__ */ l.createElement("div", {
      id: s,
      className: d,
      ref: k
    });
  }, a = function(o) {
    I("mounts <".concat(r, ">"));
    var s = o.id, d = o.className;
    return /* @__PURE__ */ l.createElement("div", {
      id: s,
      className: d
    });
  }, f = t ? a : i;
  return f.propTypes = {
    id: g.string,
    className: g.string,
    onChange: g.func,
    onBlur: g.func,
    onFocus: g.func,
    onReady: g.func,
    onClick: g.func,
    onLoadError: g.func,
    onLoaderStart: g.func,
    options: g.object
  }, f.displayName = r, f.__elementType = e, f;
}, 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 Ve = p("payment", m);
p("paymentRequestButton", m);
p("linkAuthentication", m);
p("shippingAddress", m);
p("affirmMessage", m);
p("afterpayClearpayMessage", m);
const Xe = (n) => {
  const { t: e, i18n: t } = Q(), { paymentOption: r, elements: i, state: a, onPaymentElementChange: f } = n, [u, o] = R(!1), [s, d] = R(r !== "HOLD"), S = u || !s || ["processing", "error"].includes(a.status), c = {
    layout: "accordion"
  };
  return Z(() => {
    i == null || i.update({ locale: t.language });
  }, [i, t.language]), /* @__PURE__ */ v.jsxs("form", { id: "payment-form", className: "bg-subtle mt-4 rounded-md p-6", onSubmit: n.onSubmit, children: [
    /* @__PURE__ */ v.jsx("div", { children: /* @__PURE__ */ v.jsx(Ve, { options: c, onChange: (b) => f() }) }),
    r === "HOLD" && /* @__PURE__ */ v.jsx("div", { className: "bg-info mb-5 mt-2 rounded-md p-3", children: /* @__PURE__ */ v.jsx(
      Ce,
      {
        description: e("acknowledge_booking_no_show_fee", {
          amount: n.payment.amount / 100,
          formatParams: { amount: { currency: n.payment.currency } }
        }),
        onChange: (b) => d(b.target.checked),
        descriptionClassName: "text-info font-semibold"
      }
    ) }),
    /* @__PURE__ */ v.jsxs("div", { className: "mt-2 flex justify-end space-x-2", children: [
      /* @__PURE__ */ v.jsx(
        H,
        {
          color: "minimal",
          disabled: S,
          id: "cancel",
          type: "button",
          loading: u,
          onClick: () => {
            o(!0), n.onCancel();
          },
          children: /* @__PURE__ */ v.jsx("span", { id: "button-text", children: e("cancel") })
        }
      ),
      /* @__PURE__ */ v.jsx(
        H,
        {
          type: "submit",
          disabled: S,
          loading: a.status === "processing",
          id: "submit",
          color: "secondary",
          children: /* @__PURE__ */ v.jsx("span", { id: "button-text", children: a.status === "processing" ? /* @__PURE__ */ v.jsx("div", { className: "spinner", id: "spinner" }) : e(r === "HOLD" ? "submit_card" : "pay_now") })
        }
      )
    ] }),
    a.status === "error" && /* @__PURE__ */ v.jsx("div", { className: "mt-4 text-center text-red-900 dark:text-gray-300", role: "alert", children: a.error.message })
  ] });
}, ze = (n) => {
  const { t: e } = Q(), t = He(), r = n.payment.paymentOption, i = n.booking.attendees[0].email, a = Ge(), [f, u] = R({ status: "idle" });
  return /* @__PURE__ */ v.jsx(
    Xe,
    {
      ...n,
      elements: t,
      paymentOption: r,
      state: f,
      onSubmit: async (o) => {
        var d;
        if (o.preventDefault(), !a || !t)
          return;
        u({ status: "processing" });
        let s;
        n.booking.uid, r === "HOLD" && "setupIntent" in n.payment.data ? (s = await a.confirmSetup({
          elements: t,
          redirect: "if_required"
        }), s.setupIntent && (s.setupIntent.id, s.setupIntent.client_secret, s.setupIntent.status)) : r === "ON_BOOKING" && (s = await a.confirmPayment({
          elements: t,
          redirect: "if_required"
        }), s.paymentIntent && (s.paymentIntent.id, s.paymentIntent.client_secret, s.paymentIntent.status)), s != null && s.error ? u({
          status: "error",
          error: new Error(`Payment failed: ${s.error.message}`)
        }) : (u({ status: "idle" }), (d = n.onPaymentSuccess) == null || d.call(n, n), n.location && (n.location.includes("integration") ? e("web_conferencing_details_to_follow") : n.location));
      },
      onCancel: () => {
        var o;
        (o = n.onPaymentCancellation) == null || o.call(n, n);
      },
      onPaymentElementChange: () => {
        u({ status: "idle" });
      }
    }
  );
}, Ze = (n) => {
  const e = ke(n.payment.data.stripe_publishable_key), [t, r] = R("stripe");
  return Z(() => {
    document.documentElement.classList.contains("dark") && r("night");
  }, []), /* @__PURE__ */ v.jsx(
    ie,
    {
      stripe: e,
      options: {
        clientSecret: n.clientSecret,
        appearance: {
          theme: t
        }
      },
      children: /* @__PURE__ */ v.jsx(ze, { ...n })
    }
  );
};
export {
  Ze as default
};
