"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: "button-container" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "index",
  props: {
    modelValue: { type: Boolean },
    roomId: {}
  },
  emits: ["update:modelValue", "success", "cancel", "error"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const { t } = uikitBaseComponentVue3.useUIKit();
    const { joinRoom } = room.useRoomState();
    const visible = vue.ref(false);
    const password = vue.ref("");
    const isJoining = vue.ref(false);
    vue.watch(() => props.modelValue, (val) => {
      visible.value = val;
    });
    vue.watch(visible, (val) => {
      emit("update:modelValue", val);
      if (!val) {
        password.value = "";
      }
    });
    const handleConfirm = async () => {
      if (!password.value) {
        uikitBaseComponentVue3.TUIToast.error({ message: t("Room.EnterPassword") });
        return;
      }
      if (isJoining.value) {
        return;
      }
      try {
        isJoining.value = true;
        await joinRoom({
          roomId: props.roomId,
          password: password.value
        });
        visible.value = false;
        password.value = "";
        emit("success", { roomId: props.roomId, password: password.value });
      } catch (error) {
        console.error("Failed to join room with password:", error);
        emit("error", error);
      } finally {
        isJoining.value = false;
      }
    };
    const handleCancel = () => {
      visible.value = false;
      password.value = "";
      emit("cancel");
    };
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.unref(uikitBaseComponentVue3.TUIDialog), {
        visible: visible.value,
        "onUpdate:visible": _cache[1] || (_cache[1] = ($event) => visible.value = $event),
        title: vue.unref(t)("Room.EnterPassword"),
        "show-close": false,
        modal: false
      }, {
        footer: vue.withCtx(() => [
          vue.createElementVNode("div", _hoisted_1, [
            vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIButton), {
              type: "primary",
              style: { "min-width": "88px" },
              loading: isJoining.value,
              onClick: handleConfirm
            }, {
              default: vue.withCtx(() => [
                vue.createTextVNode(vue.toDisplayString(vue.unref(t)("Room.Confirm")), 1)
              ]),
              _: 1
            }, 8, ["loading"]),
            vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIButton), {
              style: { "min-width": "88px" },
              onClick: handleCancel
            }, {
              default: vue.withCtx(() => [
                vue.createTextVNode(vue.toDisplayString(vue.unref(t)("Room.Cancel")), 1)
              ]),
              _: 1
            })
          ])
        ]),
        default: vue.withCtx(() => [
          vue.createVNode(vue.unref(uikitBaseComponentVue3.TUIInput), {
            modelValue: password.value,
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => password.value = $event),
            type: "number",
            "show-password": "",
            "max-length": "6",
            placeholder: vue.unref(t)("Room.EnterPasswordPlaceholder"),
            onKeyup: vue.withKeys(handleConfirm, ["enter"])
          }, null, 8, ["modelValue", "placeholder"])
        ]),
        _: 1
      }, 8, ["visible", "title"]);
    };
  }
});
exports.default = _sfc_main;
