import { c as O, p as V, h as k, f as C, i as j, k as G, b as g, d as P, u as L } from "./AssetItem-BxjLUzNd.js";
import { a as $ } from "./index-client-C5PXnhDi.js";
import { t as R, n as z, D as I, m as x, v as B, o as M, p as q, z as h, w as T, E as y, x as A, y as H, r as D, l as K, J as b, by as Q, L as Y, bC as F, O as E, P as W, V as X, I as Z, bR as ee, bD as te, bw as _, bS as ae, bT as se, bU as ne, bE as re, bV as oe } from "./index-BBXAtvZr.js";
import { c as ce, s as ie, S as le, g as de } from "./index-D5XO39uY.js";
import { C as ue } from "./ContentHeader-CNIXuMji.js";
import { L as fe } from "./Loader-Byv7_nwE.js";
var pe = C('<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 = C('<!> <div class="crtw-w-full"><!> <div id="cpuiScanner" style="background-color: rgb(238, 238, 238)"></div></div>', 1);
function N(i, r) {
  if (new.target) return O({ component: N, ...i });
  R(r, !1);
  const o = x();
  let l = V(r, "options", 12);
  z(() => B(l()), () => {
    I(o, l().isScannerLoaded);
  }), M();
  var d = {
    get options() {
      return l();
    },
    set options(e) {
      l(e), K();
    },
    $set: L,
    $on: (e, s) => P(r, e, s)
  };
  k();
  var p = _e(), S = q(p);
  ue(S, { text: "Scan PassScan Code" });
  var v = h(S, 2), n = T(v);
  {
    var t = (e) => {
      var s = pe(), f = T(s);
      fe(f, {}), A(s), g(e, s);
    };
    j(n, (e) => {
      y(o) || e(t);
    });
  }
  var c = h(n, 2);
  let a;
  return A(v), H(() => a = G(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), D(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(Q)}`
      },
      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 });
  R(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 U(u) {
        try {
          w(a.throw(u));
        } catch (m) {
          f(m);
        }
      }
      function w(u) {
        u.done ? s(u.value) : e(u.value).then(J, U);
      }
      w((a = a.apply(n, t || [])).next());
    });
  };
  const { close: l } = b(Y);
  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(Z);
        [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);
    }
  });
  $(() => o(void 0, void 0, void 0, function* () {
    const { scanner: n, events: t } = yield ce(le);
    d = n, F(W.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.");
      }
    }), I(p, !0), yield d.scan({ isCloseButton: !1 });
  }));
  var v = {
    $set: L,
    $on: (n, t) => P(r, n, t)
  };
  k();
  {
    let n = X(() => ({ isScannerLoaded: y(p) }));
    N(i, {
      get options() {
        return y(n);
      }
    });
  }
  return D(v);
}
export {
  ye as default
};
//# sourceMappingURL=Scanner-ieRWiYQ6.js.map
