"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const lockClick = require("./lock-click.js");
const index$1 = require("../icon/index.js");
const index = require("../popup/index.js");
const index$2 = require("../loading/index.js");
const props = require("../utils/props.js");
const create = require("../utils/create.js");
const basic = require("../utils/basic.js");
const [name, bem] = create.createNamespace("toast");
const popupInheritProps = ["show", "overlay", "teleport", "transition", "overlayClass", "overlayStyle", "closeOnClickOverlay", "zIndex"];
const toastProps = {
  icon: String,
  show: Boolean,
  type: props.makeStringProp("text"),
  overlay: Boolean,
  message: props.numericProp,
  iconSize: props.numericProp,
  duration: props.makeNumberProp(2e3),
  position: props.makeStringProp("middle"),
  teleport: [String, Object],
  wordBreak: String,
  className: props.unknownProp,
  iconPrefix: String,
  transition: props.makeStringProp("van-fade"),
  loadingType: String,
  forbidClick: Boolean,
  overlayClass: props.unknownProp,
  overlayStyle: Object,
  closeOnClick: Boolean,
  closeOnClickOverlay: Boolean,
  zIndex: props.numericProp
};
var stdin_default = Vue.defineComponent({
  name,
  props: toastProps,
  emits: ["update:show"],
  setup(props2, {
    emit,
    slots
  }) {
    let timer;
    let clickable = false;
    const toggleClickable = () => {
      const newValue = props2.show && props2.forbidClick;
      if (clickable !== newValue) {
        clickable = newValue;
        lockClick.lockClick(clickable);
      }
    };
    const updateShow = (show) => emit("update:show", show);
    const onClick = () => {
      if (props2.closeOnClick) {
        updateShow(false);
      }
    };
    const clearTimer = () => clearTimeout(timer);
    const renderIcon = () => {
      const {
        icon,
        type,
        iconSize,
        iconPrefix,
        loadingType
      } = props2;
      const hasIcon = icon || type === "success" || type === "fail";
      if (hasIcon) {
        return Vue.createVNode(index$1.Icon, {
          "name": icon || type,
          "size": iconSize,
          "class": bem("icon"),
          "classPrefix": iconPrefix
        }, null);
      }
      if (type === "loading") {
        return Vue.createVNode(index$2.Loading, {
          "class": bem("loading"),
          "size": iconSize,
          "type": loadingType
        }, null);
      }
    };
    const renderMessage = () => {
      const {
        type,
        message
      } = props2;
      if (slots.message) {
        return Vue.createVNode("div", {
          "class": bem("text")
        }, [slots.message()]);
      }
      if (basic.isDef(message) && message !== "") {
        return type === "html" ? Vue.createVNode("div", {
          "key": 0,
          "class": bem("text"),
          "innerHTML": String(message)
        }, null) : Vue.createVNode("div", {
          "class": bem("text")
        }, [message]);
      }
    };
    Vue.watch(() => [props2.show, props2.forbidClick], toggleClickable);
    Vue.watch(() => [props2.show, props2.type, props2.message, props2.duration], () => {
      clearTimer();
      if (props2.show && props2.duration > 0) {
        timer = setTimeout(() => {
          updateShow(false);
        }, props2.duration);
      }
    });
    Vue.onMounted(toggleClickable);
    Vue.onUnmounted(toggleClickable);
    return () => Vue.createVNode(index.Popup, Vue.mergeProps({
      "class": [bem([props2.position, props2.wordBreak === "normal" ? "break-normal" : props2.wordBreak, {
        [props2.type]: !props2.icon
      }]), props2.className],
      "lockScroll": false,
      "onClick": onClick,
      "onClosed": clearTimer,
      "onUpdate:show": updateShow
    }, basic.pick(props2, popupInheritProps)), {
      default: () => [renderIcon(), renderMessage()]
    });
  }
});
exports.default = stdin_default;
exports.toastProps = toastProps;
