import { c as E, p as k, h as N, f as D, i as q, b as V, d as z, u as W, v as X, e as A, k as Z, r as F } from "./AssetItem-ufNA-vj9.js";
import { a as $ } from "./index-client-DOkVNeOk.js";
import { t as K, m as I, w as P, z as b, x as S, E as a, r as U, l as B, p as ee, y as G, C as te, D as y, n as re, v as ae, o as ne, F as j, I as O, K as se, bv as oe, W as le, N as H, O as L, L as ue, bw as ce } from "./index-DRgrWhNH.js";
import { C as ie } from "./ContentHeader-B8i-EqEU.js";
import { B as Y } from "./Button-Dvas4qfY.js";
import { e as de, i as ve } from "./each-C_AuyVTL.js";
import { b as fe } from "./input-BDcUSgHd.js";
var me = D("<button> </button>"), ge = D('<div class="crtw-text-xs crtw-text-gray-400 crtw-mt-1"> </div>'), pe = D('<input class="crtw-appearance-none focus:crtw-outline-0 crtw-w-full crtw-h-9 crtw-mt-4 crtw-px-5 crtw-text-base crtw-border crtw-border-gray-300 crtw-rounded focus:crtw-border-blue-800 hover:crtw-bg-gray-100" type="number" min="1" max="100"/> <!>', 1), we = D('<div><div class="crtw-flex crtw-flex-col">Select amount <div class="crtw-inline-flex crtw-w-full" role="group"></div> <!></div></div>');
function J(g, n) {
  if (new.target) return E({ component: J, ...g });
  K(n, !1);
  let s = k(n, "selected", 12, void 0), o = k(n, "minStoredValueToPurchase", 12, 0), l = k(n, "maxStoredValueToPurchase", 12, 100), w = I(!1), p = I(s());
  const h = [
    { value: "10", name: "10" },
    { value: "25", name: "25" },
    { value: "50", name: "50" },
    { value: "CUSTOM", name: "Custom" }
  ], T = (e) => {
    if (y(p, e), e === "CUSTOM") {
      y(w, !0), s("");
      return;
    }
    y(w, !1), s(e);
  }, C = (e) => {
    const r = e.target;
    if (r.value = r.value.replace(/[,.-]/g, ""), +r.value > l()) {
      s(l().toString());
      return;
    }
    s(r.value);
  };
  var c = {
    get selected() {
      return s();
    },
    set selected(e) {
      s(e), B();
    },
    get minStoredValueToPurchase() {
      return o();
    },
    set minStoredValueToPurchase(e) {
      o(e), B();
    },
    get maxStoredValueToPurchase() {
      return l();
    },
    set maxStoredValueToPurchase(e) {
      l(e), B();
    },
    $set: W,
    $on: (e, r) => z(n, e, r)
  };
  N();
  var i = we(), m = P(i), u = b(P(m));
  de(u, 5, () => h, ve, (e, r) => {
    var t = me();
    let f;
    var d = P(t, !0);
    S(t), G(() => {
      f = Z(t, 1, "crtw-w-full crtw-h-[30px] crtw-text-sm crtw-border hover:crtw-bg-gray-100 hover:crtw-text-blue-800 first:crtw-rounded-l last:crtw-rounded-r", null, f, {
        "crtw-border-blue-800": a(r).value === a(p),
        "crtw-z-10": a(r).value === a(p)
      }), F(d, (a(r), te(() => a(r).name)));
    }), A("click", t, () => T(a(r).value)), V(e, t);
  }), S(u);
  var x = b(u, 2);
  {
    var v = (e) => {
      var r = pe(), t = ee(r);
      X(t);
      var f = b(t, 2);
      {
        var d = (_) => {
          var M = ge(), R = P(M);
          S(M), G(() => F(R, `Minimum purchase amount is ${o() ?? ""}`)), V(_, M);
        };
        q(f, (_) => {
          o() && _(d);
        });
      }
      fe(t, s), A("input", t, C), V(e, r);
    };
    q(x, (e) => {
      a(w) && e(v);
    });
  }
  return S(m), S(i), V(g, i), U(c);
}
var he = D('<div class="crtw-w-full crtw-px-2.5"><!> <!> <div class="crtw-h-4"></div> <!> <div class="crtw-m-3.5"></div> <!></div>');
function Q(g, n) {
  if (new.target) return E({ component: Q, ...g });
  K(n, !1);
  const s = I();
  let o = k(n, "selected", 12), l = k(n, "options", 12), {
    title: w,
    description: p,
    onSendClick: h,
    sendValueButtonText: T,
    onPaymentClick: C,
    minStoredValueToPurchase: c = 0,
    maxStoredValueToPurchase: i = 100
  } = l();
  re(() => ae(l()), () => {
    y(s, l().isSendValueDisabled);
  }), ne();
  var m = {
    get selected() {
      return o();
    },
    set selected(t) {
      o(t), B();
    },
    get options() {
      return l();
    },
    set options(t) {
      l(t), B();
    },
    $set: W,
    $on: (t, f) => z(n, t, f)
  };
  N();
  var u = he(), x = P(u);
  ie(x, {
    get text() {
      return w;
    },
    get description() {
      return p;
    }
  });
  var v = b(x, 2);
  J(v, {
    get minStoredValueToPurchase() {
      return c;
    },
    get maxStoredValueToPurchase() {
      return i;
    },
    get selected() {
      return o();
    },
    set selected(t) {
      o(t);
    },
    $$legacy: !0
  });
  var e = b(v, 4);
  {
    let t = j(() => !o() || !!c && +o() < c);
    Y(e, {
      text: "Confirm purchase",
      get disabled() {
        return a(t);
      },
      get onClick() {
        return C;
      }
    });
  }
  var r = b(e, 4);
  return Y(r, {
    get onClick() {
      return h;
    },
    get text() {
      return T;
    },
    get disabled() {
      return a(s);
    }
  }), S(u), V(g, u), U(m);
}
function _e(g, n) {
  if (new.target) return E({ component: _e, ...g });
  K(n, !1);
  var s = this && this.__awaiter || function(c, i, m, u) {
    function x(v) {
      return v instanceof m ? v : new m(function(e) {
        e(v);
      });
    }
    return new (m || (m = Promise))(function(v, e) {
      function r(d) {
        try {
          f(u.next(d));
        } catch (_) {
          e(_);
        }
      }
      function t(d) {
        try {
          f(u.throw(d));
        } catch (_) {
          e(_);
        }
      }
      function f(d) {
        d.done ? v(d.value) : x(d.value).then(r, t);
      }
      f((u = u.apply(c, i || [])).next());
    });
  };
  const { getBalance: o } = O(se), { maxStoredValueToPurchase: l, minStoredValueToPurchase: w } = oe(O(le).clientId);
  let p = I("");
  $(() => s(void 0, void 0, void 0, function* () {
    y(p, yield o());
  }));
  let h = I("10");
  const T = () => {
    ue.set({
      subtitle: "Purchase stored value",
      payments: { credenzaStoredValue: { disabled: !0 } },
      assets: [
        {
          packageId: O(ce),
          type: "cred",
          amount: +a(h)
        }
      ]
    }), H.set(L.PAYMENT);
  };
  var C = {
    $set: W,
    $on: (c, i) => z(n, c, i)
  };
  N();
  {
    let c = j(() => ({
      title: "buy stored value",
      description: "Buy/Send stored value for purchases throughout this website.",
      onSendClick: () => H.set(L.SEND_TOKENS),
      sendValueButtonText: "Send stored value",
      isSendValueDisabled: !a(p),
      onPaymentClick: T,
      maxStoredValueToPurchase: l,
      minStoredValueToPurchase: w
    }));
    Q(g, {
      get options() {
        return a(c);
      },
      get selected() {
        return a(h);
      },
      set selected(i) {
        y(h, i);
      },
      $$legacy: !0
    });
  }
  return U(C);
}
export {
  _e as default
};
//# sourceMappingURL=Wallet-CMmhZ02h.js.map
