import { c as ke, p as pe, h as Te, f as le, i as ie, k as je, o as me, s as ze, e as Ge, b as J, d as Ee, u as Be, t as Ke } from "./AssetItem-CFsdMEwW.js";
import { v as Ie, o as h, G as r, m as i, w as x, p as Re, r as Qe, I as e, Y as z, A as f, x as _, y as b, z as ge, D as ce, F as de, t as De, E as Pe, a4 as Le, n as we, M as oe, L as ye, O as Xe, a2 as j, a0 as he, Q as Ye, a1 as qe, S as Ce, T as $e, bI as Je, N as Ae, P as _e, bJ as We, bK as Ze, bL as et } from "./index-BxjwuJ6T.js";
import { c as tt, C as rt, s as nt, g as at } from "./index-BCkrxVnM.js";
import { C as st } from "./ContentHeader-IUWmor6Y.js";
import { B as it } from "./ButtonBack-TLkmy8GZ.js";
import { B as be } from "./Button-S2OwL6nP.js";
import { I as xe } from "./Input-BtyPpztB.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 });
  Ie(B, !1);
  const H = () => de(Le, "$clientPublicStore", W), [W, Z] = Pe(), 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: F,
    onSendTokens: w,
    title: E,
    chainId: M,
    onScannerClicked: P,
    isNativeCurrecyTransferAllowed: C = !0
  } = n();
  const L = (t) => Math.floor(t * 100) / 100;
  h(() => x(n()), () => {
    r(I, n().balance);
  }), h(() => x(n()), () => {
    r(ee, n().isLoading);
  }), h(() => x(n()), () => {
    r(R, n().isSubmitDisabled);
  }), h(() => x(n()), () => {
    r(U, n().isRecipientAddressValid);
  }), h(() => x(n()), () => {
    r(k, n().isScannerHidden);
  }), h(() => x(n()), () => {
    r(D, n().activeCurrency);
  }), h(() => x(n()), () => {
    r(te, n().nativeSymbol);
  }), h(() => x(n()), () => {
    r(K, n().nativeBalance);
  }), Re();
  var O = {
    get recipientAddress() {
      return T();
    },
    set recipientAddress(t) {
      T(t), we();
    },
    get amount() {
      return S();
    },
    set amount(t) {
      S(t), we();
    },
    get options() {
      return n();
    },
    set options(t) {
      n(t), we();
    },
    $set: Be,
    $on: (t, l) => Ee(B, t, l)
  };
  Te();
  var N = ut(), Q = Qe(N);
  {
    let t = z(() => e(k) ? "" : "Scan Passport Id");
    st(Q, {
      get text() {
        return E;
      },
      get description() {
        return e(t);
      }
    });
  }
  var $ = f(Q, 2), re = _($);
  let ne;
  var ae = f(re, 2);
  {
    var ue = (t) => {
      var l = ct(), V = f(_(l)), fe = _(V, !0);
      b(V), b(l), ge(() => me(fe, M)), J(t, l);
    };
    ie(ae, (t) => {
      M && t(ue);
    });
  }
  var X = f(ae, 2), o = f(_(X)), a = _(o);
  {
    var c = (t) => {
      var l = Ke();
      ge((V) => me(l, `${V ?? ""} ${e(te) ?? ""} /`), [
        () => (e(K), ce(() => L(+e(K))))
      ]), J(t, l);
    };
    ie(a, (t) => {
      C && t(c);
    });
  }
  var s = f(a);
  b(o), b(X);
  var m = f(X, 2), g = _(m), v = _(g);
  xe(v, {
    name: "recipientAddress",
    type: "text",
    placeholder: "Address 0x...",
    get value() {
      return T();
    },
    set value(t) {
      T(t);
    },
    $$legacy: !0
  });
  var Y = f(v, 2);
  {
    var q = (t) => {
      var l = dt();
      J(t, l);
    };
    ie(Y, (t) => {
      T() && !e(U) && t(q);
    });
  }
  b(g);
  var A = f(g, 2), d = _(A);
  b(A), b(m);
  var y = f(m, 2), se = _(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), Ne = _(ve);
  {
    let t = z(() => +e(I) <= 0);
    be(Ne, {
      get onClick() {
        return p;
      },
      text: "MAX",
      get disabled() {
        return e(t);
      }
    });
  }
  b(ve);
  var He = f(ve, 2);
  {
    var Me = (t) => {
      var l = lt(), V = _(l);
      {
        let fe = z(() => !e(D));
        be(V, {
          get onClick() {
            return u;
          },
          get text() {
            return e(D);
          },
          get disabled() {
            return e(fe);
          }
        });
      }
      b(l), J(t, l);
    };
    ie(He, (t) => {
      C && t(Me);
    });
  }
  b(y);
  var Ue = f(y, 2);
  {
    let t = z(() => `Send ${S() || ""} ${e(D)}`);
    be(Ue, {
      get onClick() {
        return w;
      },
      get text() {
        return e(t);
      },
      get isLoading() {
        return e(ee);
      },
      get disabled() {
        return e(R);
      }
    });
  }
  b($);
  var Se = f($, 2), Fe = _(Se);
  it(Fe, {
    get onClick() {
      return F;
    }
  }), b(Se), ge(
    (t) => {
      ne = je(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 ?? ""} $${H(), ce(() => H()?.ui_settings.cred_alias || "cred") ?? ""}`), ze(d, "src", ot);
    },
    [
      () => (e(I), ce(() => L(+e(I))))
    ]
  ), Ge("click", d, P), J(G, N);
  var Ve = De(O);
  return Z(), Ve;
}
function vt(G, B) {
  if (new.target) return ke({ component: vt, ...G });
  Ie(B, !1);
  const H = () => de(ye, "$configStore", I), W = () => de(he, "$providerStore", I), Z = () => de(Le, "$clientPublicStore", I), [I, ee] = Pe(), 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 Y(d) {
        try {
          A(s.next(d));
        } catch (y) {
          v(y);
        }
      }
      function q(d) {
        try {
          A(s.throw(d));
        } catch (y) {
          v(y);
        }
      }
      function A(d) {
        d.done ? g(d.value) : m(d.value).then(Y, q);
      }
      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(""), F = 18, w = i("-"), E = i(""), M = 18, P = i("-"), C = i(""), L = i(!0), O = i(!1), N, Q, $;
  const re = () => k(void 0, void 0, void 0, function* () {
    const { scanner: o, events: a } = yield tt(rt);
    $ = o, We(_e.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(w);
    r(O, !0);
    try {
      const a = j.parseUnits(String(e(u)), o ? F : M), c = yield te({
        address: e(n),
        amount: a,
        instance: o ? N : void 0
      });
      T(`<a href="${Je(c.hash)}" target="_blank">Send TX</a> was created`), r(n, ""), r(u, void 0);
      const [s, m] = yield Promise.all([
        N.balanceOf(S),
        Q.provider.getBalance(S)
      ]);
      r(E, j.formatUnits(s, F)), r(C, parseFloat(j.formatUnits(m, M)).toFixed(4)), Ae(_e.RECHECK_BALANCE, [c.hash]);
    } catch (a) {
      T(a?.message || a || "An error occurred while sending tokens", "failure"), Ae(_e.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(Ye);
    r(n, v?.to || ""), r(u, v?.amount || void 0);
    const { decimals: Y, contract: q } = yield K();
    F = Y, N = q;
    const A = oe(he);
    if (!A) return;
    Q = yield A.getSigner(), S = yield qe();
    const d = yield Promise.all([
      N.symbol(),
      N.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(w, d[0]), r(E, j.formatUnits(d[1], F)), M = (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(C, parseFloat(j.formatUnits(d[2], M)).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(w));
  });
  h(() => (H(), W()), () => {
    H().chainId && W() && ae();
  }), h(() => e(n), () => {
    r(R, !!j.isAddress(e(n)));
  }), h(
    () => (e(O), e(u), e(R), e(p), e(w), e(E), e(P), e(C)),
    () => {
      r(U, e(O) || !e(u) || !e(R) || e(p) === e(w) && e(u) > +e(E) || e(p) === e(P) && e(u) > +e(C));
    }
  ), Re();
  var ue = {
    $set: Be,
    $on: (o, a) => Ee(B, o, a)
  };
  Te();
  {
    let o = z(() => (H(), e(L), e(E), e(R), x(Ce), x($e), e(p), e(w), e(P), e(u), e(C), e(O), e(U), Z(), ce(() => ({
      title: "Send stored value",
      isNativeCurrecyTransferAllowed: H().transferTokens?.nativeCurrency !== !1,
      isScannerHidden: e(L),
      balance: e(E),
      chainId: D.chainId,
      isRecipientAddressValid: e(R),
      onScannerClicked: re,
      onSendTokens: ne,
      onBackClicked: () => Ce.set($e.WALLET),
      onChangeCurrency: () => e(p) === e(w) ? r(p, e(P)) : r(p, e(w)),
      onSetMaxAmount: () => e(p) === e(w) ? r(u, +e(E)) : r(u, +e(C)),
      isLoading: e(O),
      isSubmitDisabled: e(U),
      credAlias: Z()?.ui_settings.cred_alias,
      activeCurrency: e(p),
      symbol: e(w),
      nativeSymbol: e(P),
      nativeBalance: e(C)
    }))));
    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 = De(ue);
  return ee(), X;
}
export {
  vt as default
};
//# sourceMappingURL=SendTokens-nzOBlkTN.js.map
