"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const pinia = require("pinia");
require("../../services/main.js");
const roomService = require("../../services/roomService.js");
const types = require("../../services/types.js");
const index = require("../../locales/index.js");
require("@tencentcloud/tuiroom-engine-js");
require("mitt");
require("../../services/manager/roomActionManager.js");
require("@tencentcloud/tui-core");
const index$1 = require("../common/base/Dialog/index.js");
const Button = require("../common/base/Button.vue.js");
const index$2 = require("../common/base/Input/index.js");
const CloseInputIcon = require("../common/icons/CloseInputIcon.vue.js");
const utils = require("../../utils/utils.js");
const Message = require("../common/base/Message/Message.js");
const message = require("../../constants/message.js");
const basic = require("../../stores/basic.js");
const room = require("../../constants/room.js");
const SvgIcon = require("../common/base/SvgIcon.vue.js");
const _sfc_main = /* @__PURE__ */ Vue.defineComponent({
  __name: "PasswordDialog",
  props: {
    visible: { type: Boolean }
  },
  setup(__props) {
    const basicStore = basic.useBasicStore();
    const { roomId } = pinia.storeToRefs(basicStore);
    const { t } = index.useI18n();
    const inputPassword = Vue.ref("");
    const props = __props;
    const isShowPasswordContainer = Vue.ref(false);
    Vue.watch(
      () => props.visible,
      (val) => {
        isShowPasswordContainer.value = val;
      },
      {
        immediate: true
      }
    );
    async function joinRoom() {
      if (!utils.isDigitsOnly(inputPassword.value) || inputPassword.value.length < room.PASSWORD_MAX_LENGTH_LIMIT) {
        Message.default({
          type: "warning",
          message: t("Your room password format is incorrect, please check it"),
          duration: message.MESSAGE_DURATION.NORMAL
        });
        return;
      }
      await roomService.roomService.join(roomId.value, {
        isOpenCamera: false,
        isOpenMicrophone: true,
        password: inputPassword.value
      });
      roomService.roomService.emit(types.EventType.ROOM_JOIN);
    }
    function cancelInputPassword() {
      inputPassword.value = "";
      roomService.roomService.emit(types.EventType.ROOM_ERROR);
    }
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createBlock(Vue.unref(index$1.default), {
        modelValue: isShowPasswordContainer.value,
        "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => isShowPasswordContainer.value = $event),
        title: Vue.unref(t)("The room is encrypted"),
        modal: true,
        "show-close": false,
        "close-on-click-modal": false,
        width: "420px",
        "append-to-body": true,
        "confirm-button": Vue.unref(t)("Join"),
        "cancel-button": Vue.unref(t)("Cancel"),
        onConfirm: joinRoom,
        onCancel: cancelInputPassword
      }, {
        footer: Vue.withCtx(() => [
          Vue.createElementVNode("span", null, [
            Vue.createVNode(Button.default, {
              class: "button",
              size: "default",
              disabled: inputPassword.value.length === 0,
              onClick: joinRoom
            }, {
              default: Vue.withCtx(() => [
                Vue.createTextVNode(Vue.toDisplayString(Vue.unref(t)("Join")), 1)
              ]),
              _: 1
            }, 8, ["disabled"]),
            Vue.createVNode(Button.default, {
              class: "button",
              size: "default",
              type: "primary",
              onClick: cancelInputPassword
            }, {
              default: Vue.withCtx(() => [
                Vue.createTextVNode(Vue.toDisplayString(Vue.unref(t)("Cancel")), 1)
              ]),
              _: 1
            })
          ])
        ]),
        default: Vue.withCtx(() => [
          Vue.createVNode(Vue.unref(index$2.default), {
            "model-value": inputPassword.value,
            onInput: _cache[1] || (_cache[1] = ($event) => inputPassword.value = $event),
            placeholder: Vue.unref(t)("Please enter your room password"),
            type: "password",
            maxlength: "6"
          }, {
            suffixIcon: Vue.withCtx(() => [
              Vue.createVNode(SvgIcon.default, {
                class: "svg-icon",
                onClick: _cache[0] || (_cache[0] = ($event) => inputPassword.value = ""),
                icon: CloseInputIcon.default
              })
            ]),
            _: 1
          }, 8, ["model-value", "placeholder"])
        ]),
        _: 1
      }, 8, ["modelValue", "title", "confirm-button", "cancel-button"]);
    };
  }
});
exports.default = _sfc_main;
