const inputElement = document.getElementById('our_listings_page_input');

// Define the searchAddress function
function searchAddress() {

    const inputValue = inputElement.value.trim();

    axios.get(`https://api.realtytexas.net/v1/cognitive-searches/address/${inputValue}?filter="rtlist eq true and search.in(MlsStatus, 'Active,Incomplete,ActiveUnderContract,ComingSoon,Pending,Contingent', ',')"`)
        .then(response => {
            let searchBlock = document.getElementById('searchResults');

            searchBlock.style.display = "block";

            let address = document.getElementById('noAddresses');

            let htmlAddress = '';

            // Address
            response.data.address.forEach((item, index) => {
                htmlAddress += `
                        <a
                            href="` + item.subdomain + item.url.substring(0, item.url.length - 5) + `"
                        >
                        <h6>
                        ` +
                    item.Address +
                    `
                        </h6>
                        </a>
                    `;
            });

            address.innerHTML = htmlAddress;
        })
        .catch(error => {
            console.error('Axios error:', error);
        });
}

document.addEventListener("DOMContentLoaded", function() {
    inputElement.addEventListener('input', searchAddress);
});