"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const uikitBaseComponentVue3 = require("@tencentcloud/uikit-base-component-vue3");
const room = require("tuikit-atomicx-vue3/room");
const _hoisted_1 = { class: "login-user-info" };
const _hoisted_2 = { class: "login-user-info-trigger" };
const _hoisted_3 = { class: "user-id" };
const _hoisted_4 = {
  key: 1,
  class: "login-user-info-trigger"
};
const _hoisted_5 = { class: "user-id" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "index",
  props: {
    showLogout: { type: Boolean, default: true }
  },
  emits: ["logout"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const { loginUserInfo, logout } = room.useLoginState();
    const { t } = uikitBaseComponentVue3.useUIKit();
    const emits = __emit;
    const handleCommand = async (command) => {
      if (command === "logout") {
        try {
          await logout();
          localStorage.removeItem("tuiRoom-userInfo");
          uikitBaseComponentVue3.TUIToast.success({ message: t("LoginUserInfo.LogoutSuccess") });
          emits("logout");
        } catch (_error) {
          uikitBaseComponentVue3.TUIToast.error({ message: t("LoginUserInfo.LogoutFailed") });
        }
      }
    };
    return (_ctx, _cache) => {
      var _a, _b, _c;
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        props.showLogout ? (vue.openBlock(), vue.createBlock(vue.unref(uikitBaseComponentVue3.TUIDropdown), {
          key: 0,
          trigger: "click",
          placement: "bottom-end",
          onCommand: handleCommand
        }, {
          dropdown: vue.withCtx(() => [
            vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIDropdownItem), { command: "logout" }, {
              default: vue.withCtx(() => [
                vue.createTextVNode(vue.toDisplayString(vue.unref(t)("LoginUserInfo.Logout")), 1)
              ]),
              _: 1
            })
          ]),
          default: vue.withCtx(() => {
            var _a2, _b2, _c2;
            return [
              vue.createElementVNode("div", _hoisted_2, [
                vue.createVNode(vue.unref(room.Avatar), {
                  src: (_a2 = vue.unref(loginUserInfo)) == null ? void 0 : _a2.avatarUrl,
                  size: 28
                }, null, 8, ["src"]),
                vue.createElementVNode("span", _hoisted_3, vue.toDisplayString(((_b2 = vue.unref(loginUserInfo)) == null ? void 0 : _b2.userName) || ((_c2 = vue.unref(loginUserInfo)) == null ? void 0 : _c2.userId)), 1),
                vue.createVNode(vue.unref(uikitBaseComponentVue3.IconCaretDownSmall), { size: 24 })
              ])
            ];
          }),
          _: 1
        })) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [
          vue.createVNode(vue.unref(room.Avatar), {
            src: (_a = vue.unref(loginUserInfo)) == null ? void 0 : _a.avatarUrl,
            size: 28
          }, null, 8, ["src"]),
          vue.createElementVNode("span", _hoisted_5, vue.toDisplayString(((_b = vue.unref(loginUserInfo)) == null ? void 0 : _b.userName) || ((_c = vue.unref(loginUserInfo)) == null ? void 0 : _c.userId)), 1)
        ]))
      ]);
    };
  }
});
exports.default = _sfc_main;
