import { Controller } from '@hotwired/stimulus';
import { wpjEvent } from '@assets/components/util.event';

export default class extends Controller<HTMLElement> {
   scrollToReviews(event): void {
      const target = document.getElementById(event.params.target)
      if (target) {
         if (typeof target.checkVisibility() !== 'undefined' && !target.checkVisibility()) {
            const tab_trigger = document.querySelector(`[data-target="#${event.params.target}"]`);
            wpjEvent.trigger(tab_trigger, 'click');
         }
         target.scrollIntoView({ behavior: 'smooth', block: 'start' });
      }
   }
}
