<div class="pageButton">
    <a id="leftArrow"><i class='bx bxs-left-arrow'></i></a>
    {pages}
    <a id="rightArrow"><i class='bx bxs-right-arrow'></i></a>
</div>
<script>
    // Get all elements with the class "pageNumber"
    const pageNumbers = document.querySelectorAll('.pageNumber');
    const activePageElement = document.getElementById('activePage');
    const nextPage = parseInt(activePageElement.getAttribute('data-page')) + 1;
    const previousPage = parseInt(activePageElement.getAttribute('data-page')) - 1;
    const rightArrow = document.getElementById('rightArrow');
    const leftArrow = document.getElementById('leftArrow');

    // Add click event listeners to each page number element
    pageNumbers.forEach(pageNumber => {{
        pageNumber.addEventListener('click', () => {{
            // Get the page number from the data-page attribute
            const page = pageNumber.getAttribute('data-page');
            // Construct the URL with the page number
            const url = `/movie?query_term={query_term}&page=${{page}}`;
            // Redirect to the constructed URL
            window.location.href = url;
        }});
    }});
    if (nextPage > {pageLimit}) {{
        rightArrow.disabled = true;
        rightArrow.classList.add('disabled-button');
    }}
    if (previousPage < 1) {{
        leftArrow.disabled = true;
        leftArrow.classList.add('disabled-button');
    }}
    // Add click event listener to the leftArrow element
    leftArrow.addEventListener('click', () => {{
        // Define the URL to redirect to
        const page = previousPage
        const url = `/movie?query_term={query_term}&page=${{page}}`;
        // Redirect to the specified URL
        window.location.href = url;
    }});
    // Add click event listener to the leftArrow element
    rightArrow.addEventListener('click', () => {{
        // Define the URL to redirect to
        const page = nextPage
        const url = `/movie?query_term={query_term}&page=${{page}}`;
        // Redirect to the specified URL
        window.location.href = url;
    }});
</script>