export default {
  inserted(el, binding) {
    if (el.tagName === "IMG") {
      let hasError = false;

      const handleError = () => {
        if (!hasError) {
          hasError = true;
          el.src = binding.value.errorImageSrc;
          el.onerror = null; // Remove the onerror event to prevent loops
          el.onload = null; // Also remove the onload event in case of error
        }
      };

      el.onerror = handleError;
      el.src = binding.value.src;
    }
  },
  // update(el, binding) {
  //   if (el.tagName === "IMG" && el.src !== binding.value.src) {
  //     let hasError = false;

  //     const handleError = () => {
  //       if (!hasError) {
  //         hasError = true;
  //         el.src = binding.value.errorImageSrc;
  //         el.onerror = null; // Remove the onerror event to prevent loops
  //         el.onload = null; // Also remove the onload event in case of error
  //       }
  //     };

  //     el.onerror = handleError;
  //     el.src = binding.value.src;
  //   }
  // },
};
