import { LEFTBAR_GENERAL_ROW_TYPES as C, LEFTBAR_GENERAL_ROW_CONTACT_CENTER_COLORS as N, LEFTBAR_GENERAL_ROW_CONTACT_CENTER_VALIDATION_ERROR as D, LEFTBAR_GENERAL_ROW_ICON_SIZES as k } from "./general-row-constants.js";
import { DtIconWaveform as M, DtIconPhone as W } from "@dialpad/dialtone-icons/vue3";
import I from "./leftbar-general-row-icon.js";
import { addClassStyleAttrs as q, removeClassStyleAttrs as z, returnFirstEl as b, safeConcatStrings as v, extractVueListeners as F } from "../../common/utils/index.js";
import { DialtoneLocalization as V } from "../../localization/index.js";
import { resolveComponent as o, resolveDirective as G, createElementBlock as h, openBlock as r, mergeProps as O, createElementVNode as s, createCommentVNode as u, toHandlers as x, withDirectives as L, renderSlot as R, createVNode as c, normalizeStyle as j, withCtx as i, createTextVNode as w, toDisplayString as m, createBlock as T, normalizeClass as S, withModifiers as P } from "vue";
import { _ as X } from "../../_plugin-vue_export-helper-CHgC5LLL.js";
import H from "../tooltip/tooltip.js";
import Y from "../button/button.js";
import K from "../badge/badge.js";
import Z from "../emoji-text-wrapper/emoji-text-wrapper.js";
const J = {
  compatConfig: { MODE: 3 },
  name: "DtRecipeGeneralRow",
  components: {
    DtEmojiTextWrapper: Z,
    DtBadge: K,
    DtButton: Y,
    DtTooltip: H,
    DtIconPhone: W,
    DtIconWaveform: M,
    DtRecipeLeftbarGeneralRowIcon: I
  },
  inheritAttrs: !1,
  props: {
    /**
     * Determines the icon to show.
     * If type is contact center, the color prop must be provided and will determine the color of the icon
     */
    type: {
      type: String,
      default: "inbox",
      validator: (t) => Object.values(C).includes(t)
    },
    /**
     * Will be read out by a screen reader upon focus of this row. If not defined "description" will be read.
     */
    ariaLabel: {
      type: String,
      default: ""
    },
    /**
     * Text displayed next to the icon. Required. Even if you are overriding this field using the label slot
     * you still must input this as it will be displayed as the "title" attribute for the row.
     */
    description: {
      type: String,
      required: !0
    },
    /**
     * Determines the color of the contact center icon
     */
    color: {
      type: String,
      default: null,
      validator: (t) => Object.keys(N).includes(t)
    },
    /**
     * The channel setting, either 'mention' or 'always'.
     * @values 'mention', 'always', null.
     */
    channelSetting: {
      type: String,
      default: null
    },
    /**
     * Styles the row with an increased font weight to convey it has unreads. This must be true to see
     * the unread count badge.
     */
    hasUnreads: {
      type: Boolean,
      default: !1
    },
    /**
     * Number of unread messages
     */
    unreadCount: {
      type: String,
      default: null
    },
    /**
     * Number of unread mention messages
     */
    unreadMentionCount: {
      type: String,
      default: null
    },
    /**
     * Determines if the row is selected
     */
    selected: {
      type: Boolean,
      default: !1
    },
    /**
     * Gives a faded style to be used when muted
     */
    muted: {
      type: Boolean,
      default: !1
    },
    /**
     * Shows styling to represent an active voice chat. This will display over unreadCount.
     */
    activeVoiceChat: {
      type: Boolean,
      default: !1
    },
    /**
     * Acronym used to represent "Do not Disturb" state. If entered will display the entered text alongside
     * unreadCount.
     */
    dndText: {
      type: String,
      default: ""
    },
    /**
     * Whether the row should have a call button. Usually only applicable to individual contact rows.
     */
    hasCallButton: {
      type: Boolean,
      default: !1
    },
    /**
     * Shows an "is typing" animation over the avatar when true.
     */
    isTyping: {
      type: Boolean,
      default: !1
    },
    /**
     * Sets the size of the icon.
     */
    iconSize: {
      type: String,
      default: "300",
      validator: (t) => k.includes(t)
    }
  },
  emits: [
    /**
     * Call button clicked
     *
     * @event call
     * @type {PointerEvent | KeyboardEvent}
     */
    "call"
  ],
  data() {
    return {
      actionFocused: !1,
      labelWidth: "100%",
      i18n: new V()
    };
  },
  computed: {
    leftbarGeneralRowClasses() {
      return [
        "d-recipe-leftbar-row",
        {
          "d-recipe-leftbar-row--no-action": !this.hasCallButton,
          "d-recipe-leftbar-row--has-unread": this.hasUnreads,
          "d-recipe-leftbar-row__unread-count": this.showUnreadCount || this.showUnreadMentionCount,
          "d-recipe-leftbar-row--selected": this.selected,
          "d-recipe-leftbar-row--muted": this.muted,
          "d-recipe-leftbar-row--action-focused": this.actionFocused
        }
      ];
    },
    getIcon() {
      switch (this.type) {
        case C.CHANNELS:
          if (this.hasUnreads) return "channel unread";
          break;
        case C.LOCKED_CHANNEL:
          if (this.hasUnreads) return "locked channel unread";
          break;
      }
      return this.type;
    },
    generalRowListeners() {
      return F(this.$attrs);
    },
    getAriaLabel() {
      return this.ariaLabel ? this.ariaLabel : v([
        this.typingTooltip,
        this.description,
        this.unreadCountTooltip,
        this.dndTextTooltip,
        this.activeVoiceChatTooltip
      ]);
    },
    hasActions() {
      return this.dndText || this.activeVoiceChat || this.showUnreadCount || this.hasCallButton || this.showUnreadMentionCount;
    },
    showUnreadCount() {
      return !!this.unreadCount && this.hasUnreads;
    },
    showUnreadMentionCount() {
      return !!this.unreadMentionCount && this.hasUnreads;
    },
    hasUnreadCount() {
      return this.unreadCount !== null;
    },
    hasUnreadMentionCount() {
      return this.unreadMentionCount !== null;
    },
    shouldApplyCustomStyleForCountBadge() {
      return this.hasUnreadCount && this.hasUnreadMentionCount;
    },
    /**
     * When a channel in 'always' setting, meaning the user should see both unread count and unread mention count,
     * if there are only mention messages, we should apply the theme design tokens var(--dt-theme-mention-color-[background||foreground]-strong).
     * @returns {boolean}
     */
    shouldApplyCustomStyleForMentionOnly() {
      return this.channelSetting === "always" && !this.hasUnreadCount && this.hasUnreadMentionCount;
    },
    messageCount() {
      return isNaN(this.unreadCount) ? this.unreadCount : Number(this.unreadCount);
    },
    mentionCount() {
      return isNaN(this.unreadMentionCount) ? this.unreadMentionCount : Number(this.unreadMentionCount);
    },
    unreadCountTooltip() {
      return v([
        this.unreadCount && this.i18n.$t("DIALTONE_UNREAD_MESSAGE_COUNT_TEXT", { unreadCount: this.messageCount }),
        this.unreadMentionCount && this.i18n.$t("DIALTONE_UNREAD_MENTION_COUNT_TEXT", { unreadCount: this.mentionCount })
      ]);
    },
    dndTextTooltip() {
      return this.dndText && this.i18n.$t("DIALTONE_GENERAL_ROW_DND_TEXT_TOOLTIP");
    },
    activeVoiceChatTooltip() {
      return this.activeVoiceChat && this.i18n.$t("DIALTONE_GENERAL_ROW_ACTIVE_VOICE_CHAT_TEXT");
    },
    callButtonTooltip() {
      return this.i18n.$t("DIALTONE_GENERAL_ROW_CALL_BUTTON_TOOLTIP");
    },
    typingTooltip() {
      return this.isTyping && this.i18n.$t("DIALTONE_TYPING_TEXT");
    }
  },
  watch: {
    $props: {
      immediate: !0,
      deep: !0,
      async handler() {
        this.validateProps(), await this.$nextTick(), this.adjustLabelWidth();
      }
    }
  },
  mounted() {
    this.resizeObserver = new ResizeObserver(this.adjustLabelWidth), this.resizeObserver.observe(b(this.$el)), this.adjustLabelWidth();
  },
  beforeUnmount: function() {
    this.resizeObserver.disconnect();
  },
  methods: {
    removeClassStyleAttrs: z,
    addClassStyleAttrs: q,
    validateProps() {
      this.type === C.CONTACT_CENTER && !Object.keys(N).includes(this.color) && console.error(D);
    },
    adjustLabelWidth() {
      var l, e, _, p, d, f;
      const t = ((e = (l = b(this.$el)) == null ? void 0 : l.querySelector(".d-recipe-leftbar-row__primary")) == null ? void 0 : e.clientWidth) || 0, a = ((p = (_ = b(this.$el)) == null ? void 0 : _.querySelector(".d-recipe-leftbar-row__omega")) == null ? void 0 : p.clientWidth) || 0, n = ((f = (d = b(this.$el)) == null ? void 0 : d.querySelector(".d-recipe-leftbar-row__alpha")) == null ? void 0 : f.clientWidth) || 0, g = 16;
      this.labelWidth = t - (a + n + g) + "px";
    }
  }
}, Q = ["data-qa", "aria-label", "title", "href"], $ = { class: "d-recipe-leftbar-row__alpha" }, ee = {
  key: 0,
  class: "d-recipe-leftbar-row__is-typing"
}, te = /* @__PURE__ */ s("span", null, null, -1), ne = /* @__PURE__ */ s("span", null, null, -1), re = /* @__PURE__ */ s("span", null, null, -1), ae = [
  te,
  ne,
  re
], oe = {
  key: 0,
  class: "d-recipe-leftbar-row__omega"
}, ie = {
  key: 1,
  class: "d-recipe-leftbar-row__active-voice"
}, se = {
  key: 3,
  class: "d-recipe-leftbar-row__action",
  "data-qa": "dt-recipe-leftbar-row-action"
};
function le(t, a, n, g, l, e) {
  const _ = o("dt-recipe-leftbar-general-row-icon"), p = o("dt-emoji-text-wrapper"), d = o("dt-tooltip"), f = o("dt-icon-waveform"), E = o("dt-badge"), U = o("dt-icon-phone"), B = o("dt-button"), A = G("dt-tooltip");
  return r(), h("div", O({ class: e.leftbarGeneralRowClasses }, e.addClassStyleAttrs(t.$attrs), { "data-qa": "dt-recipe-leftbar-row" }), [
    s("a", O({
      class: "d-recipe-leftbar-row__primary",
      "data-qa": "data-qa" in t.$attrs ? t.$attrs["data-qa"] : "d-recipe-leftbar-row-link",
      "aria-label": e.getAriaLabel,
      title: n.description,
      href: "href" in t.$attrs ? t.$attrs.href : "javascript:void(0)"
    }, e.removeClassStyleAttrs(t.$attrs), x(e.generalRowListeners, !0)), [
      s("div", $, [
        n.isTyping ? L((r(), h("div", ee, ae)), [
          [A, e.typingTooltip]
        ]) : R(t.$slots, "left", { key: 1 }, () => [
          c(_, {
            type: e.getIcon,
            color: n.color,
            "icon-size": n.iconSize,
            "data-qa": "dt-recipe-leftbar-row-icon"
          }, null, 8, ["type", "color", "icon-size"])
        ])
      ]),
      s("div", {
        class: "d-recipe-leftbar-row__label",
        style: j(`flex-basis: ${l.labelWidth}`)
      }, [
        R(t.$slots, "label", {}, () => [
          c(p, {
            class: "d-recipe-leftbar-row__description",
            "data-qa": "dt-recipe-leftbar-row-description",
            size: "200"
          }, {
            default: i(() => [
              w(m(n.description), 1)
            ]),
            _: 1
          })
        ])
      ], 4)
    ], 16, Q),
    e.hasActions ? (r(), h("div", oe, [
      n.dndText ? (r(), T(d, {
        key: 0,
        placement: "top",
        message: e.dndTextTooltip
      }, {
        anchor: i(() => [
          s("div", {
            ref: "d-recipe-leftbar-row-dnd",
            class: "d-recipe-leftbar-row__dnd",
            "data-qa": "dt-recipe-leftbar-row-dnd"
          }, m(n.dndText), 513)
        ]),
        _: 1
      }, 8, ["message"])) : u("", !0),
      n.activeVoiceChat ? L((r(), h("div", ie, [
        c(f, { size: "300" })
      ])), [
        [A, e.activeVoiceChatTooltip]
      ]) : e.showUnreadCount || e.showUnreadMentionCount ? (r(), T(d, {
        key: 2,
        message: e.unreadCountTooltip,
        placement: "top"
      }, {
        anchor: i(() => [
          e.showUnreadCount ? (r(), T(E, {
            key: 0,
            kind: "count",
            type: "bulletin",
            "data-qa": "dt-recipe-leftbar-row-unread-badge",
            class: S(["d-recipe-leftbar-row__unread-badge", {
              "d-recipe-leftbar-row__unread-count-badge": e.shouldApplyCustomStyleForCountBadge
            }])
          }, {
            default: i(() => [
              w(m(n.unreadCount), 1)
            ]),
            _: 1
          }, 8, ["class"])) : u("", !0),
          e.showUnreadMentionCount ? (r(), T(E, {
            key: 1,
            kind: "count",
            type: "bulletin",
            "data-qa": "dt-recipe-leftbar-row-unread-mention-badge",
            class: S([
              "d-recipe-leftbar-row__unread-badge",
              { "d-recipe-leftbar-row__unread-mention-count-badge": e.shouldApplyCustomStyleForCountBadge },
              { "d-recipe-leftbar-row__unread-mention-only-count-badge": e.shouldApplyCustomStyleForMentionOnly }
            ])
          }, {
            default: i(() => [
              w(m(n.unreadMentionCount), 1)
            ]),
            _: 1
          }, 8, ["class"])) : u("", !0)
        ]),
        _: 1
      }, 8, ["message"])) : u("", !0),
      n.hasCallButton ? (r(), h("div", se, [
        c(d, {
          message: e.callButtonTooltip,
          placement: "top"
        }, {
          anchor: i(() => [
            c(B, {
              class: "d-recipe-leftbar-row__action-button",
              "data-qa": "dt-recipe-leftbar-row-action-call-button",
              circle: "",
              size: "xs",
              kind: "inverted",
              "aria-label": e.callButtonTooltip,
              onFocus: a[0] || (a[0] = (y) => l.actionFocused = !0),
              onBlur: a[1] || (a[1] = (y) => l.actionFocused = !1),
              onClick: a[2] || (a[2] = P((y) => t.$emit("call", y), ["stop"]))
            }, {
              icon: i(() => [
                c(U, { size: "200" })
              ]),
              _: 1
            }, 8, ["aria-label"])
          ]),
          _: 1
        }, 8, ["message"])
      ])) : u("", !0)
    ])) : u("", !0)
  ], 16);
}
const ye = /* @__PURE__ */ X(J, [["render", le]]);
export {
  ye as default
};
//# sourceMappingURL=general-row.js.map
