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