import { defineComponent as W, createElementBlock as a, openBlock as o, createCommentVNode as z, unref as t, normalizeStyle as $, createElementVNode as m, toDisplayString as k, Fragment as j, renderList as L, createBlock as q, reactive as G } from "vue";
import { prettyBytes as D } from "./composables-BAZQlC3e.js";
import { FileCard as H } from "./components.js";
const I = { class: "flex flex-col gap-2 max-w-55ch relative" }, J = {
  key: 1,
  class: "p-2"
}, K = {
  key: 2,
  class: "p-2 text-sm flex flex-wrap gap-2"
}, M = { class: "p-1" }, O = { class: "p-1" }, U = /* @__PURE__ */ W({
  __name: "TorrentDownload",
  props: {
    id: {
      type: String,
      default: ""
    }
  },
  setup(E) {
    const N = E;
    function V(f) {
      const r = G({
        files: [],
        task: null,
        status: {
          done: !1,
          progress: 0,
          downloadSpeed: 0,
          downloaded: 0
        }
      });
      return import("./webtorrent.min-nzZ6Y_6Q.js").then((d) => {
        const l = d.default, n = new l();
        r.task = n.add(f, (s) => {
          r.files = s.files;
        }), n.on("download", () => {
          const { progress: s, downloaded: p, done: i, downloadSpeed: c } = r.task;
          r.status = { done: i, progress: s, downloaded: p, downloadSpeed: c };
        });
      }), r;
    }
    const e = V(`magnet:?xt=urn:btih:${N.id}&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com`);
    return (f, r) => {
      var d, l, n, s, p, i, c, g, w, F, A, _, x, y, v, h, b, S, T, B, C;
      return o(), a("div", I, [
        ((l = (d = t(e)) == null ? void 0 : d.status) == null ? void 0 : l.progress) > 0 && !((s = (n = t(e)) == null ? void 0 : n.status) != null && s.done) ? (o(), a("div", {
          key: 0,
          class: "bg-dark-100 op-20 absolute top-0 bottom-0 left-0",
          inert: "",
          style: $({ width: `${((i = (p = t(e)) == null ? void 0 : p.status) == null ? void 0 : i.progress) * 100}%` })
        }, null, 4)) : z("", !0),
        ((g = (c = t(e)) == null ? void 0 : c.status) == null ? void 0 : g.progress) == 0 && !((F = (w = t(e)) == null ? void 0 : w.status) != null && F.done) ? (o(), a("div", J, r[0] || (r[0] = [
          m("div", { class: "p-1" }, "Waiting for the torrent... ", -1)
        ]))) : (_ = (A = t(e)) == null ? void 0 : A.status) != null && _.done ? z("", !0) : (o(), a("div", K, [
          r[1] || (r[1] = m("div", { class: "p-1" }, "Torrent: ", -1)),
          m("div", M, k((y = (x = t(e)) == null ? void 0 : x.status) != null && y.done ? "done" : (h = (v = t(e)) == null ? void 0 : v.status) == null ? void 0 : h.progress), 1),
          m("div", O, "Total " + k(t(D)((S = (b = t(e)) == null ? void 0 : b.status) == null ? void 0 : S.downloaded)) + " at " + k(t(D)((B = (T = t(e)) == null ? void 0 : T.status) == null ? void 0 : B.downloadSpeed)) + "/s", 1)
        ])),
        (o(!0), a(j, null, L((C = t(e)) == null ? void 0 : C.files, (u) => (o(), q(t(H), {
          key: u == null ? void 0 : u.name,
          file: u
        }, null, 8, ["file"]))), 128))
      ]);
    };
  }
});
export {
  U as default
};
//# sourceMappingURL=TorrentDownload-DW-XMpfI.js.map
