"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const comp = require("../../ui/src/comp.js");
const XEUtils = require("xe-utils");
require("../../ui/index.js");
const dom = require("../../ui/src/dom.js");
const useFns = require("../../../../@vxe-ui/core/es/src/useFns.js");
const config = require("../../../../@vxe-ui/core/es/src/config.js");
const event = require("../../../../@vxe-ui/core/es/src/event.js");
const index_esm = require("../../../../@vxe-ui/core/es/index.esm.js");
const VxeAvatarComponent = comp.defineVxeComponent({
  name: "VxeAvatar",
  props: {
    count: [String, Number],
    dot: Boolean,
    content: [String, Number],
    icon: String,
    src: String,
    width: [String, Number],
    height: [String, Number],
    circle: {
      type: Boolean,
      default: () => config.getConfig().avatar.circle
    },
    status: {
      type: String,
      default: () => config.getConfig().avatar.status
    },
    size: {
      type: String,
      default: () => config.getConfig().avatar.size || config.getConfig().size
    }
  },
  emits: [],
  setup(props, context) {
    const { emit } = context;
    const xID = XEUtils.uniqueId();
    const { computeSize } = useFns.useSize(props);
    const refElem = vue.ref();
    const reactData = vue.reactive({});
    const refMaps = {
      refElem
    };
    const computeAvatarStyle = vue.computed(() => {
      const { width, height } = props;
      const stys = {};
      if (width) {
        stys.width = dom.toCssUnit(width);
      }
      if (height) {
        stys.height = dom.toCssUnit(height);
      }
      return stys;
    });
    const computeCountNum = vue.computed(() => {
      const { count } = props;
      return count ? XEUtils.toNumber(count) : 0;
    });
    const computeMaps = {};
    const $xeAvatar = {
      xID,
      props,
      context,
      reactData,
      getRefMaps: () => refMaps,
      getComputeMaps: () => computeMaps
    };
    const dispatchEvent = (type, params, evnt) => {
      emit(type, event.createEvent(evnt, { $avatar: $xeAvatar }, params));
    };
    const collapsePaneMethods = {
      dispatchEvent
    };
    const collapsePanePrivateMethods = {};
    Object.assign($xeAvatar, collapsePaneMethods, collapsePanePrivateMethods);
    const renderContent = () => {
      const { icon, content, src } = props;
      if (icon) {
        return vue.h("span", {
          class: "vxe-avatar--icon"
        }, [
          vue.h("i", {
            class: icon
          })
        ]);
      }
      if (content) {
        return vue.h("span", {
          class: "vxe-avatar--content"
        }, `${content}`);
      }
      if (src) {
        return vue.h("img", {
          class: "vxe-avatar--img",
          src
        });
      }
      return index_esm.renderEmptyElement();
    };
    const renderVN = () => {
      const { circle, dot, status } = props;
      const vSize = computeSize.value;
      const countNum = computeCountNum.value;
      const avatarStyle = computeAvatarStyle.value;
      return vue.h("div", {
        ref: refElem,
        class: ["vxe-avatar", {
          [`size--${vSize}`]: vSize,
          [`theme--${status}`]: status,
          "is--circle": circle,
          "is--dot": dot
        }],
        style: avatarStyle
      }, [
        renderContent(),
        countNum ? vue.h("span", {
          class: "vxe-avatar--count"
        }, countNum > 99 ? "99+" : `${countNum}`) : index_esm.renderEmptyElement()
      ]);
    };
    $xeAvatar.renderVN = renderVN;
    return $xeAvatar;
  },
  render() {
    return this.renderVN();
  }
});
exports.default = VxeAvatarComponent;
