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