import { defineComponent as h, ref as i, watch as b, parseLink as y, safeJSONParse as k, useUser as g, openBlock as d, createElementBlock as r, createBaseVNode as l, withDirectives as u, vModelText as c, createCommentVNode as f, createVNode as v, unref as w, withCtx as N, Transition as C, createStaticVNode as V, SEA as S, uploadText as E } from "./composables-108ad332.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__ */ h({
  __name: "AuthForm",
  setup(M) {
    const n = i("pass"), o = i(), a = i(null);
    function p(t) {
      n.value != t ? n.value = t : n.value = null;
    }
    b(o, (t) => {
      console.log(t), t && typeof t == "string" && t.substring(0, 3) == "SEA" && (a.value = ""), typeof t == "string" && t.includes("#/auth/") && (t = y(t));
      let e = k(t);
      e != null && e.pub && (e != null && e.priv) ? (x(e), o.value = "") : console.log("No valid pair");
    });
    const { auth: x } = g();
    async function m() {
      o.value = await S.decrypt(o.value, a.value);
    }
    function _(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) => p("key"))
        }, F),
        J
      ]),
      a.value !== null ? (d(), r("form", O, [
        u(l("input", {
          class: "py-1 px-4 m-1 rounded-xl",
          "onUpdate:modelValue": e[1] || (e[1] = (s) => a.value = s),
          autofocus: "",
          type: "text",
          placeholder: "Enter the password"
        }, null, 512), [
          [c, a.value]
        ]),
        l("button", {
          class: "button text-2xl",
          type: "submit",
          onClick: e[2] || (e[2] = (s) => m())
        }, $)
      ])) : f("", !0),
      l("div", D, [
        v(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) => _(s))
        }, null, 544)
      ]),
      l("div", I, [
        v(C, { name: "fade" }, {
          default: N(() => [
            n.value == "key" ? u((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)), [
              [c, o.value]
            ]) : f("", !0)
          ]),
          _: 1
        })
      ])
    ]));
  }
});
export {
  z as default
};
//# sourceMappingURL=AuthForm-140377de.js.map
