import { c as N, p as B, h as G, f as I, i as q, b as k, d as H, u as U, r as re, e as F, k as ae, o as K } from "./AssetItem-CFsdMEwW.js";
import { v as W, m as E, x as $, A as T, y, I as n, t as Y, n as D, r as se, z as L, D as ne, G as S, o as R, w as oe, p as X, Y as Z, M as ce, O as le, F as A, E as ue, L as ie, a0 as de, S as Q, T as j, Q as ve, bH as fe } from "./index-BxjwuJ6T.js";
import { C as me } from "./ContentHeader-IUWmor6Y.js";
import { B as J } from "./Button-S2OwL6nP.js";
import { e as pe, i as ge } from "./each-BgMcYdMq.js";
import { b as we } from "./input-BnNaXS4t.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 });
  W(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: U,
    $on: (e, r) => H(o, e, r)
  };
  G();
  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), L(() => {
      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)
      }), K(v, (n(r), ne(() => n(r).name)));
    }), F("click", t, () => C(n(r).value)), k(e, t);
  }), y(d);
  var b = T(d, 2);
  {
    var l = (e) => {
      var r = Se(), t = se(r);
      re(t);
      var m = T(t, 2);
      {
        var v = (p) => {
          var P = he(), M = $(P);
          y(P), L(() => K(M, `Minimum purchase amount is ${s() ?? ""}`)), k(p, P);
        };
        q(m, (p) => {
          s() && p(v);
        });
      }
      we(t, a), F("input", t, w), k(e, r);
    };
    q(b, (e) => {
      n(u) && e(l);
    });
  }
  return y(x), y(i), k(f, i), Y(_);
}
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 });
  W(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();
  R(() => oe(c()), () => {
    S(a, c().isSendValueDisabled);
  }), X();
  var x = {
    get selected() {
      return s();
    },
    set selected(t) {
      s(t), D();
    },
    get options() {
      return c();
    },
    set options(t) {
      c(t), D();
    },
    $set: U,
    $on: (t, m) => H(o, t, m)
  };
  G();
  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 = Z(() => !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), Y(x);
}
function ye(f, o) {
  if (new.target) return N({ component: ye, ...f });
  W(o, !1);
  const a = () => A(ie, "$configStore", u), s = () => A(de, "$providerStore", u), c = () => A(fe, "$contractsStore", u), [u, g] = ue();
  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 } = ce(le);
  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)
        }
      ]
    }), Q.set(j.PAYMENT);
  };
  R(() => (a(), s()), () => {
    a().chainId && s() && _();
  }), X();
  var d = {
    $set: U,
    $on: (l, e) => H(o, l, e)
  };
  G();
  {
    let l = Z(() => ({
      title: "buy stored value",
      description: "Buy/Send stored value for purchases throughout this website.",
      onSendClick: () => Q.set(j.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 = Y(d);
  return g(), b;
}
export {
  ye as default
};
//# sourceMappingURL=Wallet-BsUYX2oU.js.map
