"use strict";
const common_vendor = require("../../../../common/vendor.js");
const uni_modules_uviewPro_components_uImage_types = require("./types.js");
const uni_modules_uviewPro_libs_index = require("../../libs/index.js");
require("../../libs/util/logger.js");
require("../../libs/config/theme-tokens.js");
if (!Array) {
  const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  _easycom_u_icon2();
}
const _easycom_u_icon = () => "../u-icon/u-icon.js";
if (!Math) {
  _easycom_u_icon();
}
const __default__ = {
  name: "u-image",
  options: {
    addGlobalClass: true,
    virtualHost: true,
    styleIsolation: "shared"
  }
};
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  ...__default__,
  props: uni_modules_uviewPro_components_uImage_types.ImageProps,
  emits: ["click", "error", "load"],
  setup(__props, { expose: __expose, emit: __emit }) {
    const emit = __emit;
    const props = __props;
    const isError = common_vendor.ref(false);
    const loading = common_vendor.ref(true);
    const opacity = common_vendor.ref(1);
    const durationTime = common_vendor.ref(props.duration);
    const backgroundStyle = common_vendor.ref({});
    common_vendor.watch(
      () => props.src,
      (n) => {
        if (!n) {
          isError.value = true;
          loading.value = false;
        } else {
          isError.value = false;
          loading.value = true;
        }
      },
      { immediate: true }
    );
    const wrapStyle = common_vendor.computed(() => {
      let style = {};
      style.width = uni_modules_uviewPro_libs_index.$u.addUnit(props.width);
      style.height = uni_modules_uviewPro_libs_index.$u.addUnit(props.height);
      style.borderRadius = props.shape === "circle" ? "50%" : uni_modules_uviewPro_libs_index.$u.addUnit(props.borderRadius);
      style.overflow = Number(props.borderRadius) > 0 ? "hidden" : "visible";
      if (props.fade) {
        style.opacity = opacity.value;
        style.transition = `opacity ${Number(durationTime.value) / 1e3}s ease-in-out`;
      }
      return style;
    });
    function onClick() {
      emit("click");
    }
    function onErrorHandler(err) {
      loading.value = false;
      isError.value = true;
      emit("error", err);
    }
    function onLoadHandler() {
      loading.value = false;
      isError.value = false;
      emit("load");
      if (!props.fade)
        return removeBgColor();
      opacity.value = 0;
      durationTime.value = 0;
      setTimeout(() => {
        durationTime.value = props.duration;
        opacity.value = 1;
        setTimeout(() => {
          removeBgColor();
        }, Number(durationTime.value));
      }, 50);
    }
    function removeBgColor() {
      backgroundStyle.value = {
        backgroundColor: "transparent"
      };
    }
    function changeStatus(status) {
      if (status === "loading") {
        loading.value = true;
        isError.value = false;
      } else if (status === "error") {
        loading.value = false;
        isError.value = true;
      } else {
        loading.value = false;
        isError.value = false;
      }
    }
    const $slots = common_vendor.useSlots();
    function hasSlot(name) {
      return props.useSlots ? !!$slots[name] && props.useSlots[name] : !!$slots[name];
    }
    __expose({
      changeStatus
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: !isError.value
      }, !isError.value ? {
        b: _ctx.src,
        c: _ctx.mode,
        d: common_vendor.o(onErrorHandler, "d0"),
        e: common_vendor.o(onLoadHandler, "eb"),
        f: _ctx.lazyLoad,
        g: _ctx.showMenuByLongpress,
        h: _ctx.shape === "circle" ? "50%" : common_vendor.unref(uni_modules_uviewPro_libs_index.$u).addUnit(_ctx.borderRadius)
      } : {}, {
        i: _ctx.showLoading && loading.value
      }, _ctx.showLoading && loading.value ? common_vendor.e({
        j: hasSlot("loading")
      }, hasSlot("loading") ? {} : {
        k: common_vendor.p({
          name: _ctx.loadingIcon,
          width: _ctx.width,
          height: _ctx.height
        })
      }, {
        l: _ctx.shape === "circle" ? "50%" : common_vendor.unref(uni_modules_uviewPro_libs_index.$u).addUnit(_ctx.borderRadius),
        m: _ctx.bgColor
      }) : {}, {
        n: _ctx.showError && isError.value && !loading.value
      }, _ctx.showError && isError.value && !loading.value ? common_vendor.e({
        o: hasSlot("error")
      }, hasSlot("error") ? {} : {
        p: common_vendor.p({
          name: _ctx.errorIcon,
          width: _ctx.width,
          height: _ctx.height
        })
      }, {
        q: _ctx.shape === "circle" ? "50%" : common_vendor.unref(uni_modules_uviewPro_libs_index.$u).addUnit(_ctx.borderRadius)
      }) : {}, {
        r: common_vendor.o(onClick, "d8"),
        s: common_vendor.s(common_vendor.unref(uni_modules_uviewPro_libs_index.$u).toStyle(wrapStyle.value, backgroundStyle.value, _ctx.customStyle)),
        t: common_vendor.n(_ctx.customClass)
      });
    };
  }
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c4bf84b3"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uview-pro/components/u-image/u-image.js.map
