import { defineComponent as D, computed as r, createElementBlock as o, openBlock as a, unref as s, normalizeStyle as h, normalizeClass as u, createCommentVNode as i, createElementVNode as m, createVNode as f, withCtx as R, createTextVNode as O, toDisplayString as v, createBlock as g, Transition as j } from "vue";
import z from "../../1_atoms/ContextMenu/ContextMenu.vue.js";
import W from "../../1_atoms/LinkPreview/LinkPreview.vue.js";
import $ from "../../1_atoms/EmbedPreview/EmbedPreview.vue.js";
import G from "../BaseReplyMessage/BaseReplyMessage.vue.js";
import J from "../MessageReactions/MessageReactions.vue.js";
import K from "../MessageStatusIndicator/MessageStatusIndicator.vue.js";
import Q from "../MessageSmsInvite/MessageSmsInvite.vue.js";
import U from "../../1_atoms/Tooltip/Tooltip.vue.js";
import { useMessageActions as X } from "../../../hooks/messages/useMessageActions.js";
import { useMessageLinks as Y } from "../../../hooks/messages/useMessageLinks.js";
import { useChannelAccentColor as Z } from "../../../hooks/messages/useChannelAccentColor.js";
import { useSubtextTooltip as p } from "../../../hooks/messages/useSubtextTooltip.js";
import { getStatus as _, getStatusTitle as ee } from "../../../functions/getStatusMessage.js";
import { getMessageClass as se } from "../../../functions/getMessageClass.js";
import { createReactionHandlers as te } from "../../../functions/createReactionHandlers.js";
import "../../../functions/parseMarkdown.js";
const ae = ["messageId"], ne = ["src"], ie = {
  key: 1,
  class: "text-message__subtext"
}, le = ["innerHTML"], oe = { class: "text-message__info-container" }, me = {
  key: 1,
  class: "text-message__time"
}, Ie = /* @__PURE__ */ D({
  __name: "TextMessage",
  props: {
    message: {
      type: Object,
      required: !0
    },
    applyStyle: {
      type: Function,
      default: () => null
    },
    isFirstInSeries: {
      type: Boolean,
      default: !0
    },
    reactionsEnabled: {
      type: Boolean,
      default: !0
    },
    subtextTooltipData: {
      type: Object,
      required: !1,
      default: () => ({})
    },
    channel: {
      type: String,
      required: !1,
      default: void 0
    }
  },
  emits: ["action", "reply", "sms-invite"],
  setup(e, { emit: w }) {
    const n = e, c = w, { linkedHtml: T, inNewWindow: y } = Y(() => n.message.text), {
      isOpenMenu: d,
      buttonMenuVisible: I,
      showMenu: b,
      hideMenu: x,
      clickAction: C,
      viewsAction: k,
      handleClickReplied: A
    } = X(n.message, c), B = r(() => _(n.message.status)), F = r(() => ee(n.message.status, n.message.statusMsg)), { bubbleStyle: E } = Z(
      r(() => n.message),
      { cssVariable: "--chotto-textmessage-right-bg", position: "right" }
    );
    function S(M) {
      return se(M.position, "text-message");
    }
    const { onToggleReaction: V, onAddReaction: N, onRemoveReaction: H } = te(c), L = p(() => n.message, () => n.subtextTooltipData), P = r(
      () => n.message.status === "error" && n.message.hasMessengerAccount === !1
    );
    function q() {
      c("sms-invite", n.message);
    }
    return (M, t) => (a(), o("div", {
      class: u(["text-message", [
        S(e.message),
        e.applyStyle(e.message)
      ]]),
      messageId: e.message.messageId,
      style: h(s(E)),
      onMouseleave: t[4] || (t[4] = //@ts-ignore
      (...l) => s(x) && s(x)(...l))
    }, [
      e.message.avatar && e.isFirstInSeries ? (a(), o("img", {
        key: 0,
        class: "text-message__avatar",
        src: e.message.avatar,
        height: "32",
        width: "32",
        style: h({ gridRow: e.message.subText && e.isFirstInSeries ? "2" : "1" })
      }, null, 12, ne)) : i("", !0),
      e.message.subText && e.isFirstInSeries ? (a(), o("p", ie, [
        f(U, {
          text: s(L),
          position: e.message.position === "left" ? "right" : "left",
          offset: 8
        }, {
          default: R(() => [
            O(v(e.message.subText), 1)
          ]),
          _: 1
        }, 8, ["text", "position"])
      ])) : i("", !0),
      m("div", {
        class: u(["text-message__content", { "is-first": e.isFirstInSeries, "with-avatar-indent": !e.isFirstInSeries && e.message.avatar }]),
        onMouseenter: t[3] || (t[3] = //@ts-ignore
        (...l) => s(b) && s(b)(...l))
      }, [
        e.message.reply ? (a(), g(G, {
          key: 0,
          class: u(e.message.position),
          message: e.message.reply,
          onReply: s(A)
        }, null, 8, ["class", "message", "onReply"])) : i("", !0),
        m("p", {
          class: "text-message__text",
          onClick: t[0] || (t[0] = //@ts-ignore
          (...l) => s(y) && s(y)(...l)),
          innerHTML: s(T)
        }, null, 8, le),
        e.message.linkPreview ? (a(), g(W, {
          key: 1,
          class: u(e.message.position),
          "link-preview": e.message.linkPreview
        }, null, 8, ["class", "link-preview"])) : i("", !0),
        e.message.embed ? (a(), g($, {
          key: 2,
          class: u(e.message.position),
          embed: e.message.embed
        }, null, 8, ["class", "embed"])) : i("", !0),
        e.reactionsEnabled ? (a(), g(J, {
          key: 3,
          reactions: e.message.reactions,
          "message-id": e.message.messageId,
          enabled: e.reactionsEnabled,
          onToggleReaction: s(V),
          onAddReaction: s(N),
          onRemoveReaction: s(H)
        }, null, 8, ["reactions", "message-id", "enabled", "onToggleReaction", "onAddReaction", "onRemoveReaction"])) : i("", !0),
        m("div", oe, [
          e.message.views ? (a(), o("div", {
            key: 0,
            class: "text-message__views",
            onClick: t[1] || (t[1] = //@ts-ignore
            (...l) => s(k) && s(k)(...l))
          }, [
            t[5] || (t[5] = m("span", { class: "pi pi-eye" }, null, -1)),
            m("p", null, v(e.message.views), 1)
          ])) : i("", !0),
          e.message.time ? (a(), o("span", me, v(e.message.time), 1)) : i("", !0),
          f(K, {
            "base-class": "text-message",
            "message-class": S(e.message),
            "message-status": e.message.status,
            "status-class": B.value,
            "status-title": F.value
          }, null, 8, ["message-class", "message-status", "status-class", "status-title"])
        ]),
        P.value ? (a(), g(Q, {
          key: 4,
          status: e.message.status,
          "has-messenger-account": e.message.hasMessengerAccount,
          channel: e.channel,
          onSmsInvite: q
        }, null, 8, ["status", "has-messenger-account", "channel"])) : i("", !0),
        s(I) && e.message.actions ? (a(), o("button", {
          key: 5,
          class: "text-message__menu-button",
          onClick: t[2] || (t[2] = (l) => d.value = !s(d))
        }, [...t[6] || (t[6] = [
          m("span", { class: "pi pi-ellipsis-h" }, null, -1)
        ])])) : i("", !0),
        f(j, null, {
          default: R(() => [
            s(d) && e.message.actions ? (a(), g(z, {
              key: 0,
              class: "text-message__context-menu",
              actions: e.message.actions,
              onClick: s(C)
            }, null, 8, ["actions", "onClick"])) : i("", !0)
          ]),
          _: 1
        })
      ], 34)
    ], 46, ae));
  }
});
export {
  Ie as default
};
