import { c as N, p as B, h as U, f as I, i as J, b as k, d as W, u as q, v as re, e as K, k as ae, r as L, o as A, n as se } from "./AssetItem-BxjLUzNd.js";
import { t as G, m as E, w as $, z as T, x as y, E as n, r as H, l as D, p as ne, y as Q, C as oe, D as S, n as F, v as ce, o as R, V as X, J as le, L as ue, I as ie, Z as de, O as Y, Q as Z, M as ve, bA as fe } from "./index-BBXAtvZr.js";
import { C as me } from "./ContentHeader-CNIXuMji.js";
import { B as j } from "./Button-CqLZSfSk.js";
import { e as pe, i as ge } from "./each-D1jTQ_vC.js";
import { b as we } from "./input-c8sTQ2Qk.js";
var _e = I("<button> </button>"), he = I('<div class="crtw-text-xs crtw-text-gray-400 crtw-mt-1"> </div>'), Se = I('<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), xe = I('<div><div class="crtw-flex crtw-flex-col">Select amount <div class="crtw-inline-flex crtw-w-full" role="group"></div> <!></div></div>');
function ee(f, o) {
  if (new.target) return N({ component: ee, ...f });
  G(o, !1);
  let a = B(o, "selected", 12, void 0), s = B(o, "minStoredValueToPurchase", 12, 0), c = B(o, "maxStoredValueToPurchase", 12, 100), u = E(!1), g = E(a());
  const V = [
    { value: "10", name: "10" },
    { value: "25", name: "25" },
    { value: "50", name: "50" },
    { value: "CUSTOM", name: "Custom" }
  ], C = (e) => {
    if (S(g, e), e === "CUSTOM") {
      S(u, !0), a("");
      return;
    }
    S(u, !1), a(e);
  }, w = (e) => {
    const r = e.target;
    if (r.value = r.value.replace(/[,.-]/g, ""), +r.value > c()) {
      a(c().toString());
      return;
    }
    a(r.value);
  };
  var _ = {
    get selected() {
      return a();
    },
    set selected(e) {
      a(e), D();
    },
    get minStoredValueToPurchase() {
      return s();
    },
    set minStoredValueToPurchase(e) {
      s(e), D();
    },
    get maxStoredValueToPurchase() {
      return c();
    },
    set maxStoredValueToPurchase(e) {
      c(e), D();
    },
    $set: q,
    $on: (e, r) => W(o, e, r)
  };
  U();
  var i = xe(), x = $(i), d = T($(x));
  pe(d, 5, () => V, ge, (e, r) => {
    var t = _e();
    let m;
    var v = $(t, !0);
    y(t), Q(() => {
      m = ae(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, m, {
        "crtw-border-blue-800": n(r).value === n(g),
        "crtw-z-10": n(r).value === n(g)
      }), L(v, (n(r), oe(() => n(r).name)));
    }), K("click", t, () => C(n(r).value)), k(e, t);
  }), y(d);
  var b = T(d, 2);
  {
    var l = (e) => {
      var r = Se(), t = ne(r);
      re(t);
      var m = T(t, 2);
      {
        var v = (p) => {
          var P = he(), M = $(P);
          y(P), Q(() => L(M, `Minimum purchase amount is ${s() ?? ""}`)), k(p, P);
        };
        J(m, (p) => {
          s() && p(v);
        });
      }
      we(t, a), K("input", t, w), k(e, r);
    };
    J(b, (e) => {
      n(u) && e(l);
    });
  }
  return y(x), y(i), k(f, i), H(_);
}
var be = I('<div class="crtw-w-full crtw-px-2.5"><!> <!> <div class="crtw-h-4"></div> <!> <div class="crtw-m-3.5"></div> <!></div>');
function te(f, o) {
  if (new.target) return N({ component: te, ...f });
  G(o, !1);
  const a = E();
  let s = B(o, "selected", 12), c = B(o, "options", 12), {
    title: u,
    description: g,
    onSendClick: V,
    sendValueButtonText: C,
    onPaymentClick: w,
    minStoredValueToPurchase: _ = 0,
    maxStoredValueToPurchase: i = 100
  } = c();
  F(() => ce(c()), () => {
    S(a, c().isSendValueDisabled);
  }), R();
  var x = {
    get selected() {
      return s();
    },
    set selected(t) {
      s(t), D();
    },
    get options() {
      return c();
    },
    set options(t) {
      c(t), D();
    },
    $set: q,
    $on: (t, m) => W(o, t, m)
  };
  U();
  var d = be(), b = $(d);
  me(b, {
    get text() {
      return u;
    },
    get description() {
      return g;
    }
  });
  var l = T(b, 2);
  ee(l, {
    get minStoredValueToPurchase() {
      return _;
    },
    get maxStoredValueToPurchase() {
      return i;
    },
    get selected() {
      return s();
    },
    set selected(t) {
      s(t);
    },
    $$legacy: !0
  });
  var e = T(l, 4);
  {
    let t = X(() => !s() || !!_ && +s() < _);
    j(e, {
      text: "Confirm purchase",
      get disabled() {
        return n(t);
      },
      get onClick() {
        return w;
      }
    });
  }
  var r = T(e, 4);
  return j(r, {
    get onClick() {
      return V;
    },
    get text() {
      return C;
    },
    get disabled() {
      return n(a);
    }
  }), y(d), k(f, d), H(x);
}
function ye(f, o) {
  if (new.target) return N({ component: ye, ...f });
  G(o, !1);
  const a = () => A(ie, "$configStore", u), s = () => A(de, "$providerStore", u), c = () => A(fe, "$contractsStore", u), [u, g] = se();
  var V = this && this.__awaiter || function(l, e, r, t) {
    function m(v) {
      return v instanceof r ? v : new r(function(p) {
        p(v);
      });
    }
    return new (r || (r = Promise))(function(v, p) {
      function P(h) {
        try {
          O(t.next(h));
        } catch (z) {
          p(z);
        }
      }
      function M(h) {
        try {
          O(t.throw(h));
        } catch (z) {
          p(z);
        }
      }
      function O(h) {
        h.done ? v(h.value) : m(h.value).then(P, M);
      }
      O((t = t.apply(l, e || [])).next());
    });
  };
  const { getBalance: C } = le(ue);
  let w = E("");
  const _ = () => V(void 0, void 0, void 0, function* () {
    try {
      S(w, yield C());
    } catch {
      S(w, "0");
    }
  });
  let i = E("10");
  const x = () => {
    ve.set({
      title: "Purchase stored value",
      payments: { credenzaStoredValue: { disabled: !0 } },
      tokens: [
        {
          contractAddress: c().erc20Cred.address,
          amount: +n(i)
        }
      ]
    }), Y.set(Z.PAYMENT);
  };
  F(() => (a(), s()), () => {
    a().chainId && s() && _();
  }), R();
  var d = {
    $set: q,
    $on: (l, e) => W(o, l, e)
  };
  U();
  {
    let l = X(() => ({
      title: "buy stored value",
      description: "Buy/Send stored value for purchases throughout this website.",
      onSendClick: () => Y.set(Z.SEND_TOKENS),
      sendValueButtonText: "Send stored value",
      isSendValueDisabled: !n(w),
      onPaymentClick: x
    }));
    te(f, {
      get options() {
        return n(l);
      },
      get selected() {
        return n(i);
      },
      set selected(e) {
        S(i, e);
      },
      $$legacy: !0
    });
  }
  var b = H(d);
  return g(), b;
}
export {
  ye as default
};
//# sourceMappingURL=Wallet-ReusbIhq.js.map
