import {
  H as a,
  I as o,
  j as r,
  ay as e,
  c as l,
  ag as s,
  ah as i,
  w as n,
  X as t,
  Z as d,
  D as c,
  a8 as u,
  v,
  J as g,
  K as f,
  a0 as h,
  as as m,
  aT as p,
  aw as w,
  P as y,
  Q as b,
} from "./index-476be0bb.js";
const [z, L] = a("image");
const S = b(
  o({
    name: z,
    props: {
      src: String,
      alt: String,
      fit: String,
      position: String,
      round: Boolean,
      block: Boolean,
      width: g,
      height: g,
      radius: g,
      lazyLoad: Boolean,
      iconSize: g,
      showError: f,
      errorIcon: h("photo-fail"),
      iconPrefix: String,
      showLoading: f,
      loadingIcon: h("photo"),
    },
    emits: ["load", "error"],
    setup(a, { emit: o, slots: g }) {
      const f = r(!1),
        h = r(!0),
        b = r(),
        { $Lazyload: z } = e().proxy,
        S = l(() => {
          const o = { width: s(a.width), height: s(a.height) };
          return (
            i(a.radius) &&
              ((o.overflow = "hidden"), (o.borderRadius = s(a.radius))),
            o
          );
        });
      n(
        () => a.src,
        () => {
          (f.value = !1), (h.value = !0);
        }
      );
      const x = (a) => {
          h.value && ((h.value = !1), o("load", a));
        },
        I = () => {
          const a = new Event("load");
          Object.defineProperty(a, "target", {
            value: b.value,
            enumerable: !0,
          }),
            x(a);
        },
        P = (a) => {
          (f.value = !0), (h.value = !1), o("error", a);
        },
        j = (o, r, e) =>
          e
            ? e()
            : v(
                y,
                {
                  name: o,
                  size: a.iconSize,
                  class: r,
                  classPrefix: a.iconPrefix,
                },
                null
              ),
        $ = () => {
          if (f.value || !a.src) return;
          const o = {
            alt: a.alt,
            class: L("img"),
            style: { objectFit: a.fit, objectPosition: a.position },
          };
          return a.lazyLoad
            ? m(v("img", w({ ref: b }, o), null), [[p("lazy"), a.src]])
            : v(
                "img",
                w({ ref: b, src: a.src, onLoad: x, onError: P }, o),
                null
              );
        },
        E = ({ el: a }) => {
          const o = () => {
            a === b.value && h.value && I();
          };
          b.value ? o() : u(o);
        },
        k = ({ el: a }) => {
          a !== b.value || f.value || P();
        };
      return (
        z &&
          t &&
          (z.$on("loaded", E),
          z.$on("error", k),
          d(() => {
            z.$off("loaded", E), z.$off("error", k);
          })),
        c(() => {
          u(() => {
            var o;
            (null == (o = b.value) ? void 0 : o.complete) && !a.lazyLoad && I();
          });
        }),
        () => {
          var o;
          return v(
            "div",
            { class: L({ round: a.round, block: a.block }), style: S.value },
            [
              $(),
              h.value && a.showLoading
                ? v("div", { class: L("loading") }, [
                    j(a.loadingIcon, L("loading-icon"), g.loading),
                  ])
                : f.value && a.showError
                ? v("div", { class: L("error") }, [
                    j(a.errorIcon, L("error-icon"), g.error),
                  ])
                : void 0,
              null == (o = g.default) ? void 0 : o.call(g),
            ]
          );
        }
      );
    },
  })
);
export { S as I };
