import { defineComponent as y, ref as i, useUser as b, watch as k, parseLink as u, safeJSONParse as g, openBlock as d, createElementBlock as r, createBaseVNode as l, withDirectives as c, vModelText as f, createCommentVNode as v, createVNode as p, unref as w, withCtx as N, Transition as C, createStaticVNode as V, SEA as S, uploadText as E } from "./composables-Ci32s3jE.js";
import { QrLoad as L } from "./components.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" }, B = /* @__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), q = /* @__PURE__ */ l("div", { class: "p-1 ml-1 font-bold" }, "Paste", -1), F = [
  U,
  q
], J = /* @__PURE__ */ V('<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"
}, Q = /* @__PURE__ */ l("div", { class: "i-la-sign-in-alt" }, null, -1), $ = [
  Q
], D = { class: "hidden" }, I = { class: "flex flex-wrap" }, z = /* @__PURE__ */ y({
  __name: "AuthForm",
  setup(M) {
    const a = i("pass"), o = i(), n = i(null), { auth: x } = b();
    function m(t) {
      a.value != t ? a.value = t : a.value = null;
    }
    k(o, async (t) => {
      if (!t) return;
      typeof t == "string" && t.includes("#/auth/") && (t = u(t)), t && typeof t == "string" && t.substring(0, 3) == "SEA" && (n.value = "");
      let e = g(t);
      e != null && e.pub && (e != null && e.priv) ? (x(e), o.value = null) : console.log("No valid pair");
    });
    async function _(t = o.value) {
      typeof t == "string" && t.includes("#/auth/") && (t = u(t)), o.value = await S.decrypt(t, n.value);
    }
    function h(t) {
      var e;
      E((e = t.target) == null ? void 0 : e.files, (s) => o.value = s);
    }
    return (t, e) => (d(), r("div", A, [
      B,
      P,
      l("div", T, [
        l("button", {
          class: "button m-2 cursor-pointer flex items-center",
          onClick: e[0] || (e[0] = (s) => m("key"))
        }, F),
        J
      ]),
      n.value !== null ? (d(), r("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) => _())
        }, $)
      ])) : v("", !0),
      l("div", D, [
        p(w(L), {
          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", I, [
        p(C, { name: "fade" }, {
          default: N(() => [
            a.value == "key" ? c((d(), r("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]
            ]) : v("", !0)
          ]),
          _: 1
        })
      ])
    ]));
  }
});
export {
  z as default
};
//# sourceMappingURL=AuthForm-D7VU7PH2.js.map
