/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { renderLNodeJSX } from '../../utils/render-node.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import props from './props.js';
import 'vue';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../_chunks/dep-def4c2ce.js';

const classPrefixMixins = getClassPrefixMixins("badge");
var _Badge = mixins(classPrefixMixins).extend({
  name: "LBadge",
  props: {
    ...props
  },
  methods: {
    getContent() {
      if (this.dot) return "";
      if (typeof this.count === "function") return renderLNodeJSX(this, "count");
      if (isNaN(Number(this.count))) return this.count;
      const count = Number(this.count);
      return count > this.maxCount ? `${this.maxCount}+` : count;
    },
    isSmall() {
      return this.size === "small";
    },
    isZero() {
      const content = this.getContent();
      return content === 0 || content === "0";
    },
    isHidden() {
      return !this.showZero && this.isZero();
    },
    getOffset() {
      if (!this.offset) return {};
      let [xOffset, yOffset] = this.offset;
      xOffset = isNaN(Number(xOffset)) ? xOffset : `${xOffset}px`;
      yOffset = isNaN(Number(yOffset)) ? yOffset : `${yOffset}px`;
      return {
        xOffset,
        yOffset
      };
    }
  },
  render() {
    const h = arguments[0];
    const {
      dot,
      shape,
      color
    } = this.$props;
    const content = this.getContent();
    const isHidden = this.isHidden();
    const children = this.$slots.default;
    const {
      xOffset,
      yOffset
    } = this.getOffset();
    const badgeClassNames = [{
      [`${this.componentName}--dot`]: !!dot,
      [`${this.componentName}--circle`]: !dot && shape === "circle",
      [`${this.componentName}--round`]: shape === "round",
      [`${this.componentName}--ribbon`]: shape === "ribbon",
      [`${this.classPrefix}-size-s`]: this.isSmall()
    }];
    const inlineStyle = {
      background: `${color}`,
      right: xOffset,
      top: yOffset
    };
    return h("div", {
      "class": this.componentName
    }, [children || null, isHidden ? null : h("sup", {
      "class": badgeClassNames,
      "style": inlineStyle
    }, [content])]);
  }
});

export { _Badge as default };
//# sourceMappingURL=badge.js.map
