import { defineComponent as k, ref as i, watch as g, createElementBlock as r, openBlock as u, createElementVNode as l, createCommentVNode as d, createStaticVNode as w, withDirectives as f, vModelText as v, createVNode as p, unref as N, Transition as C, withCtx as V } from "vue";
import { useUser as E, parseLink as x, safeJSONParse as S, SEA as L, uploadText as h } from "./composables-BAZQlC3e.js";
import { QrLoad as A } from "./components.js";
const P = { class: "flex flex-col my-4 flex-1 items-center bg-light-700 dark-bg-dark-50 rounded-3xl p-4 shadow-lg" }, T = { class: "flex" }, U = {
  key: 0,
  class: "flex"
}, q = { class: "hidden" }, B = { class: "flex flex-wrap" }, $ = /* @__PURE__ */ k({
  __name: "AuthForm",
  setup(F) {
    const a = i("pass"), o = i(), n = i(null), { auth: c } = E();
    function m(t) {
      a.value != t ? a.value = t : a.value = null;
    }
    g(o, async (t) => {
      if (!t) return;
      typeof t == "string" && t.includes("#/auth/") && (t = x(t)), t && typeof t == "string" && t.substring(0, 3) == "SEA" && (n.value = "");
      let e = S(t);
      e != null && e.pub && (e != null && e.priv) ? (c(e), o.value = null) : console.log("No valid pair");
    });
    async function y(t = o.value) {
      typeof t == "string" && t.includes("#/auth/") && (t = x(t)), o.value = await L.decrypt(t, n.value);
    }
    function b(t) {
      var e;
      h((e = t.target) == null ? void 0 : e.files, (s) => o.value = s);
    }
    return (t, e) => (u(), r("div", P, [
      e[9] || (e[9] = l("div", { class: "font-bold text-xl" }, "I already have an account", -1)),
      e[10] || (e[10] = l("div", { class: "text-md" }, "Login with a saved key", -1)),
      l("div", T, [
        l("button", {
          class: "button m-2 cursor-pointer flex items-center",
          onClick: e[0] || (e[0] = (s) => m("key"))
        }, e[6] || (e[6] = [
          l("div", { class: "i-la-key text-xl" }, null, -1),
          l("div", { class: "p-1 ml-1 font-bold" }, "Paste", -1)
        ])),
        e[7] || (e[7] = w('<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))
      ]),
      n.value !== null ? (u(), r("form", U, [
        f(l("input", {
          class: "py-1 px-4 m-1 rounded-xl",
          "onUpdate:modelValue": e[1] || (e[1] = (s) => n.value = s),
          autofocus: "",
          autocomplete: "current-password",
          type: "text",
          placeholder: "Enter the password"
        }, null, 512), [
          [v, n.value]
        ]),
        l("button", {
          class: "button text-2xl",
          type: "submit",
          onClick: e[2] || (e[2] = (s) => y())
        }, e[8] || (e[8] = [
          l("div", { class: "i-la-sign-in-alt" }, null, -1)
        ]))
      ])) : d("", !0),
      l("div", q, [
        p(N(A), {
          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) => b(s))
        }, null, 544)
      ]),
      l("div", B, [
        p(C, { name: "fade" }, {
          default: V(() => [
            a.value == "key" ? f((u(), 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)), [
              [v, o.value]
            ]) : d("", !0)
          ]),
          _: 1
        })
      ])
    ]));
  }
});
export {
  $ as default
};
//# sourceMappingURL=AuthForm-DKP-LrcT.js.map
