import { defineComponent, createElementBlock, openBlock, createBlock, unref, withCtx, createElementVNode, createVNode, toDisplayString, createTextVNode } from "vue";
import { useUIKit, TUIDropdown, IconCaretDownSmall, TUIDropdownItem, TUIToast } from "@tencentcloud/uikit-base-component-vue3";
import { useLoginState, Avatar } from "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__ */ defineComponent({
  __name: "index",
  props: {
    showLogout: { type: Boolean, default: true }
  },
  emits: ["logout"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const { loginUserInfo, logout } = useLoginState();
    const { t } = useUIKit();
    const emits = __emit;
    const handleCommand = async (command) => {
      if (command === "logout") {
        try {
          await logout();
          localStorage.removeItem("tuiRoom-userInfo");
          TUIToast.success({ message: t("LoginUserInfo.LogoutSuccess") });
          emits("logout");
        } catch (_error) {
          TUIToast.error({ message: t("LoginUserInfo.LogoutFailed") });
        }
      }
    };
    return (_ctx, _cache) => {
      var _a, _b, _c;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        props.showLogout ? (openBlock(), createBlock(unref(TUIDropdown), {
          key: 0,
          trigger: "click",
          placement: "bottom-end",
          onCommand: handleCommand
        }, {
          dropdown: withCtx(() => [
            createVNode(unref(TUIDropdownItem), { command: "logout" }, {
              default: withCtx(() => [
                createTextVNode(toDisplayString(unref(t)("LoginUserInfo.Logout")), 1)
              ]),
              _: 1
            })
          ]),
          default: withCtx(() => {
            var _a2, _b2, _c2;
            return [
              createElementVNode("div", _hoisted_2, [
                createVNode(unref(Avatar), {
                  src: (_a2 = unref(loginUserInfo)) == null ? void 0 : _a2.avatarUrl,
                  size: 28
                }, null, 8, ["src"]),
                createElementVNode("span", _hoisted_3, toDisplayString(((_b2 = unref(loginUserInfo)) == null ? void 0 : _b2.userName) || ((_c2 = unref(loginUserInfo)) == null ? void 0 : _c2.userId)), 1),
                createVNode(unref(IconCaretDownSmall), { size: 24 })
              ])
            ];
          }),
          _: 1
        })) : (openBlock(), createElementBlock("div", _hoisted_4, [
          createVNode(unref(Avatar), {
            src: (_a = unref(loginUserInfo)) == null ? void 0 : _a.avatarUrl,
            size: 28
          }, null, 8, ["src"]),
          createElementVNode("span", _hoisted_5, toDisplayString(((_b = unref(loginUserInfo)) == null ? void 0 : _b.userName) || ((_c = unref(loginUserInfo)) == null ? void 0 : _c.userId)), 1)
        ]))
      ]);
    };
  }
});
export {
  _sfc_main as default
};
