import { defineComponent as b, ref as f, computed as y, useClipboard as w, useShare as C, openBlock as i, createElementBlock as c, createBaseVNode as e, toDisplayString as v, unref as t, createCommentVNode as u, createBlock as m, Fragment as S, renderList as $, uploadTorrent as U, watch as B } from "./composables-108ad332.js";
import { QrShow as H, FileCard as L } from "./components.js";
const D = { class: "flex flex-col gap-4 p-4" }, E = { class: "p-2 flex flex-wrap gap-2 bg-light-100 dark-bg-dark-400 rounded cursor-pointer" }, F = /* @__PURE__ */ e("div", { class: "font-bold" }, "Upload a file", -1), N = /* @__PURE__ */ e("div", { class: "flex-1" }, null, -1), R = { class: "flex flex-wrap gap-2" }, T = {
  key: 0,
  class: "flex flex-col gap-2"
}, V = /* @__PURE__ */ e("div", { class: "text-xl" }, "Share the torrent", -1), Q = { class: "font-mono text-sm" }, j = ["href"], q = /* @__PURE__ */ e("div", { class: "i-la-link" }, null, -1), z = /* @__PURE__ */ e("div", { class: "p-0" }, "Download URL", -1), A = [
  q,
  z
], G = /* @__PURE__ */ e("div", { class: "i-la-copy" }, null, -1), I = { class: "p-0" }, J = /* @__PURE__ */ e("div", { class: "i-la-share" }, null, -1), K = /* @__PURE__ */ e("div", { class: "p-0" }, " Share", -1), M = [
  J,
  K
], Y = /* @__PURE__ */ b({
  __name: "TorrentUpload",
  emits: ["uploaded"],
  setup(O, { emit: P }) {
    const r = f();
    f();
    function g(s) {
      var l;
      const { torrent: o } = U((l = s == null ? void 0 : s.target) == null ? void 0 : l.files);
      B(o, async (a) => {
        r.value = a, console.log(a);
      });
    }
    const d = y(() => {
      var o, l, a;
      if (!((o = r.value) != null && o.infoHash))
        return "";
      let s = new URL((l = window == null ? void 0 : window.location) == null ? void 0 : l.href);
      return `${s.protocol}//${s.hostname}${s.port ? `:${s.port}` : ""}/#/file/${(a = r.value) == null ? void 0 : a.infoHash}`;
    }), p = w({ source: d }), { share: k, isSupported: x } = C();
    return (s, o) => {
      var l, a, _;
      return i(), c("div", D, [
        e("label", E, [
          F,
          N,
          e("input", {
            type: "file",
            accept: "image/*",
            onChange: o[0] || (o[0] = (n) => g(n))
          }, null, 32)
        ]),
        e("div", R, [
          r.value ? (i(), c("div", T, [
            V,
            e("div", Q, v((l = r.value) == null ? void 0 : l.infoHash), 1),
            e("a", {
              class: "gap-2 button underline font-bold break-all",
              href: t(d),
              target: "_blank"
            }, A, 8, j),
            t(p).isSupported.value ? (i(), c("button", {
              key: 0,
              class: "p-2 button gap-2",
              onClick: o[1] || (o[1] = (n) => t(p).copy())
            }, [
              G,
              e("div", I, v((a = t(p)) != null && a.copied.value ? "Copied!" : "Copy"), 1)
            ])) : u("", !0),
            t(x) ? (i(), c("button", {
              key: 1,
              class: "p-2 button gap-2",
              onClick: o[2] || (o[2] = (n) => {
                var h;
                return t(k)({ title: (h = r.value) == null ? void 0 : h.name, url: t(d) });
              })
            }, M)) : u("", !0)
          ])) : u("", !0),
          t(d) ? (i(), m(t(H), {
            key: 1,
            data: t(d)
          }, null, 8, ["data"])) : u("", !0)
        ]),
        (i(!0), c(S, null, $((_ = r.value) == null ? void 0 : _.files, (n) => (i(), m(t(L), {
          key: n == null ? void 0 : n.name,
          file: n
        }, null, 8, ["file"]))), 128))
      ]);
    };
  }
});
export {
  Y as default
};
//# sourceMappingURL=TorrentUpload-92846c61.js.map
