"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 PopUpArrowDown = require("../base/PopUpArrowDown.vue2.js");
const _hoisted_1 = { class: "login-user-info" };
const _hoisted_2 = { class: "user-id" };
const _hoisted_3 = {
  key: 1,
  class: "login-user-info-trigger"
};
const _hoisted_4 = { 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 isLogoutPopupVisible = vue.ref(false);
    const emits = __emit;
    const showLogoutPopup = () => {
      isLogoutPopupVisible.value = true;
    };
    const handleLogout = async () => {
      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, _d, _e, _f;
      return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
        vue.createElementVNode("div", _hoisted_1, [
          props.showLogout ? (vue.openBlock(), vue.createElementBlock("div", {
            key: 0,
            class: "login-user-info-trigger",
            onClick: showLogoutPopup
          }, [
            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_2, vue.toDisplayString(((_b = vue.unref(loginUserInfo)) == null ? void 0 : _b.userName) || ((_c = vue.unref(loginUserInfo)) == null ? void 0 : _c.userId)), 1),
            vue.createVNode(vue.unref(uikitBaseComponentVue3.IconCaretDownSmall), { size: 24 })
          ])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_3, [
            vue.createVNode(vue.unref(room.Avatar), {
              src: (_d = vue.unref(loginUserInfo)) == null ? void 0 : _d.avatarUrl,
              size: 28
            }, null, 8, ["src"]),
            vue.createElementVNode("span", _hoisted_4, vue.toDisplayString(((_e = vue.unref(loginUserInfo)) == null ? void 0 : _e.userName) || ((_f = vue.unref(loginUserInfo)) == null ? void 0 : _f.userId)), 1)
          ]))
        ]),
        vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIPopup), {
          modelValue: isLogoutPopupVisible.value,
          "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isLogoutPopupVisible.value = $event)
        }, {
          default: vue.withCtx(() => [
            vue.createVNode(PopUpArrowDown.default, {
              onClick: _cache[0] || (_cache[0] = ($event) => isLogoutPopupVisible.value = false)
            }),
            vue.createElementVNode("div", {
              class: "logout-popup",
              onClick: handleLogout
            }, vue.toDisplayString(vue.unref(t)("LoginUserInfo.Logout")), 1)
          ]),
          _: 1
        }, 8, ["modelValue"])
      ], 64);
    };
  }
});
exports.default = _sfc_main;
