"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const props = require("../utils/props.js");
const format = require("../utils/format.js");
const basic = require("../utils/basic.js");
const create = require("../utils/create.js");
const [name, bem] = create.createNamespace("badge");
const badgeProps = {
  dot: Boolean,
  max: props.numericProp,
  tag: props.makeStringProp("div"),
  color: String,
  offset: Array,
  content: props.numericProp,
  showZero: props.truthProp,
  position: props.makeStringProp("top-right")
};
var stdin_default = Vue.defineComponent({
  name,
  props: badgeProps,
  setup(props2, {
    slots
  }) {
    const hasContent = () => {
      if (slots.content) {
        return true;
      }
      const {
        content,
        showZero
      } = props2;
      return basic.isDef(content) && content !== "" && (showZero || content !== 0 && content !== "0");
    };
    const renderContent = () => {
      const {
        dot,
        max,
        content
      } = props2;
      if (!dot && hasContent()) {
        if (slots.content) {
          return slots.content();
        }
        if (basic.isDef(max) && basic.isNumeric(content) && +content > +max) {
          return `${max}+`;
        }
        return content;
      }
    };
    const getOffsetWithMinusString = (val) => val.startsWith("-") ? val.replace("-", "") : `-${val}`;
    const style = Vue.computed(() => {
      const style2 = {
        background: props2.color
      };
      if (props2.offset) {
        const [x, y] = props2.offset;
        const {
          position
        } = props2;
        const [offsetY, offsetX] = position.split("-");
        if (slots.default) {
          if (typeof y === "number") {
            style2[offsetY] = format.addUnit(offsetY === "top" ? y : -y);
          } else {
            style2[offsetY] = offsetY === "top" ? format.addUnit(y) : getOffsetWithMinusString(y);
          }
          if (typeof x === "number") {
            style2[offsetX] = format.addUnit(offsetX === "left" ? x : -x);
          } else {
            style2[offsetX] = offsetX === "left" ? format.addUnit(x) : getOffsetWithMinusString(x);
          }
        } else {
          style2.marginTop = format.addUnit(y);
          style2.marginLeft = format.addUnit(x);
        }
      }
      return style2;
    });
    const renderBadge = () => {
      if (hasContent() || props2.dot) {
        return Vue.createVNode("div", {
          "class": bem([props2.position, {
            dot: props2.dot,
            fixed: !!slots.default
          }]),
          "style": style.value
        }, [renderContent()]);
      }
    };
    return () => {
      if (slots.default) {
        const {
          tag
        } = props2;
        return Vue.createVNode(tag, {
          "class": bem("wrapper")
        }, {
          default: () => [slots.default(), renderBadge()]
        });
      }
      return renderBadge();
    };
  }
});
exports.badgeProps = badgeProps;
exports.default = stdin_default;
