import { defineComponent as R, computed as S, ref as z, onMounted as I, createElementBlock as m, openBlock as d, normalizeStyle as x, withDirectives as U, createElementVNode as n, createVNode as V, unref as s, toDisplayString as f, vShow as j, createBlock as A, createCommentVNode as H } from "vue";
import { useMd as P, useUser as F, selectedUser as O, getFirstEmoji as B } from "./composables-BAZQlC3e.js";
import { AccountBadge as q, TorrentDownload as G } from "./components.js";
import { _export_sfc as J } from "./_plugin-vue_export-helper-DueaC3du.js";
const K = ["id", "data-pub"], Q = { class: "ml-2 text-sm opacity-20 hover-opacity-80 transition cursor-default text-light-200" }, W = { class: "ml-2 text-sm opacity-20 hover-opacity-80 transition cursor-default text-dark-200" }, X = {
  key: 0,
  class: "text-8xl"
}, Y = ["innerHTML"], Z = /* @__PURE__ */ R({
  __name: "ChatMessage",
  props: {
    index: { type: Number, default: 0 },
    source: {
      type: Object,
      default: () => ({
        author: "",
        timestamp: "",
        text: "empty"
      })
    }
  },
  setup(e) {
    const a = e, L = P(), v = S(() => E(Number(a.source.timestamp))), { user: N } = F(), u = S(() => a.source.author == N.pub);
    function E(o) {
      if (!o) return;
      const t = new Date(o), r = t.toLocaleDateString("en-CA"), i = t.toLocaleTimeString("ru-RU");
      return {
        full: r + " " + i,
        date: r,
        time: i
        // ms: ms(Date.now() - theDate.getTime()),
      };
    }
    const p = z(!0);
    return I(() => {
      var o, t;
      a.index > 1 && ((t = (o = document.getElementById(`chat-${a.index - 1}`)) == null ? void 0 : o.dataset) == null ? void 0 : t.pub) == a.source.author && (p.value = !1);
    }), (o, t) => {
      var r, i, h, y, b, g, k, w, c, D, M, l, T, $, C;
      return d(), m("div", {
        class: "px-1 py-2px flex flex-col w-full gap-1",
        style: x({ alignItems: u.value ? "end" : "start" })
      }, [
        U(n("div", {
          class: "flex items-center w-full mt-2",
          id: `chat-${e.index}`,
          style: x({ flexDirection: u.value ? "row-reverse" : "row" }),
          "data-pub": e.source.author
        }, [
          V(s(q), {
            class: "opacity-50 hover-opacity-90 transition",
            pub: e.source.author,
            "show-name": !0,
            size: 20,
            onClick: t[0] || (t[0] = (_) => s(O).pub = e.source.author)
          }, null, 8, ["pub"]),
          n("div", Q, f((r = v.value) == null ? void 0 : r.time), 1),
          t[1] || (t[1] = n("div", { class: "flex-1" }, null, -1)),
          n("div", W, f((i = v.value) == null ? void 0 : i.date), 1)
        ], 12, K), [
          [j, p.value]
        ]),
        n("div", {
          class: "px-2 py-1 bg-light-300 dark-bg-dark-200 dark-bg-opacity-80 bg-opacity-80 rounded-b-xl max-w-max break-all overflow-hidden",
          style: x({ borderTopLeftRadius: u.value ? "12px" : "0px", borderTopRightRadius: u.value ? "0px" : "12px", fontSize: `${(h = e.source) == null ? void 0 : h.text}` == s(B)(`${(y = e.source) == null ? void 0 : y.text}`) ? "6em" : "1em" })
        }, [
          ((b = e.source) == null ? void 0 : b.text) == s(B)(`${(g = e.source) == null ? void 0 : g.text}`) ? (d(), m("div", X, f((k = e.source) == null ? void 0 : k.text), 1)) : (D = (c = (w = e.source) == null ? void 0 : w.text) == null ? void 0 : c.split) != null && D.call(c, "#/files/")[1] ? (d(), A(s(G), {
            key: 1,
            id: (T = (l = (M = e.source) == null ? void 0 : M.text) == null ? void 0 : l.split) == null ? void 0 : T.call(l, "#/files/")[1].slice(0, 40)
          }, null, 8, ["id"])) : ($ = e.source) != null && $.text ? (d(), m("div", {
            key: 2,
            class: "markdown-body",
            innerHTML: s(L).render(`${(C = e.source) == null ? void 0 : C.text}`)
          }, null, 8, Y)) : H("", !0)
        ], 4)
      ], 4);
    };
  }
}), se = /* @__PURE__ */ J(Z, [["__scopeId", "data-v-2d944cf6"]]);
export {
  se as default
};
//# sourceMappingURL=ChatMessage-DTtyLvwY.js.map
