<style>
    .h3
    {
        display: block;
        height: 18.1875px;
        margin: 16.9px 0;
        width: 100%; /* Or 1639px, if a fixed width is required */
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
        font-size: 16.9px;
        font-weight: 600;
        line-height: 18.2px;
        color: rgb(29, 35, 39);
        -webkit-font-smoothing: subpixel-antialiased;
        unicode-bidi: isolate;
    }
</style>
<h3 id="results-heading">Please select your Google Business from the Results:</h3>
<form method="POST" action="" id="place-selection-form">
    <input type="hidden" name="selected_place_id" id="selected_place_id">
    <input type="hidden" name="avg_rating" id="avg_rating">
    <input type="hidden" name="total_reviews" id="total_reviews">
    <input type="hidden" name="business_name" value="<?php echo htmlspecialchars($_POST['business_name']); ?>">
    <table class="table table-striped" id="results-table" style="border: 1px solid #dee2e6; margin: 20px 0;">
        <thead>
            <tr>
                <th>Business Name</th>
                <th>Address</th>
                <th>Average Rating</th>
                <th>Total Reviews</th>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($this->candidates as $candidate)
            {
                if (isset($candidate['place_id']))
                {
                    ?>
                    <tr style="cursor: pointer;"
                        onclick="selectPlace('<?php echo htmlspecialchars($candidate['place_id']); ?>', '<?php echo htmlspecialchars($candidate['rating'] ?? 0); ?>', '<?php echo htmlspecialchars($candidate['user_ratings_total'] ?? 0); ?>')">
                        <td><?php echo htmlspecialchars($candidate['name']); ?></td>
                        <td><?php echo htmlspecialchars($candidate['formatted_address']); ?></td>
                        <td><?php echo htmlspecialchars($candidate['rating']) . ' ⭐' ?></td>
                        <td><?php echo htmlspecialchars($candidate['user_ratings_total']) ?></td>

                    </tr>
                    <?php
                }
            }
            ?>
        </tbody>
    </table>
</form>
<script>
    function selectPlace(placeId, avgRating, totalReviews)
    {
        document.getElementById('selected_place_id').value = placeId;
        document.getElementById('avg_rating').value = avgRating;
        document.getElementById('total_reviews').value = totalReviews;
        document.getElementById('place-selection-form').submit();
    }
</script>