/**
 * ldesign v0.2.3
 * (c) 2022年9月24日 swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var components_badge_props = require('./props.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
require('vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("badge");
var _Badge = utils_mixins["default"](classPrefixMixins).extend({
  name: "LBadge",
  props: { ...components_badge_props["default"]
  },
  methods: {
    getContent() {
      if (this.dot) return "";

      if (typeof this.count === "function") {
        return utils_renderNode.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])]);
  }

});

exports["default"] = _Badge;
//# sourceMappingURL=badge.js.map
