import { c as $e, p as ae, h as Ae, f as q, i as W, k as Fe, r as se, o as le, s as Ue, e as je, b as z, d as xe, u as he, n as ke, t as Ge } from "./AssetItem-ufNA-vj9.js";
import { t as Te, n as g, D as r, m as i, v as S, o as Ee, p as Ke, E as e, F as O, z as v, w, x as m, y as ie, C as X, r as Be, X as Re, l as oe, I as me, K as We, bx as Xe, W as qe, L as Je, by as _e, bz as ge, N as be, O as Se, bA as Qe, J as ye, P as ce, bB as Ye, bC as Ze } from "./index-DRgrWhNH.js";
import { c as et, C as tt, s as rt, g as nt } from "./index-D5XO39uY.js";
import { C as at } from "./ContentHeader-B8i-EqEU.js";
import { B as st } from "./ButtonBack-De1k3L47.js";
import { B as de } from "./Button-Dvas4qfY.js";
import { I as Ce } from "./Input-BDP5L1Bw.js";
import { S as it } from "./scanner-Bm3Pvpfs.js";
import { N as ot } from "./constants-ByF0HyKB.js";
var ct = q('<div>ChainId: <span class="crtw-font-bold"> </span></div>'), dt = q('<label class="crtw-text-[10px] crtw-text-warningTextColor cpui-send-tokens-validation-message" for="recipientAddress">Provided address is not valid.</label>'), lt = q('<div class="crtw-ml-2.5 crtw-w-16 crtw-min-w-16"><!></div>'), ut = q('<!> <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 Ie(H, C) {
  if (new.target) return $e({ component: Ie, ...H });
  Te(C, !1);
  const E = () => le(Re, "$clientPublicStore", F), [F, U] = ke(), I = i(), $ = i(), D = i(), A = i(), x = i(), u = i(), c = i(), d = i();
  let f = ae(C, "recipientAddress", 12), p = ae(C, "amount", 12), n = ae(C, "options", 12), {
    onChangeCurrency: y,
    onSetMaxAmount: B,
    onBackClicked: h,
    onSendTokens: k,
    title: J,
    chainId: j,
    onScannerClicked: Q,
    isNativeCurrecyTransferAllowed: G = !0
  } = n();
  const K = (t) => Math.floor(t * 100) / 100;
  g(() => S(n()), () => {
    r(I, n().balance);
  }), g(() => S(n()), () => {
    r($, n().isLoading);
  }), g(() => S(n()), () => {
    r(D, n().isSubmitDisabled);
  }), g(() => S(n()), () => {
    r(A, n().isRecipientAddressValid);
  }), g(() => S(n()), () => {
    r(x, n().isScannerHidden);
  }), g(() => S(n()), () => {
    r(u, n().activeCurrency);
  }), g(() => S(n()), () => {
    r(c, n().nativeSymbol);
  }), g(() => S(n()), () => {
    r(d, n().nativeBalance);
  }), Ee();
  var s = {
    get recipientAddress() {
      return f();
    },
    set recipientAddress(t) {
      f(t), oe();
    },
    get amount() {
      return p();
    },
    set amount(t) {
      p(t), oe();
    },
    get options() {
      return n();
    },
    set options(t) {
      n(t), oe();
    },
    $set: he,
    $on: (t, o) => xe(C, t, o)
  };
  Ae();
  var a = ut(), _ = Ke(a);
  {
    let t = O(() => e(x) ? "" : "Scan Passport Id");
    at(_, {
      get text() {
        return J;
      },
      get description() {
        return e(t);
      }
    });
  }
  var l = v(_, 2), L = w(l);
  let T;
  var R = v(L, 2);
  {
    var Y = (t) => {
      var o = ct(), P = v(w(o)), ne = w(P, !0);
      m(P), m(o), ie(() => se(ne, j)), z(t, o);
    };
    W(R, (t) => {
      j && t(Y);
    });
  }
  var M = v(R, 2), N = v(w(M)), b = w(N);
  {
    var V = (t) => {
      var o = Ge();
      ie((P) => se(o, `${P ?? ""} ${e(c) ?? ""} /`), [
        () => (e(d), X(() => K(+e(d))))
      ]), z(t, o);
    };
    W(b, (t) => {
      G && t(V);
    });
  }
  var De = v(b);
  m(N), m(M);
  var Z = v(M, 2), ee = w(Z), ue = w(ee);
  Ce(ue, {
    name: "recipientAddress",
    type: "text",
    placeholder: "Address 0x...",
    get value() {
      return f();
    },
    set value(t) {
      f(t);
    },
    $$legacy: !0
  });
  var Le = v(ue, 2);
  {
    var Ne = (t) => {
      var o = dt();
      z(t, o);
    };
    W(Le, (t) => {
      f() && !e(A) && t(Ne);
    });
  }
  m(ee);
  var ve = v(ee, 2), pe = w(ve);
  m(ve), m(Z);
  var te = v(Z, 2), fe = w(te);
  {
    let t = O(() => `${e(u)} amount`);
    Ce(fe, {
      type: "number",
      min: "0",
      step: "0.001",
      get placeholder() {
        return e(t);
      },
      get value() {
        return p();
      },
      set value(o) {
        p(o);
      },
      $$legacy: !0
    });
  }
  var re = v(fe, 2), Pe = w(re);
  {
    let t = O(() => +e(I) <= 0);
    de(Pe, {
      get onClick() {
        return B;
      },
      text: "MAX",
      get disabled() {
        return e(t);
      }
    });
  }
  m(re);
  var Oe = v(re, 2);
  {
    var He = (t) => {
      var o = lt(), P = w(o);
      {
        let ne = O(() => !e(u));
        de(P, {
          get onClick() {
            return y;
          },
          get text() {
            return e(u);
          },
          get disabled() {
            return e(ne);
          }
        });
      }
      m(o), z(t, o);
    };
    W(Oe, (t) => {
      G && t(He);
    });
  }
  m(te);
  var Me = v(te, 2);
  {
    let t = O(() => `Send ${p() || ""} ${e(u)}`);
    de(Me, {
      get onClick() {
        return k;
      },
      get text() {
        return e(t);
      },
      get isLoading() {
        return e($);
      },
      get disabled() {
        return e(D);
      }
    });
  }
  m(l);
  var we = v(l, 2), Ve = w(we);
  st(Ve, {
    get onClick() {
      return h;
    }
  }), m(we), ie(
    (t) => {
      T = Fe(L, 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, T, {
        "crtw-hidden": e(x),
        "crtw-z-[-1]": e(x)
      }), se(De, ` ${t ?? ""} $${E(), X(() => E()?.ui_settings.cred_alias || "cred") ?? ""}`), Ue(pe, "src", it);
    },
    [
      () => (e(I), X(() => K(+e(I))))
    ]
  ), je("click", pe, Q), z(H, a);
  var ze = Be(s);
  return U(), ze;
}
function vt(H, C) {
  if (new.target) return $e({ component: vt, ...H });
  Te(C, !1);
  const E = () => le(qe, "$configStore", U), F = () => le(Re, "$clientPublicStore", U), [U, I] = ke(), $ = i(), D = i();
  var A = this && this.__awaiter || function(s, a, _, l) {
    function L(T) {
      return T instanceof _ ? T : new _(function(R) {
        R(T);
      });
    }
    return new (_ || (_ = Promise))(function(T, R) {
      function Y(b) {
        try {
          N(l.next(b));
        } catch (V) {
          R(V);
        }
      }
      function M(b) {
        try {
          N(l.throw(b));
        } catch (V) {
          R(V);
        }
      }
      function N(b) {
        b.done ? T(b.value) : L(b.value).then(Y, M);
      }
      N((l = l.apply(s, a || [])).next());
    });
  };
  const { toastAlert: x } = me(We);
  let u = i(""), c = i(), d = i("");
  const f = "CRED";
  let p = i("");
  const n = "SUI";
  let y = i(""), B = i(!0), h = i(!1), k;
  const J = () => A(void 0, void 0, void 0, function* () {
    const { scanner: s, events: a } = yield et(tt);
    k = s, Ye(ce.UI_CLOSED, k.close), yield k.scan(), rt(k, a, {
      onCapture: (_) => A(void 0, [_], void 0, function* ({ sub: l }) {
        if (!l)
          return x(ot(), "failure"), k.close();
        const { address: L } = yield Ze(l);
        r(u, L), k.close();
      }),
      onCancel: () => r(B, !0),
      onError: (_) => {
        const l = nt(_);
        l?.includes("Permission") && alert("In order to scan please allow the current page to access your camera and try again."), r(B, !0);
      }
    }), r(B, !1);
  }), j = () => A(void 0, void 0, void 0, function* () {
    r(h, !0);
    const s = e(d) === n;
    try {
      yield Qe({
        address: e(u),
        amount: e(c),
        isSuiNativeCoinTransfer: s
      }), x("Send operation was completed."), r(u, ""), r(c, 0), setTimeout(
        () => A(void 0, void 0, void 0, function* () {
          r(p, yield _e()), r(y, yield ge()), ye(ce.RECHECK_BALANCE);
        }),
        1e3
      );
    } catch (a) {
      console.log(a), ye(ce.ERROR, { error: a }), x(a?.message || a || "An error occurred while sending tokens", "failure");
    }
    r(h, !1);
  }), Q = () => A(void 0, void 0, void 0, function* () {
    const s = me(Je);
    r(u, s?.to || ""), r(c, s?.amount || void 0), r(p, yield _e()), r(y, parseFloat(yield ge()).toFixed(4)), r(d, f);
  });
  g(() => E(), () => {
    E().suiNetwork && Q();
  }), g(() => e(u), () => {
    r($, Xe(e(u)));
  }), g(
    () => (e(h), e(c), e($), e(d), e(p), e(y)),
    () => {
      r(D, e(h) || !e(c) || !e($) || e(d) === f && e(c) > +e(p) || e(d) === n && e(c) > +e(y));
    }
  ), Ee();
  var G = {
    $set: he,
    $on: (s, a) => xe(C, s, a)
  };
  Ae();
  {
    let s = O(() => (e(B), e(p), e($), S(be), S(Se), e(d), e(c), e(y), e(h), e(D), F(), E(), X(() => ({
      title: "Send stored value",
      isScannerHidden: e(B),
      balance: e(p),
      isRecipientAddressValid: e($),
      onScannerClicked: J,
      onSendTokens: j,
      onBackClicked: () => be.set(Se.WALLET),
      onChangeCurrency: () => e(d) === f ? r(d, n) : r(d, f),
      onSetMaxAmount: () => e(d) === f ? r(c, +e(p)) : r(c, +e(y)),
      isLoading: e(h),
      isSubmitDisabled: e(D),
      credAlias: F().ui_settings.cred_alias,
      activeCurrency: e(d),
      symbol: f,
      nativeSymbol: n,
      isNativeCurrecyTransferAllowed: E().transferTokens?.nativeCurrency !== !1,
      nativeBalance: e(y)
    }))));
    Ie(H, {
      get options() {
        return e(s);
      },
      get recipientAddress() {
        return e(u);
      },
      set recipientAddress(a) {
        r(u, a);
      },
      get amount() {
        return e(c);
      },
      set amount(a) {
        r(c, a);
      },
      $$legacy: !0
    });
  }
  var K = Be(G);
  return I(), K;
}
export {
  vt as default
};
//# sourceMappingURL=SendTokens-IVvYe1T_.js.map
