import { c as O, p as U, h as k, f as P, i as $, k as j, b as g, d as C, u as L } from "./AssetItem-CFsdMEwW.js";
import { a as B } from "./index-client-DJaMHbvZ.js";
import { v as I, o as M, G as R, m as x, w as Y, p as z, r as K, A as h, x as A, I as y, y as T, z as V, t as N, n as q, M as b, bD as H, O as Q, bJ as F, S as E, P as X, Y as Z, L as W, bX as ee, bK as te, bB as _, bY as ae, bZ as se, b_ as ne, bL as re, b$ as oe } from "./index-BxjwuJ6T.js";
import { c as ce, s as ie, S as le, g as de } from "./index-BCkrxVnM.js";
import { C as ue } from "./ContentHeader-IUWmor6Y.js";
import { L as fe } from "./Loader-BMEbL3GG.js";
var pe = P('<div class="crtw-w-full crtw-h-64 crtw-rounded-[10px] crtw-flex crtw-items-center crtw-justify-center" style="background-color: rgb(238, 238, 238)"><!></div>'), _e = P('<!> <div class="crtw-w-full"><!> <div id="cpuiScanner" style="background-color: rgb(238, 238, 238)"></div></div>', 1);
function D(i, r) {
  if (new.target) return O({ component: D, ...i });
  I(r, !1);
  const o = x();
  let l = U(r, "options", 12);
  M(() => Y(l()), () => {
    R(o, l().isScannerLoaded);
  }), z();
  var d = {
    get options() {
      return l();
    },
    set options(e) {
      l(e), q();
    },
    $set: L,
    $on: (e, s) => C(r, e, s)
  };
  k();
  var p = _e(), S = K(p);
  ue(S, { text: "Scan PassScan Code" });
  var v = h(S, 2), n = A(v);
  {
    var t = (e) => {
      var s = pe(), f = A(s);
      fe(f, {}), T(s), g(e, s);
    };
    $(n, (e) => {
      y(o) || e(t);
    });
  }
  var c = h(n, 2);
  let a;
  return T(v), V(() => a = j(c, 1, "crtw-w-full crtw-h-auto crtw-rounded-lg crtw-flex crtw-items-center crtw-justify-center", null, a, { "crtw-hidden": !y(o) })), g(i, p), N(d);
}
const Se = async (i, r) => {
  const o = await fetch(
    `https://api.staging.credenza3.com/keyval/key/${i}?client_id=${r}`,
    {
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${b(H)}`
      },
      method: "GET"
    }
  );
  if (!o.ok) throw new Error("Failed to get key value");
  return await o.json();
}, ve = async (i, r) => {
  const l = (await Se(i, r)).items[0].val;
  return [JSON.parse(l).scanType, l];
};
function ye(i, r) {
  if (new.target) return O({ component: ye, ...i });
  I(r, !1);
  var o = this && this.__awaiter || function(n, t, c, a) {
    function e(s) {
      return s instanceof c ? s : new c(function(f) {
        f(s);
      });
    }
    return new (c || (c = Promise))(function(s, f) {
      function J(u) {
        try {
          w(a.next(u));
        } catch (m) {
          f(m);
        }
      }
      function G(u) {
        try {
          w(a.throw(u));
        } catch (m) {
          f(m);
        }
      }
      function w(u) {
        u.done ? s(u.value) : e(u.value).then(J, G);
      }
      w((a = a.apply(n, t || [])).next());
    });
  };
  const { close: l } = b(Q);
  let d, p = x(!1);
  const S = (n) => o(void 0, [n], void 0, function* ({ message: t, sub: c, scanType: a }) {
    if (!a)
      try {
        const e = b(W);
        [a, t] = yield ve(t, e.clientId);
      } catch {
        return ee(te(t), "failure"), d.close();
      }
    switch (d.close(), a) {
      case _.PASSPORT_ID_PASS:
      case _.PASSPORT_ID: {
        const e = JSON.parse(t), { address: s } = yield re(c);
        oe({
          userAddress: s,
          amount: e?.amount
        });
        break;
      }
      case _.TOKENS_PURCHASE: {
        ne(JSON.parse(t));
        break;
      }
      case _.AIR_DROP_ASSET: {
        yield se(JSON.parse(t));
        break;
      }
      case _.REQUEST_LOYALTY_POINTS: {
        yield ae(JSON.parse(t));
        break;
      }
      default:
        l(), E.set(null);
    }
  });
  B(() => o(void 0, void 0, void 0, function* () {
    const { scanner: n, events: t } = yield ce(le);
    d = n, F(X.UI_CLOSED, () => {
      d.close(), E.set(null);
    }), ie(d, t, {
      onCapture: S,
      onError: (c) => {
        const a = de(c);
        a?.includes("Permission") && alert("In order to scan please allow the current page to access your camera and try again.");
      }
    }), R(p, !0), yield d.scan({ isCloseButton: !1 });
  }));
  var v = {
    $set: L,
    $on: (n, t) => C(r, n, t)
  };
  k();
  {
    let n = Z(() => ({ isScannerLoaded: y(p) }));
    D(i, {
      get options() {
        return y(n);
      }
    });
  }
  return N(v);
}
export {
  ye as default
};
//# sourceMappingURL=Scanner-H_lPZirt.js.map
