// Function to attach event listener to the parent element
const attachEventListenerToParent = () => {
  const parentElement = document.querySelector('.chbs-booking-extra-list');
  
  if (parentElement) {
    parentElement.addEventListener('click', (event) => {
      const target = event.target;
      
      if (target.classList.contains('chbs-meta-icon-minus')) {
        // Find the first element with class 'chbs-summary' and simulate a click after 1000 milliseconds
        setTimeout(() => {
          const summaryElement = document.getElementById('movingStep2');
          if (summaryElement) {
            summaryElement.click();
            console.log('Step 2 element clicked');
          }
        }, 7000);
      }
      
      if (target.classList.contains('chbs-meta-icon-plus')) {
        // Find the first element with class 'chbs-summary' and simulate a click after 1000 milliseconds
        setTimeout(() => {
          const summaryElement = document.getElementById('movingStep2');
          if (summaryElement) {
            summaryElement.click();
            console.log('Step 2 element clicked');
          }
        }, 7000);
      }
    });
    
    clearInterval(intervalId); // Stop the interval
  }
};

// Function to check for the existence of parent element
const checkParentElement = () => {
  const parentElement = document.querySelector('.chbs-booking-extra-list');

  if (parentElement) {
    console.log('Parent element found');
    attachEventListenerToParent(); // Attach event listener to the parent element
  }
};

var intervalId = setInterval(() => {
  console.log('Checking for parent element');
  checkParentElement();
}, 3000);
