import { defineComponent, ref, computed, createElementBlock, openBlock, createVNode, unref } from "vue";
import { useUIKit } from "@tencentcloud/uikit-base-component-vue3";
import { useMessageActions, MessageList, MessageInputH5 } from "tuikit-atomicx-vue3/chat";
import { useRoomParticipantState } from "tuikit-atomicx-vue3/room";
import CustomMessage from "./CustomMessage.vue3.mjs";
const _hoisted_1 = { class: "room-chat" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "RoomChat",
  setup(__props) {
    const messageListRef = ref(null);
    const messageInputRef = ref(null);
    const { t } = useUIKit();
    const { localParticipant } = useRoomParticipantState();
    const placeholder = computed(
      () => {
        var _a;
        return ((_a = localParticipant.value) == null ? void 0 : _a.isMessageDisabled) ? t("RoomChat.disabled_placeholder") : t("RoomChat.input_placeholder");
      }
    );
    const messageActionList = useMessageActions(["copy", "recall", "delete"]);
    function handleInputAreaExpand() {
      var _a;
      (_a = messageListRef.value) == null ? void 0 : _a.scrollToBottom({ behavior: "instant" });
    }
    function handleMessageListClick(event) {
      var _a;
      const target = event.target;
      if (!target.closest(".message-bubble")) {
        (_a = messageInputRef.value) == null ? void 0 : _a.collapsePanel();
      }
    }
    return (_ctx, _cache) => {
      var _a;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(unref(MessageList), {
          ref_key: "messageListRef",
          ref: messageListRef,
          class: "room-message-list",
          messageActionList: unref(messageActionList),
          Message: CustomMessage,
          onClick: handleMessageListClick
        }, null, 8, ["messageActionList"]),
        createVNode(unref(MessageInputH5), {
          ref_key: "messageInputRef",
          ref: messageInputRef,
          class: "room-message-input",
          placeholder: placeholder.value,
          disabled: (_a = unref(localParticipant)) == null ? void 0 : _a.isMessageDisabled,
          onInputAreaExpand: handleInputAreaExpand
        }, null, 8, ["placeholder", "disabled"])
      ]);
    };
  }
});
export {
  _sfc_main as default
};
