import { c as ke, p as pe, h as Te, f as le, i as ie, k as Fe, r as me, o as ce, s as ze, e as Ge, b as W, d as Ee, u as Be, n as Ie, t as Ke } from "./AssetItem-BxjLUzNd.js";
import { t as Re, n as C, D as r, m as i, v as x, o as De, p as Qe, E as e, V as z, z as f, w, x as b, y as ge, C as de, r as Pe, a1 as Le, l as _e, J as oe, I as ye, L as Xe, $ as F, Z as Ce, M as qe, _ as Je, O as he, Q as $e, bB as We, K as Ae, P as we, bC as Ye, bD as Ze, bE as et } from "./index-BBXAtvZr.js";
import { c as tt, C as rt, s as nt, g as at } from "./index-D5XO39uY.js";
import { C as st } from "./ContentHeader-CNIXuMji.js";
import { B as it } from "./ButtonBack-DvsFRnLL.js";
import { B as be } from "./Button-CqLZSfSk.js";
import { I as xe } from "./Input-CojPyd3m.js";
import { S as ot } from "./scanner-Bm3Pvpfs.js";
var ct = le('<div>ChainId: <span class="crtw-font-bold"> </span></div>'), dt = le('<label class="crtw-text-[10px] crtw-text-warningTextColor cpui-send-tokens-validation-message" for="recipientAddress">Provided address is not valid.</label>'), lt = le('<div class="crtw-ml-2.5 crtw-w-16 crtw-min-w-16"><!></div>'), ut = le('<!> <div class="crtw-w-full crtw-p-0 crtw-relative"><div id="cpuiCredScanner"></div> <!> <div>Your balance: <span class="crtw-font-bold"><!> </span></div> <div class="crtw-mb-2.5 crtw-flex crtw-items-start crtw-justify-between crtw-w-full"><div class="crtw-flex crtw-flex-col crtw-w-full"><!> <!></div> <div class="crtw-ml-2.5 crtw-cursor-pointer"><img width="53px" alt="" class="crtw-h-[53px]"/></div></div> <div class="crtw-mb-2.5 crtw-flex crtw-items-start crtw-justify-between crtw-w-full"><!> <div class="crtw-ml-2.5 crtw-w-16 crtw-min-w-16"><!></div> <!></div> <!></div> <div class="crtw-mt-0.5 crtw-mb-3 crtw-w-full"><!></div>', 1);
function Oe(G, B) {
  if (new.target) return ke({ component: Oe, ...G });
  Re(B, !1);
  const M = () => ce(Le, "$clientPublicStore", Y), [Y, Z] = Ie(), I = i(), ee = i(), R = i(), U = i(), k = i(), D = i(), te = i(), K = i();
  let T = pe(B, "recipientAddress", 12), S = pe(B, "amount", 12), n = pe(B, "options", 12), {
    onChangeCurrency: u,
    onSetMaxAmount: p,
    onBackClicked: V,
    onSendTokens: _,
    title: E,
    chainId: N,
    onScannerClicked: P,
    isNativeCurrecyTransferAllowed: h = !0
  } = n();
  const L = (t) => Math.floor(t * 100) / 100;
  C(() => x(n()), () => {
    r(I, n().balance);
  }), C(() => x(n()), () => {
    r(ee, n().isLoading);
  }), C(() => x(n()), () => {
    r(R, n().isSubmitDisabled);
  }), C(() => x(n()), () => {
    r(U, n().isRecipientAddressValid);
  }), C(() => x(n()), () => {
    r(k, n().isScannerHidden);
  }), C(() => x(n()), () => {
    r(D, n().activeCurrency);
  }), C(() => x(n()), () => {
    r(te, n().nativeSymbol);
  }), C(() => x(n()), () => {
    r(K, n().nativeBalance);
  }), De();
  var O = {
    get recipientAddress() {
      return T();
    },
    set recipientAddress(t) {
      T(t), _e();
    },
    get amount() {
      return S();
    },
    set amount(t) {
      S(t), _e();
    },
    get options() {
      return n();
    },
    set options(t) {
      n(t), _e();
    },
    $set: Be,
    $on: (t, l) => Ee(B, t, l)
  };
  Te();
  var H = ut(), Q = Qe(H);
  {
    let t = z(() => e(k) ? "" : "Scan Passport Id");
    st(Q, {
      get text() {
        return E;
      },
      get description() {
        return e(t);
      }
    });
  }
  var $ = f(Q, 2), re = w($);
  let ne;
  var ae = f(re, 2);
  {
    var ue = (t) => {
      var l = ct(), j = f(w(l)), fe = w(j, !0);
      b(j), b(l), ge(() => me(fe, N)), W(t, l);
    };
    ie(ae, (t) => {
      N && t(ue);
    });
  }
  var X = f(ae, 2), o = f(w(X)), a = w(o);
  {
    var c = (t) => {
      var l = Ke();
      ge((j) => me(l, `${j ?? ""} ${e(te) ?? ""} /`), [
        () => (e(K), de(() => L(+e(K))))
      ]), W(t, l);
    };
    ie(a, (t) => {
      h && t(c);
    });
  }
  var s = f(a);
  b(o), b(X);
  var m = f(X, 2), g = w(m), v = w(g);
  xe(v, {
    name: "recipientAddress",
    type: "text",
    placeholder: "Address 0x...",
    get value() {
      return T();
    },
    set value(t) {
      T(t);
    },
    $$legacy: !0
  });
  var q = f(v, 2);
  {
    var J = (t) => {
      var l = dt();
      W(t, l);
    };
    ie(q, (t) => {
      T() && !e(U) && t(J);
    });
  }
  b(g);
  var A = f(g, 2), d = w(A);
  b(A), b(m);
  var y = f(m, 2), se = w(y);
  {
    let t = z(() => `${e(D)} amount`);
    xe(se, {
      type: "number",
      min: "0",
      step: "0.001",
      get placeholder() {
        return e(t);
      },
      get value() {
        return S();
      },
      set value(l) {
        S(l);
      },
      $$legacy: !0
    });
  }
  var ve = f(se, 2), He = w(ve);
  {
    let t = z(() => +e(I) <= 0);
    be(He, {
      get onClick() {
        return p;
      },
      text: "MAX",
      get disabled() {
        return e(t);
      }
    });
  }
  b(ve);
  var Me = f(ve, 2);
  {
    var Ne = (t) => {
      var l = lt(), j = w(l);
      {
        let fe = z(() => !e(D));
        be(j, {
          get onClick() {
            return u;
          },
          get text() {
            return e(D);
          },
          get disabled() {
            return e(fe);
          }
        });
      }
      b(l), W(t, l);
    };
    ie(Me, (t) => {
      h && t(Ne);
    });
  }
  b(y);
  var Ue = f(y, 2);
  {
    let t = z(() => `Send ${S() || ""} ${e(D)}`);
    be(Ue, {
      get onClick() {
        return _;
      },
      get text() {
        return e(t);
      },
      get isLoading() {
        return e(ee);
      },
      get disabled() {
        return e(R);
      }
    });
  }
  b($);
  var Se = f($, 2), Ve = w(Se);
  it(Ve, {
    get onClick() {
      return V;
    }
  }), b(Se), ge(
    (t) => {
      ne = Fe(re, 1, "crtw-absolute crtw-overflow-hidden crtw-top-0 crtw-bottom-0 crtw-left-0 crtw-right-0 crtw-z-10 crtw-border crtw-border-gray-300 crtw-rounded-lg crtw-backdrop-blur-lg", null, ne, {
        "crtw-hidden": e(k),
        "crtw-z-[-1]": e(k)
      }), me(s, ` ${t ?? ""} $${M(), de(() => M()?.ui_settings.cred_alias || "cred") ?? ""}`), ze(d, "src", ot);
    },
    [
      () => (e(I), de(() => L(+e(I))))
    ]
  ), Ge("click", d, P), W(G, H);
  var je = Pe(O);
  return Z(), je;
}
function vt(G, B) {
  if (new.target) return ke({ component: vt, ...G });
  Re(B, !1);
  const M = () => ce(ye, "$configStore", I), Y = () => ce(Ce, "$providerStore", I), Z = () => ce(Le, "$clientPublicStore", I), [I, ee] = Ie(), R = i(), U = i();
  var k = this && this.__awaiter || function(o, a, c, s) {
    function m(g) {
      return g instanceof c ? g : new c(function(v) {
        v(g);
      });
    }
    return new (c || (c = Promise))(function(g, v) {
      function q(d) {
        try {
          A(s.next(d));
        } catch (y) {
          v(y);
        }
      }
      function J(d) {
        try {
          A(s.throw(d));
        } catch (y) {
          v(y);
        }
      }
      function A(d) {
        d.done ? g(d.value) : m(d.value).then(q, J);
      }
      A((s = s.apply(o, a || [])).next());
    });
  };
  const D = oe(ye), { sendTokens: te, getCREDContract: K, toastAlert: T } = oe(Xe);
  let S = "", n = i(""), u = i(), p = i(""), V = 18, _ = i("-"), E = i(""), N = 18, P = i("-"), h = i(""), L = i(!0), O = i(!1), H, Q, $;
  const re = () => k(void 0, void 0, void 0, function* () {
    const { scanner: o, events: a } = yield tt(rt);
    $ = o, Ye(we.UI_CLOSED, $.close), nt($, a, {
      onCapture: (c) => k(void 0, [c], void 0, function* ({ sub: s }) {
        if (!s)
          return T(Ze(), "failure"), $.close();
        const { address: m } = yield et(s);
        r(n, m), $.close();
      }),
      onCancel: () => r(L, !0),
      onError: (c) => {
        const s = at(c);
        s?.includes("Permission") && alert("In order to scan please allow the current page to access your camera and try again."), r(L, !0);
      }
    }), r(L, !1), yield $.scan();
  }), ne = () => k(void 0, void 0, void 0, function* () {
    const o = e(p) === e(_);
    r(O, !0);
    try {
      const a = F.parseUnits(String(e(u)), o ? V : N), c = yield te({
        address: e(n),
        amount: a,
        instance: o ? H : void 0
      });
      T(`<a href="${We(c.hash)}" target="_blank">Send TX</a> was created`), r(n, ""), r(u, void 0);
      const [s, m] = yield Promise.all([
        H.balanceOf(S),
        Q.provider.getBalance(S)
      ]);
      r(E, F.formatUnits(s, V)), r(h, parseFloat(F.formatUnits(m, N)).toFixed(4)), Ae(we.RECHECK_BALANCE, [c.hash]);
    } catch (a) {
      T(a?.message || a || "An error occurred while sending tokens", "failure"), Ae(we.ERROR, { error: a });
    }
    r(O, !1);
  }), ae = () => k(void 0, void 0, void 0, function* () {
    var o, a, c, s, m, g;
    const v = oe(qe);
    r(n, v?.to || ""), r(u, v?.amount || void 0);
    const { decimals: q, contract: J } = yield K();
    V = q, H = J;
    const A = oe(Ce);
    if (!A) return;
    Q = yield A.getSigner(), S = yield Je();
    const d = yield Promise.all([
      H.symbol(),
      H.balanceOf(S),
      A.getBalance(S),
      fetch("https://chainid.network/chains.json").then((y) => y.json()).then((y) => y.find((se) => String(se.chainId) === D.chainId))
    ]);
    r(_, d[0]), r(E, F.formatUnits(d[1], V)), N = (c = (a = (o = d[3]) === null || o === void 0 ? void 0 : o.nativeCurrency) === null || a === void 0 ? void 0 : a.decimals) !== null && c !== void 0 ? c : 18, r(h, parseFloat(F.formatUnits(d[2], N)).toFixed(4)), r(P, (g = (m = (s = d[3]) === null || s === void 0 ? void 0 : s.nativeCurrency) === null || m === void 0 ? void 0 : m.symbol) !== null && g !== void 0 ? g : "ETH"), r(p, e(_));
  });
  C(() => (M(), Y()), () => {
    M().chainId && Y() && ae();
  }), C(() => e(n), () => {
    r(R, !!F.isAddress(e(n)));
  }), C(
    () => (e(O), e(u), e(R), e(p), e(_), e(E), e(P), e(h)),
    () => {
      r(U, e(O) || !e(u) || !e(R) || e(p) === e(_) && e(u) > +e(E) || e(p) === e(P) && e(u) > +e(h));
    }
  ), De();
  var ue = {
    $set: Be,
    $on: (o, a) => Ee(B, o, a)
  };
  Te();
  {
    let o = z(() => (M(), e(L), e(E), e(R), x(he), x($e), e(p), e(_), e(P), e(u), e(h), e(O), e(U), Z(), de(() => ({
      title: "Send stored value",
      isNativeCurrecyTransferAllowed: M().transferTokens?.nativeCurrency !== !1,
      isScannerHidden: e(L),
      balance: e(E),
      chainId: D.chainId,
      isRecipientAddressValid: e(R),
      onScannerClicked: re,
      onSendTokens: ne,
      onBackClicked: () => he.set($e.WALLET),
      onChangeCurrency: () => e(p) === e(_) ? r(p, e(P)) : r(p, e(_)),
      onSetMaxAmount: () => e(p) === e(_) ? r(u, +e(E)) : r(u, +e(h)),
      isLoading: e(O),
      isSubmitDisabled: e(U),
      credAlias: Z()?.ui_settings.cred_alias,
      activeCurrency: e(p),
      symbol: e(_),
      nativeSymbol: e(P),
      nativeBalance: e(h)
    }))));
    Oe(G, {
      get options() {
        return e(o);
      },
      get recipientAddress() {
        return e(n);
      },
      set recipientAddress(a) {
        r(n, a);
      },
      get amount() {
        return e(u);
      },
      set amount(a) {
        r(u, a);
      },
      $$legacy: !0
    });
  }
  var X = Pe(ue);
  return ee(), X;
}
export {
  vt as default
};
//# sourceMappingURL=SendTokens-DW44yXNz.js.map
