import { ActionEvent, Controller } from '@hotwired/stimulus';

export default class extends Controller<HTMLElement> {
   static values = {
      productId: Number,
   };

   declare productIdValue: number | null;

   handleItemMouseOver(event: ActionEvent) {
      const customEvent = new CustomEvent(`product-${this.productIdValue}:changeImageSrc`, {
         detail: {
            src: event.params.imageSrc,
         },
      });
      document.dispatchEvent(customEvent);
   }

   handleCollectionMouseLeave() {
      const customEvent = new CustomEvent(`product-${this.productIdValue}:revertToOriginalSrc`);
      document.dispatchEvent(customEvent);
   }
}
