import { defineComponent as F, ref as h, computed as N, useClipboard as Q, useShare as R, openBlock as a, createElementBlock as c, createBaseVNode as e, toDisplayString as p, unref as n, prettyBytes as T, withModifiers as V, createVNode as y, withCtx as C, createCommentVNode as _, Transition as D, createBlock as S, Fragment as E, renderList as q, uploadTorrent as G, useGun as M, useUser as j, watch as z } from "./composables-Ci32s3jE.js";
import { QrShow as A, FileCard as I, UiLayer as J } from "./components.js";
const K = { class: "flex flex-col gap-4 p-4 break-all" }, O = {
  key: 0,
  class: "p-2 flex flex-wrap gap-2 bg-light-100 dark-bg-dark-400 rounded cursor-pointer items-center"
}, P = /* @__PURE__ */ e("div", { class: "font-bold" }, "Share a file", -1), W = /* @__PURE__ */ e("div", { class: "font-bold" }, "Sharing a file:", -1), X = { class: "text-md max-w-55ch" }, Y = { class: "flex-1 font-mono text-xs min-w-10" }, Z = { class: "p-0" }, ee = { class: "flex flex-wrap gap-2 p-4 items-start" }, te = {
  key: 0,
  class: "flex flex-col gap-2"
}, se = /* @__PURE__ */ e("div", { class: "text-xl" }, "Sharing the torrent", -1), oe = { class: "font-mono text-sm" }, le = ["href"], ae = /* @__PURE__ */ e("div", { class: "i-la-link" }, null, -1), ne = /* @__PURE__ */ e("div", { class: "p-0" }, "Download URL", -1), ie = [
  ae,
  ne
], re = /* @__PURE__ */ e("div", { class: "i-la-copy" }, null, -1), de = { class: "p-0" }, ue = /* @__PURE__ */ e("div", { class: "i-la-share" }, null, -1), ce = /* @__PURE__ */ e("div", { class: "p-0" }, " Share", -1), pe = [
  ue,
  ce
], ve = /* @__PURE__ */ e("div", { class: "i-la-qrcode" }, null, -1), fe = { class: "p-0" }, he = /* @__PURE__ */ e("div", { class: "i-la-file" }, null, -1), _e = { class: "p-0" }, be = /* @__PURE__ */ F({
  __name: "TorrentUpload",
  emits: ["uploaded"],
  setup(me, { emit: $ }) {
    const H = $, s = h();
    h();
    const v = h(!1), m = h(!1), g = h(!1);
    function U(o) {
      var i;
      const { torrent: t } = G((i = o == null ? void 0 : o.target) == null ? void 0 : i.files);
      M();
      const { user: d } = j();
      z(t, async (u) => {
        s.value = u, v.value = !0;
        const l = {
          infoHash: u.infoHash,
          length: u.length,
          name: u.name,
          author: d.pub
        };
        H("uploaded", l);
      });
    }
    const f = N(() => {
      var t, d, i;
      if (!((t = s.value) != null && t.infoHash)) return "";
      let o = new URL((d = window == null ? void 0 : window.location) == null ? void 0 : d.href);
      return `${o.protocol}//${o.hostname}${o.port ? `:${o.port}` : ""}/#/files/${(i = s.value) == null ? void 0 : i.infoHash}`;
    }), k = Q({ source: f }), { share: B, isSupported: L } = R();
    return (o, t) => {
      var d, i, u;
      return a(), c("div", K, [
        s.value ? (a(), c("div", {
          key: 1,
          class: "p-2 flex flex-wrap gap-2 bg-light-100 dark-bg-dark-400 rounded cursor-pointer items-center break-all",
          onClick: t[2] || (t[2] = (l) => v.value = !v.value)
        }, [
          W,
          e("div", X, p((d = s.value) == null ? void 0 : d.name), 1),
          e("div", Y, p((i = s.value) == null ? void 0 : i.infoHash), 1),
          e("div", Z, p(n(T)((u = s.value) == null ? void 0 : u.length)), 1),
          e("div", {
            class: "i-la-times",
            onClick: t[1] || (t[1] = V((l) => s.value = null, ["prevent", "stop"]))
          })
        ])) : (a(), c("label", O, [
          P,
          e("input", {
            class: "max-w-30",
            type: "file",
            accept: "image/*",
            onChange: t[0] || (t[0] = (l) => U(l))
          }, null, 32)
        ])),
        y(n(J), {
          open: v.value,
          onClose: t[7] || (t[7] = (l) => v.value = !1)
        }, {
          default: C(() => {
            var l, b, x;
            return [
              e("div", ee, [
                s.value ? (a(), c("div", te, [
                  se,
                  e("div", oe, p((l = s.value) == null ? void 0 : l.infoHash), 1),
                  e("a", {
                    class: "gap-2 button underline font-bold break-all",
                    href: f.value,
                    target: "_blank"
                  }, ie, 8, le),
                  n(k).isSupported.value ? (a(), c("button", {
                    key: 0,
                    class: "p-2 button gap-2",
                    onClick: t[3] || (t[3] = (r) => n(k).copy())
                  }, [
                    re,
                    e("div", de, p((b = n(k)) != null && b.copied.value ? "Copied!" : "Copy"), 1)
                  ])) : _("", !0),
                  n(L) ? (a(), c("button", {
                    key: 1,
                    class: "p-2 button gap-2",
                    onClick: t[4] || (t[4] = (r) => {
                      var w;
                      return n(B)({ title: (w = s.value) == null ? void 0 : w.name, url: f.value });
                    })
                  }, pe)) : _("", !0),
                  e("button", {
                    class: "button p-2 gap-2",
                    onClick: t[5] || (t[5] = (r) => m.value = !m.value)
                  }, [
                    ve,
                    e("div", fe, p(m.value ? "Hide" : "Show") + " QR ", 1)
                  ]),
                  e("button", {
                    class: "button p-2 gap-2",
                    onClick: t[6] || (t[6] = (r) => g.value = !g.value)
                  }, [
                    he,
                    e("div", _e, p(g.value ? "Hide" : "Show") + " file ", 1)
                  ])
                ])) : _("", !0),
                y(D, { name: "fade" }, {
                  default: C(() => [
                    f.value && m.value ? (a(), S(n(A), {
                      key: 0,
                      data: f.value
                    }, null, 8, ["data"])) : _("", !0)
                  ]),
                  _: 1
                }),
                g.value ? (a(!0), c(E, { key: 1 }, q((x = s.value) == null ? void 0 : x.files, (r) => (a(), S(n(I), {
                  class: "flex-auto",
                  key: r == null ? void 0 : r.name,
                  file: r
                }, null, 8, ["file"]))), 128)) : _("", !0)
              ])
            ];
          }),
          _: 1
        }, 8, ["open"])
      ]);
    };
  }
});
export {
  be as default
};
//# sourceMappingURL=TorrentUpload-D4iRNm_8.js.map
