"use strict";
const common_vendor = require("../../../../common/vendor.js");
require("../../../adapter-vue.js");
const TUIKit_utils_env = require("../../../utils/env.js");
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  props: {
    url: { default: "https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png" },
    size: { default: "36px" },
    borderRadius: { default: "5px" },
    useSkeletonAnimation: { type: Boolean, default: false }
  },
  emits: ["onLoad", "onError"],
  setup(__props, { emit: __emit }) {
    const defaultAvatarUrl = common_vendor.ref("https://web.sdk.qcloud.com/component/TUIKit/assets/avatar_21.png");
    const emits = __emit;
    const props = __props;
    const {
      size: avatarSize,
      url: avatarImageUrl,
      borderRadius: avatarBorderRadius,
      useSkeletonAnimation: useAvatarSkeletonAnimation
    } = common_vendor.toRefs(props);
    let reloadAvatarTime = 0;
    const isImgLoaded = common_vendor.ref(false);
    const loadErrorInUniapp = common_vendor.ref(false);
    function avatarLoadSuccess(e) {
      isImgLoaded.value = true;
      emits("onLoad", e);
    }
    function avatarLoadFailed(e) {
      reloadAvatarTime += 1;
      if (reloadAvatarTime > 3) {
        return;
      }
      if (TUIKit_utils_env.isUniFrameWork) {
        loadErrorInUniapp.value = true;
      } else {
        e.currentTarget.src = defaultAvatarUrl.value;
      }
      emits("onError", e);
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.unref(TUIKit_utils_env.isUniFrameWork)
      }, common_vendor.unref(TUIKit_utils_env.isUniFrameWork) ? common_vendor.e({
        b: !common_vendor.unref(loadErrorInUniapp)
      }, !common_vendor.unref(loadErrorInUniapp) ? {
        c: common_vendor.unref(avatarImageUrl) || common_vendor.unref(defaultAvatarUrl),
        d: common_vendor.o$1(avatarLoadSuccess),
        e: common_vendor.o$1(avatarLoadFailed)
      } : {
        f: common_vendor.unref(defaultAvatarUrl),
        g: common_vendor.o$1(avatarLoadSuccess),
        h: common_vendor.o$1(avatarLoadFailed)
      }) : {
        i: common_vendor.unref(avatarImageUrl) || common_vendor.unref(defaultAvatarUrl),
        j: common_vendor.o$1(avatarLoadSuccess),
        k: common_vendor.o$1(avatarLoadFailed)
      }, {
        l: common_vendor.unref(useAvatarSkeletonAnimation) && !common_vendor.unref(isImgLoaded)
      }, common_vendor.unref(useAvatarSkeletonAnimation) && !common_vendor.unref(isImgLoaded) ? {
        m: common_vendor.unref(isImgLoaded) ? 1 : "",
        n: common_vendor.unref(useAvatarSkeletonAnimation) ? 1 : ""
      } : {}, {
        o: common_vendor.unref(avatarSize),
        p: common_vendor.unref(avatarSize),
        q: common_vendor.unref(avatarBorderRadius)
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c7c42418"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/common/Avatar/index.js.map
