"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const types = require("../../../utils/types.js");
const style = require("../../../utils/dom/style.js");
const index = require("../../../hooks/use-namespace/index.js");
const index$1 = require("../../icon/index.js");
const avatar = require("./avatar.js");
const constants = require("./constants.js");
const vue = require("vue");
const shared_esmBundler = require("../../../../../@vue/shared/dist/shared.esm-bundler.js");
const _hoisted_1 = [
  "src",
  "alt",
  "srcset"
];
var avatar_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ vue.defineComponent({
  name: "ElAvatar",
  __name: "avatar",
  props: avatar.avatarProps,
  emits: avatar.avatarEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const avatarGroupContext = vue.inject(constants.avatarGroupContextKey, void 0);
    const ns = index.useNamespace("avatar");
    const hasLoadError = vue.ref(false);
    const size = vue.computed(() => props.size ?? (avatarGroupContext == null ? void 0 : avatarGroupContext.size));
    const shape = vue.computed(() => props.shape ?? (avatarGroupContext == null ? void 0 : avatarGroupContext.shape) ?? "circle");
    const avatarClass = vue.computed(() => {
      const { icon } = props;
      const classList = [ns.b()];
      if (shared_esmBundler.isString(size.value)) classList.push(ns.m(size.value));
      if (icon) classList.push(ns.m("icon"));
      if (shape.value) classList.push(ns.m(shape.value));
      return classList;
    });
    const sizeStyle = vue.computed(() => {
      return types.isNumber(size.value) ? ns.cssVarBlock({ size: style.addUnit(size.value) }) : void 0;
    });
    const fitStyle = vue.computed(() => ({ objectFit: props.fit }));
    vue.watch(() => [props.src, props.srcSet], () => hasLoadError.value = false);
    function handleError(e) {
      hasLoadError.value = true;
      emit("error", e);
    }
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("span", {
        class: vue.normalizeClass(avatarClass.value),
        style: vue.normalizeStyle(sizeStyle.value)
      }, [(__props.src || __props.srcSet) && !hasLoadError.value ? (vue.openBlock(), vue.createElementBlock("img", {
        key: 0,
        src: __props.src,
        alt: __props.alt,
        srcset: __props.srcSet,
        style: vue.normalizeStyle(fitStyle.value),
        onError: handleError
      }, null, 44, _hoisted_1)) : __props.icon ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), { key: 1 }, {
        default: vue.withCtx(() => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.icon)))]),
        _: 1
      })) : vue.renderSlot(_ctx.$slots, "default", { key: 2 })], 6);
    };
  }
});
exports.default = avatar_vue_vue_type_script_setup_true_lang_default;
