import { defineComponent as M, inject as P, ref as s, computed as I, onMounted as x, createElementBlock as n, openBlock as o, createElementVNode as i, createBlock as h, withDirectives as k, vShow as g, createCommentVNode as r, toDisplayString as c, Teleport as A, createVNode as L, Transition as U, withCtx as T, unref as N } from "vue";
import z from "../../2_modals/ModalFullscreen/ModalFullscreen.vue.js";
import "../../../hooks/useMessageDraft.js";
import "../../../hooks/useSearchModel.js";
import { useTheme as B } from "../../../hooks/useTheme.js";
/* empty css                              */
/* empty css                                              */
import "../../../node_modules/linkifyjs/dist/linkify.js";
import "../../../node_modules/linkify-string/dist/linkify-string.js";
import "../../../functions/parseMarkdown.js";
const D = { class: "preview__container" }, j = { class: "preview__block" }, F = ["src"], O = ["src"], q = {
  key: 2,
  style: { display: "flex", gap: "5px" }
}, G = ["src"], H = { class: "pi pi-play" }, J = { class: "pi pi-pause" }, K = { key: 3 }, Q = { class: "preview__control-block" }, R = { class: "preview__information" }, W = { class: "preview__name" }, X = {
  key: 0,
  class: "preview__size"
}, Y = {
  key: 1,
  class: "preview__audio-time"
}, Z = {
  key: 2,
  class: "preview__audio-time"
}, ee = { class: "preview__reset" }, ie = ["src"], te = ["src"], ce = /* @__PURE__ */ M({
  __name: "FilePreview",
  props: {
    fileInfo: {
      type: Object,
      required: !0
    }
  },
  emits: ["reset"],
  setup(t, { emit: C }) {
    const b = P("chatAppId"), { getTheme: p } = B(b), E = C, e = s(), a = s(), u = s(!1), v = s(0), _ = s(0), d = s(!1), S = () => d.value = !1;
    function V() {
      e.value && (u.value ? e.value.pause() : e.value.play(), u.value = !u.value);
    }
    const w = (m) => {
      const l = Math.floor(m / 60), f = Math.floor(m % 60);
      return `${l.toString().padStart(2, "0")}:${f.toString().padStart(2, "0")}`;
    }, $ = I(() => e.value ? w(_.value) : "0:00"), y = I(() => e.value || a.value ? w(v.value) : "0:00");
    return x(() => {
      e.value != null && (e.value.addEventListener("loadedmetadata", () => {
        e.value != null && (e.value.duration == 1 / 0 || Number.isNaN(e.value.duration)) && (e.value.currentTime = 1e101, e.value.addEventListener("timeupdate", () => {
          e.value && (e.value.currentTime = 0, v.value = e.value.duration);
        }, { once: !0 })), v.value = e.value != null ? e.value.duration : 0;
      }), e.value.addEventListener("timeupdate", () => {
        _.value = e.value != null ? e.value.currentTime : 0;
      })), a.value && a.value.addEventListener("loadedmetadata", () => {
        a.value && (v.value = a.value.duration, (a.value.duration == 1 / 0 || Number.isNaN(a.value.duration)) && (a.value.currentTime = 1e101, a.value.addEventListener("timeupdate", () => {
          a.value && (a.value.currentTime = 0, v.value = a.value.duration);
        }, { once: !0 })));
      });
    }), (m, l) => (o(), n("div", D, [
      i("div", j, [
        t.fileInfo.isImage ? (o(), n("div", {
          key: 0,
          style: { position: "relative" },
          onClick: l[0] || (l[0] = (f) => d.value = !0)
        }, [
          i("img", {
            src: t.fileInfo.previewUrl,
            alt: "Image Preview",
            class: "preview__image"
          }, null, 8, F),
          l[3] || (l[3] = i("div", { class: "preview__shadow" }, [
            i("span", { class: "pi pi-plus-circle" })
          ], -1))
        ])) : t.fileInfo.isVideo ? (o(), n("div", {
          key: 1,
          style: { position: "relative" },
          onClick: l[1] || (l[1] = (f) => d.value = !0)
        }, [
          i("video", {
            ref_key: "video",
            ref: a,
            src: t.fileInfo.previewUrl,
            class: "preview__video"
          }, null, 8, O),
          l[4] || (l[4] = i("div", { class: "preview__shadow" }, [
            i("span", { class: "pi pi-play" })
          ], -1))
        ])) : t.fileInfo.isAudio ? (o(), n("div", q, [
          l[5] || (l[5] = i("span", {
            class: "pi pi-headphones",
            style: { "font-size": "1rem", margin: "auto" }
          }, null, -1)),
          i("audio", {
            ref_key: "audio",
            ref: e,
            src: t.fileInfo.previewUrl
          }, null, 8, G),
          i("button", {
            class: "preview__audio-control",
            onClick: V
          }, [
            k(i("span", H, null, 512), [
              [g, !u.value]
            ]),
            k(i("span", J, null, 512), [
              [g, u.value]
            ])
          ])
        ])) : (o(), n("div", K, [...l[6] || (l[6] = [
          i("span", {
            class: "pi pi-file",
            style: { "font-size": "2.5rem" }
          }, null, -1)
        ])]))
      ]),
      i("div", Q, [
        i("div", R, [
          i("span", W, c(t.fileInfo.fileName), 1),
          !t.fileInfo.isAudio && !t.fileInfo.isVideo ? (o(), n("span", X, c(t.fileInfo.fileSize), 1)) : r("", !0),
          t.fileInfo.isAudio ? (o(), n("span", Y, c(`${$.value} / ${y.value}`), 1)) : r("", !0),
          t.fileInfo.isVideo ? (o(), n("span", Z, c(y.value), 1)) : r("", !0)
        ]),
        i("div", ee, [
          i("span", {
            class: "pi pi-times",
            onClick: l[2] || (l[2] = (f) => E("reset"))
          })
        ])
      ]),
      (o(), h(A, { to: "body" }, [
        L(U, { name: "modal-fade" }, {
          default: T(() => [
            d.value ? (o(), h(z, {
              key: 0,
              theme: N(p)().theme ? N(p)().theme : "",
              title: t.fileInfo.fileName,
              onClose: S
            }, {
              default: T(() => [
                t.fileInfo.isVideo ? (o(), n("video", {
                  key: 0,
                  class: "preview__modal-video",
                  src: t.fileInfo.previewUrl,
                  controls: "",
                  autoplay: ""
                }, null, 8, ie)) : r("", !0),
                t.fileInfo.isImage ? (o(), n("img", {
                  key: 1,
                  class: "preview__modal-image",
                  src: t.fileInfo.previewUrl,
                  alt: "Image Preview"
                }, null, 8, te)) : r("", !0)
              ]),
              _: 1
            }, 8, ["theme", "title"])) : r("", !0)
          ]),
          _: 1
        })
      ]))
    ]));
  }
});
export {
  ce as default
};
