// Function to show the pop-up
function showPopup() {
    // Check if it's a mobile device
    const isMobile = window.matchMedia('(max-width: 767px)').matches;

    // Exit the function if it's not a mobile device
    if (!isMobile) {
      return;
    }
    
    const html = `
      <div class="di_t_center di_w_100vw di_clr_w di_p_t_10px" style="height: 120px; background: #2a2a2a; position: fixed; z-index: 1000000; bottom: 0;">
        <div class="" style="display: flex;">
          <h1 class="di_f_s_16px di_m_l_10px" style="flex: 1;">
            Emergency Locksmith Assistance
            </br> at Your Fingertips
          </h1>
          <div id="popupCloseButton" class="rc_mask_icon di_op_7 di_size_25px di_m_r_20px di_bg_w di_d_inline_block di_p_relative" style="top: -2px; left: 3px; mask-image: url(/img/icons/close.svg); -webkit-mask-image: url(/img/icons/close.svg); "></div>
        </div>
        <div class="di_m_t_10px" style="">
          <a class="di_m_t_10px lock_mbl_call_btn lock_mbl_call_btn_popup" href="tel:+442030538733" onClick="saveCallBtnClick('g_ads_popup_bottom');">
              <button class="btn keys_secondary_bg di_clr_w">
                  
                  <span>Call us now</span> 
                  
                      <img class="di_size_25px" style="margin-top: -5px; -webkit-transform: scaleX(-1); transform: scaleX(-1);" src="/img/icons/phone_w.svg">
                  
              </button>
          </a>
        </div>
      </div>
    `;

    const popupElement = document.createElement('div');
    popupElement.innerHTML = html;
    document.body.appendChild(popupElement);

  // Add click event listener to the close button
  const closeButton = popupElement.querySelector('#popupCloseButton');
  closeButton.addEventListener('click', () => {
    document.body.removeChild(popupElement); // Remove the popup when the close button is clicked
  });

    console.log("Pop-up displayed!");
  }
  
  // Check if the URL contains "gclid"
  function checkGclidInUrl(url) {
    return url.includes("gclid");
  }
  
  // Function to initialize the pop-up
  function initializePopup() {
    // Check if the URL contains "gclid"
    const hasGclid = checkGclidInUrl(window.location.href);
  
    // Show the pop-up after 10 seconds if the URL contains "gclid"
    if (hasGclid) {
      setTimeout(showPopup, 6000);
    }
  }

  document.addEventListener("DOMContentLoaded", function() {
    initializePopup();
  });

  // Export the initializePopup function
  export { initializePopup };
  