import { defineComponent as b, ref as d, watch as y, resolveComponent as k, openBlock as r, createElementBlock as u, createElementVNode as l, withDirectives as c, vModelText as f, createCommentVNode as p, createVNode as v, Transition as g, withCtx as w, createStaticVNode as C } from "vue";
import { parseLink as N, safeJSONParse as V, useUser as E, SEA as S, uploadText as q } from "./composables-5f691338.js";
const A = { class: "flex flex-col my-4 flex-1 items-center bg-light-700 dark-bg-dark-50 rounded-3xl p-4 shadow-lg" }, L = /* @__PURE__ */ l("div", { class: "font-bold text-xl" }, "I already have an account", -1), P = /* @__PURE__ */ l("div", { class: "text-md" }, "Login with a saved key", -1), T = { class: "flex" }, U = /* @__PURE__ */ l("div", { class: "i-la-key text-xl" }, null, -1), B = /* @__PURE__ */ l("div", { class: "p-1 ml-1 font-bold" }, "Paste", -1), F = [
  U,
  B
], J = /* @__PURE__ */ C('<label class="button m-2 cursor-pointer flex items-center" for="qr-input"><div class="i-la-qrcode text-xl"></div><div class="p-1 ml-1 font-bold">QR</div></label><label class="button m-2 cursor-pointer flex items-center" for="json-input"><div class="i-la-file-code text-xl"></div><div class="p-1 ml-1 font-bold">JSON</div></label>', 2), O = {
  key: 0,
  class: "flex"
}, $ = /* @__PURE__ */ l("div", { class: "i-la-sign-in-alt" }, null, -1), D = [
  $
], I = { class: "hidden" }, M = { class: "flex flex-wrap" }, z = /* @__PURE__ */ b({
  __name: "AuthForm",
  setup(Q) {
    const a = d("pass"), o = d(), n = d(null);
    function x(t) {
      a.value != t ? a.value = t : a.value = null;
    }
    y(o, (t) => {
      console.log(t), t && typeof t == "string" && t.substring(0, 3) == "SEA" && (n.value = ""), typeof t == "string" && t.includes("#/auth/") && (t = N(t));
      let e = V(t);
      e != null && e.pub && (e != null && e.priv) ? (m(e), o.value = "") : console.log("No valid pair");
    });
    const { auth: m } = E();
    async function _() {
      o.value = await S.decrypt(o.value, n.value);
    }
    function h(t) {
      var e;
      q((e = t.target) == null ? void 0 : e.files, (i) => o.value = i);
    }
    return (t, e) => {
      const i = k("qr-load");
      return r(), u("div", A, [
        L,
        P,
        l("div", T, [
          l("button", {
            class: "button m-2 cursor-pointer flex items-center",
            onClick: e[0] || (e[0] = (s) => x("key"))
          }, F),
          J
        ]),
        n.value !== null ? (r(), u("form", O, [
          c(l("input", {
            class: "py-1 px-4 m-1 rounded-xl",
            "onUpdate:modelValue": e[1] || (e[1] = (s) => n.value = s),
            autofocus: "",
            type: "text",
            placeholder: "Enter the password"
          }, null, 512), [
            [f, n.value]
          ]),
          l("button", {
            class: "button text-2xl",
            type: "submit",
            onClick: e[2] || (e[2] = (s) => _())
          }, D)
        ])) : p("", !0),
        l("div", I, [
          v(i, {
            onLoaded: e[3] || (e[3] = (s) => o.value = s)
          }),
          l("input", {
            id: "json-input",
            ref: "file",
            tabindex: "-1",
            type: "file",
            accept: "application/json",
            onChange: e[4] || (e[4] = (s) => h(s))
          }, null, 544)
        ]),
        l("div", M, [
          v(g, { name: "fade" }, {
            default: w(() => [
              a.value == "key" ? c((r(), u("textarea", {
                class: "p-2 text-sm flex-1 w-full dark-bg-dark-200",
                key: "text",
                "onUpdate:modelValue": e[5] || (e[5] = (s) => o.value = s),
                rows: "6",
                cols: "40",
                placeholder: "Paste your key pair here"
              }, null, 512)), [
                [f, o.value]
              ]) : p("", !0)
            ]),
            _: 1
          })
        ])
      ]);
    };
  }
});
export {
  z as default
};
//# sourceMappingURL=AuthForm-32b06490.js.map
