import g from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import { useState as h, useRef as p, useEffect as d } from "react";
import { isImageValid as L } from "../util.mjs";
function b(o) {
  var t = o.src, u = o.isCustomPlaceholder, l = o.fallback, m = h(u ? "loading" : "normal"), i = g(m, 2), n = i[0], a = i[1], s = p(!1), c = n === "error";
  d(function() {
    var e = !0;
    return L(t).then(function(r) {
      !r && e && a("error");
    }), function() {
      e = !1;
    };
  }, [t]), d(function() {
    u && !s.current ? a("loading") : c && a("normal");
  }, [t]);
  var f = function() {
    a("normal");
  }, v = function(r) {
    s.current = !1, n === "loading" && r !== null && r !== void 0 && r.complete && (r.naturalWidth || r.naturalHeight) && (s.current = !0, f());
  }, S = c && l ? {
    src: l
  } : {
    onLoad: f,
    src: t
  };
  return [v, S, n];
}
export {
  b as default
};
