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