import { defineComponent, ref, watch, nextTick, openBlock, createElementBlock, unref, normalizeClass, createElementVNode, normalizeStyle, withModifiers, toDisplayString, createCommentVNode, renderSlot } from "vue";
import "../../../adapter-vue.mjs";
import { TUITranslateService } from "@tencentcloud/chat-uikit-engine";
import { outsideClick } from "@tencentcloud/universal-api";
import { isH5, isUniFrameWork, isPC } from "../../../utils/env.mjs";
const _hoisted_1 = { key: 0 };
const _hoisted_2 = {
  key: 0,
  class: "header"
};
const _hoisted_3 = {
  key: 0,
  class: "header-title"
};
const _hoisted_4 = {
  key: 1,
  class: "footer"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    // Whether to display the bottom pop-up dialog box
    show: {
      type: Boolean,
      default: false
    },
    // Whether a mask layer is required, the default is true
    modal: {
      type: Boolean,
      default: true
    },
    // Popup box content area height (excluding mask), default is fit-content
    height: {
      type: String,
      default: "fit-content"
    },
    // Whether the pop-up dialog box can be closed by clicking outside, the default is true
    // uniapp only supports closing the pop-up dialog box by clicking the mask
    closeByClickOutside: {
      type: Boolean,
      default: true
    },
    // The rounded angle of the top border corners is 0px by default, i.e. right angle by default
    borderRadius: {
      type: String,
      default: "0px"
    },
    title: {
      type: String,
      default: ""
    },
    // Whether to display the top close button, not displayed by default
    showHeaderCloseButton: {
      type: Boolean,
      default: false
    },
    // Whether to display the submit button at the bottom, not displayed by default
    showFooterSubmitButton: {
      type: Boolean,
      default: false
    },
    // Bottom submit button text, only valid when showFooterSubmitButton is true
    submitButtonContent: {
      type: String,
      default: () => TUITranslateService.t("确定")
    }
  },
  emits: ["onOpen", "onClose", "onSubmit"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const dialogRef = ref();
    watch(
      () => props.show,
      (newVal, oldVal) => {
        if (newVal === oldVal) {
          return;
        }
        switch (newVal) {
          case true:
            emits("onOpen", dialogRef);
            nextTick(() => {
              if (isH5 && !isUniFrameWork) {
                if (props.closeByClickOutside) {
                  outsideClick.listen({
                    domRefs: dialogRef.value,
                    handler: closeBottomPopup
                  });
                }
              }
            });
            break;
          case false:
            emits("onClose", dialogRef);
            break;
        }
      }
    );
    const closeBottomPopup = () => {
      if (isUniFrameWork || isH5) {
        emits("onClose", dialogRef);
      }
    };
    const submit = () => {
      emits("onSubmit");
      closeBottomPopup();
    };
    return (_ctx, _cache) => {
      return props.show ? (openBlock(), createElementBlock("div", _hoisted_1, [
        !unref(isPC) ? (openBlock(), createElementBlock("div", {
          key: 0,
          class: normalizeClass([
            "bottom-popup",
            unref(isUniFrameWork) && "bottom-popup-uni",
            !unref(isPC) && "bottom-popup-h5",
            !unref(isPC) && props.modal && "bottom-popup-modal"
          ]),
          onClick: closeBottomPopup
        }, [
          createElementVNode("div", {
            ref_key: "dialogRef",
            ref: dialogRef,
            class: normalizeClass(["bottom-popup-main", !unref(isPC) && "bottom-popup-h5-main"]),
            style: normalizeStyle({
              height: props.height,
              borderTopLeftRadius: props.borderRadius,
              borderTopRightRadius: props.borderRadius
            }),
            onClick: _cache[0] || (_cache[0] = withModifiers(() => {
            }, ["stop"]))
          }, [
            __props.title || __props.showHeaderCloseButton ? (openBlock(), createElementBlock("div", _hoisted_2, [
              __props.title ? (openBlock(), createElementBlock("div", _hoisted_3, toDisplayString(__props.title), 1)) : createCommentVNode("", true),
              __props.showHeaderCloseButton ? (openBlock(), createElementBlock("div", {
                key: 1,
                class: "header-close",
                onClick: closeBottomPopup
              }, toDisplayString(unref(TUITranslateService).t("关闭")), 1)) : createCommentVNode("", true)
            ])) : createCommentVNode("", true),
            renderSlot(_ctx.$slots, "default", {}, void 0, true),
            __props.showFooterSubmitButton ? (openBlock(), createElementBlock("div", _hoisted_4, [
              createElementVNode("div", {
                class: "footer-submit",
                onClick: submit
              }, toDisplayString(__props.submitButtonContent), 1)
            ])) : createCommentVNode("", true)
          ], 6)
        ], 2)) : renderSlot(_ctx.$slots, "default", { key: 1 }, void 0, true)
      ])) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
