import { defineComponent as M, inject as S, ref as m, watch as g, computed as w, onMounted as F, createElementBlock as l, openBlock as t, Fragment as A, createElementVNode as u, createBlock as _, createCommentVNode as p, toDisplayString as E, Teleport as I, createVNode as N, Transition as V, withCtx as L, unref as T } from "vue";
import $ from "../../../node_modules/linkify-string/dist/linkify-string.js";
import j 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 "../../../functions/parseMarkdown.js";
import { isAnimatedSticker as D } from "../StickerMessage/utils/stickerUtils.js";
import "../StickerMessage/utils/suppress-lit-warning.js";
const H = ["src"], O = ["src"], q = ["src", "alt"], G = { class: "sticker-message__text-container" }, R = { key: 0 }, W = ["innerHTML"], z = ["src"], J = ["src"], K = ["src", "alt"], re = /* @__PURE__ */ M({
  __name: "ReplyStickerMessage",
  props: {
    message: {
      type: Object,
      required: !0
    }
  },
  setup(e) {
    const b = S("chatAppId"), { getTheme: v } = B(b), r = m(!1), c = m(!1);
    async function f() {
      if (!(r.value || c.value)) {
        c.value = !0;
        try {
          await import("../StickerMessage/libs/tgs-player/lottie-player.esm.js"), await import("../StickerMessage/libs/tgs-player/tgs-player.esm.js"), r.value = !0;
        } catch (s) {
          console.error("Failed to load TGS libraries:", s);
        } finally {
          c.value = !1;
        }
      }
    }
    const i = e, d = m(!1), k = m("");
    g(
      () => i.message.text,
      () => {
        i.message.text && (k.value = $(i.message.text));
      },
      { immediate: !0 }
    );
    const o = w(() => D(i.message.url, i.message.isAnimated)), n = m(!1), y = w(() => {
      if (o.value) return !1;
      const s = String(i.message.url || "").toLowerCase();
      return !/\.(webp|png|jpe?g|gif|bmp|svg)(\?|#|$)/.test(s);
    });
    g(
      () => i.message.url,
      () => {
        n.value = !1;
      },
      { immediate: !0 }
    ), g(o, (s) => {
      s && !r.value && f();
    }, { immediate: !0 }), F(() => {
      o.value && !r.value && f();
    });
    function x(s) {
      s.preventDefault(), s.target.href && window.open(s.target.href, "_blank");
    }
    const C = () => d.value = !1;
    return (s, a) => (t(), l(A, null, [
      u("div", {
        class: "sticker-message__preview-button",
        onClick: a[1] || (a[1] = (h) => d.value = !0)
      }, [
        o.value && r.value ? (t(), l("tgs-player", {
          key: 0,
          class: "sticker-message__preview-image-animated",
          src: e.message.url,
          autoplay: "",
          loop: "",
          mode: "normal"
        }, null, 8, H)) : y.value && !n.value ? (t(), l("video", {
          key: 1,
          class: "sticker-message__preview-image",
          src: e.message.url,
          autoplay: "",
          loop: "",
          muted: "",
          playsinline: "",
          preload: "metadata",
          onError: a[0] || (a[0] = (h) => n.value = !0)
        }, null, 40, O)) : (t(), l("img", {
          key: 2,
          class: "sticker-message__preview-image",
          src: e.message.url,
          alt: e.message.alt
        }, null, 8, q))
      ]),
      u("div", G, [
        e.message.header ? (t(), l("p", R, E(e.message.header), 1)) : p("", !0),
        a[3] || (a[3] = u("div", { class: "sticker-message__reply-description" }, [
          u("span", { class: "pi pi-image" }),
          u("p", null, "Стикер")
        ], -1)),
        e.message.text ? (t(), l("p", {
          key: 1,
          class: "sticker-message__text",
          onClick: x,
          innerHTML: k.value
        }, null, 8, W)) : p("", !0)
      ]),
      (t(), _(I, { to: "body" }, [
        N(V, { name: "modal-fade" }, {
          default: L(() => [
            d.value ? (t(), _(j, {
              key: 0,
              "data-theme": T(v)().theme ? T(v)().theme : "light",
              title: e.message.alt,
              onClose: C
            }, {
              default: L(() => [
                o.value && r.value ? (t(), l("tgs-player", {
                  key: 0,
                  class: "sticker-message__modal-image-animated",
                  src: e.message.url,
                  autoplay: "",
                  loop: "",
                  mode: "normal"
                }, null, 8, z)) : y.value && !n.value ? (t(), l("video", {
                  key: 1,
                  class: "sticker-message__modal-image",
                  src: e.message.url,
                  autoplay: "",
                  loop: "",
                  muted: "",
                  playsinline: "",
                  preload: "metadata",
                  onError: a[2] || (a[2] = (h) => n.value = !0)
                }, null, 40, J)) : (t(), l("img", {
                  key: 2,
                  class: "sticker-message__modal-image",
                  src: e.message.url,
                  alt: e.message.alt
                }, null, 8, K))
              ]),
              _: 1
            }, 8, ["data-theme", "title"])) : p("", !0)
          ]),
          _: 1
        })
      ]))
    ], 64));
  }
});
export {
  re as default
};
