if ($('#launchWeekSubscribe').length) {
  // wait for Heap cookie to exist
  // function waitForHeap() {
  //   var startTimeInMs = Date.now();
  //   if (readCookie('_hp2_id.588835629') != null) {
  //     var decoded = decodeURIComponent(readCookie('_hp2_id.588835629'));
  //     document.querySelector('#heap_user_id').value =
  //       JSON.parse(decoded).userId;
  //   } else {
  //     // if cookie not found after 10 seconds, stop running
  //     setTimeout(function () {
  //       if (10000 && Date.now() - startTimeInMs > 10000) return;
  //       waitForHeap();
  //     }, 150);
  //   }
  // }
  // waitForHeap();

  jQuery('#launchWeekSubscribeForm').on('submit', (e) => {
    e.preventDefault();
    var first = jQuery('#launchWeekFirst').val();
    var last = jQuery('#launchWeekLast').val();
    var email = jQuery('#launchWeekEmail').val();
    var company = jQuery('#launchWeekCompany').val();
    var url = window.location.href;
    var path = window.location.pathname
    // var heap_user_id = jQuery('#heap_user_id').val();

    window.dataLayer.push({
      event: 'hubspot-form-success',
      'hs-form-guid': '0d508094-e876-4df4-824a-3e36adf47d71',
    });

    // https://starburst.pantheonlocal.com/
    // https://www.starburst.io/

    jQuery.ajax({
      type: 'POST',
      url: 'https://www.starburst.io/wp-admin/admin-ajax.php',
      data: {
        action: 'launch_week_subscribe',
        first: first,
        last: last,
        email: email,
        company: company,
        url: url,
        path: path,
        // heap_user_id: heap_user_id,
      },
      success: function (data) {
        jQuery('#launchWeekSubscribe').html(
          '<p style="color: #000;font-size: 1.5rem;margin-bottom: 0;">Thanks for signing up!</p>'
        );
      },
      error: function (xhr, ajaxOptions, thrownError) {
        console.log('error', thrownError);
      },
    });
  });
}
