<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>AUREN - Buyer Available Dashboard</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <style>
        body {
            background-color: #f8f9fa;
            font-family: 'Segoe UI', sans-serif;
            padding: 2rem;
        }

        .card {
            border: none;
            border-radius: 1rem;
            box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.05);
        }

        h1 {
            margin-bottom: 2rem;
        }
    </style>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap');

        * {
            font-family: "Ubuntu", sans-serif;
            font-weight: 400;
            font-style: normal;
        }

        .rejected {
            color: red;
        }
    </style>
</head>
<?php
$us_states = [
    'AL' => 'Alabama',
    'AK' => 'Alaska',
    'AZ' => 'Arizona',
    'AR' => 'Arkansas',
    'CA' => 'California',
    'CO' => 'Colorado',
    'CT' => 'Connecticut',
    'DE' => 'Delaware',
    'FL' => 'Florida',
    'GA' => 'Georgia',
    'HI' => 'Hawaii',
    'ID' => 'Idaho',
    'IL' => 'Illinois',
    'IN' => 'Indiana',
    'IA' => 'Iowa',
    'KS' => 'Kansas',
    'KY' => 'Kentucky',
    'LA' => 'Louisiana',
    'ME' => 'Maine',
    'MD' => 'Maryland',
    'MA' => 'Massachusetts',
    'MI' => 'Michigan',
    'MN' => 'Minnesota',
    'MS' => 'Mississippi',
    'MO' => 'Missouri',
    'MT' => 'Montana',
    'NE' => 'Nebraska',
    'NV' => 'Nevada',
    'NH' => 'New Hampshire',
    'NJ' => 'New Jersey',
    'NM' => 'New Mexico',
    'NY' => 'New York',
    'NC' => 'North Carolina',
    'ND' => 'North Dakota',
    'OH' => 'Ohio',
    'OK' => 'Oklahoma',
    'OR' => 'Oregon',
    'PA' => 'Pennsylvania',
    'RI' => 'Rhode Island',
    'SC' => 'South Carolina',
    'SD' => 'South Dakota',
    'TN' => 'Tennessee',
    'TX' => 'Texas',
    'UT' => 'Utah',
    'VT' => 'Vermont',
    'VA' => 'Virginia',
    'WA' => 'Washington',
    'WV' => 'West Virginia',
    'WI' => 'Wisconsin',
    'WY' => 'Wyoming'
]; ?>

<body>

    <div class="container">
        <h1 class="text-center">
            Auren Buyer Availabe Stats <br>
            <small style="font-size: 35%;">Every color change means the value has been updated</small>
        </h1>

        <div class="row g-4 mb-4">
            <div class="col-md-4">
                <div class="card bg-light">
                    <div class="card-body text-center">
                        <h5 class="card-title">
                            <div style="clear: both;">
                                <select name="asbon_state" id="asbon_state" class="form-control"
                                    style="max-width: 30%; float: left;">
                                    <option value="">State</option>
                                    <?php foreach ($us_states as $abbr => $name): ?>
                                        <option value="<?= $abbr ?>"
                                            <?= (isset($_GET['asbon_state']) && $_GET['asbon_state'] == $abbr) ? 'selected' : '' ?>>
                                            <?= $name ?></option>
                                    <?php endforeach; ?>
                                </select>


                                <input type="text" name="asbon_phone" id="asbon_phone" class="form-control"
                                    placeholder="Phone"
                                    value="<?= isset($_GET['asbon_phone']) ? $_GET['asbon_phone'] : '' ?>"
                                    style="max-width: 48%; float: left;">

                                <a href="#" class="btn btn-primary"
                                    style="max-width: 30%; float: left; margin-left: 10px;"
                                    onclick="AurenCheck(); return false;">Check</a>
                                <input type="number" name="asbon_zipcode" id="asbon_zipcode"
                                    class="form-control hide d-none" placeholder="Zip Code"
                                    value="<?= isset($_GET['asbon_zipcode']) ? $_GET['asbon_zipcode'] : '' ?>"
                                    style="max-width: 30%; float: left;">
                            </div>
                        </h5>

                    </div>
                </div>
            </div>



            <div class="col-12">
                <table class="table table-borded">
                    <tr>
                        <th>ASB ON</th>
                        <td>
                            <div id="buyer_asb_on" style="clear: both;">-</div>
                        </td>
                    </tr>
                    <tr>
                        <th>Auren Health 1 (B)</th>
                        <td>
                            <div id="buyers_available_server_auren2" style="clear: both;">-</div>
                        </td>
                    </tr>
                    <tr>
                        <th>Auren 2 (AV)</th>
                        <td>
                            <div id="buyers_available_server_auren3" style="clear: both;">-</div>
                        </td>
                    </tr>
                    <tr>
                        <th>Auren Health</th>
                        <td>
                            <div id="buyers_available_server_auren" style="clear: both;">-</div>
                        </td>
                    </tr>
                    </tr>
                    <tr>
                        <th>CBM</th>
                        <td>
                            <div id="buyer_asb_cb" style="clear: both;">-</div>
                        </td>
                    </tr>
                </table>
                <script>
                    function getRandomColor() {
                        const letters = '0123456789ABCDEF';
                        let color = '#';
                        for (let i = 0; i < 6; i++) {
                            color += letters[Math.floor(Math.random() * 16)];
                        }
                        return color;
                    }

                    function AurenCheck() {
                        ASBONfetchStatus();
                        AurenFetchStatus2();
                        AurenFetchStatus3();
                        AurenFetchStatus();
                        CBfetchStatus();
                    }

                    function AurenFetchStatus() {
                        ///$('#buyer_aw').html('<div style="">Checking...</div>');
                        state = $("select#state").val();
                        auren_state = $("select#asbon_state").val();
                        auren_zipcode = $("input#asbon_zipcode").val();
                        auren_phone = $("input#asbon_phone").val();
                        buyer_auren_state = $("select#asbon_state").val();

                        $.ajax({
                            url: 'buyers_available_server_auren.php?buyer_auren_state=' + buyer_auren_state +
                                '&state=' + state + '&auren_state=' + auren_state + '&auren_zipcode=' +
                                auren_zipcode +
                                '&auren_phone=' +
                                auren_phone,
                            method: 'GET',
                            dataType: 'json',
                            async: true,
                            beforeSend: function() {
                                //$('#buyer_aw').html('<div style="">&nbsp;</div>');
                            },
                            success: function(response) {
                                //////////////////////////////////////////////
                                $('#buyers_available_server_auren').html(response
                                    .buyers_available_server_auren);
                                $('#buyers_available_server_auren').css('color', getRandomColor());

                                setTimeout(function() {
                                    //ASBONfetchStatus();
                                }, 20 * 1000);
                                // setInterval(fetchStatus, 1000);
                            },
                            error: function() {
                                $('#live-status').text('Error').removeClass().addClass('badge bg-danger');
                            }
                        });
                    }

                    function AurenFetchStatus2() {
                        ///$('#buyer_aw').html('<div style="">Checking...</div>');
                        state = $("select#state").val();
                        auren_state = $("select#asbon_state").val();
                        auren_zipcode = $("input#asbon_zipcode").val();
                        auren_phone = $("input#asbon_phone").val();
                        buyer_auren_state = $("select#asbon_state").val();

                        $.ajax({
                            url: 'buyers_available_server_auren_2.php?buyer_auren_state=' + buyer_auren_state +
                                '&state=' +
                                state + '&auren_state=' + auren_state + '&auren_zipcode=' + auren_zipcode +
                                '&auren_phone=' +
                                auren_phone,
                            method: 'GET',
                            dataType: 'json',
                            async: true,
                            beforeSend: function() {
                                //$('#buyer_aw').html('<div style="">&nbsp;</div>');
                            },
                            success: function(response) {
                                //////////////////////////////////////////////
                                $('#buyers_available_server_auren2').html(response
                                    .buyers_available_server_auren);
                                $('#buyers_available_server_auren2').css('color', getRandomColor());

                                setTimeout(function() {
                                    //ASBONfetchStatus();
                                }, 20 * 1000);
                                // setInterval(fetchStatus, 1000);
                            },
                            error: function() {
                                $('#live-status').text('Error').removeClass().addClass('badge bg-danger');
                            }
                        });
                    }

                    function AurenFetchStatus3() {
                        ///$('#buyer_aw').html('<div style="">Checking...</div>');
                        state = $("select#state").val();
                        auren_state = $("select#asbon_state").val();
                        auren_zipcode = $("input#asbon_zipcode").val();
                        auren_phone = $("input#asbon_phone").val();
                        buyer_auren_state = $("select#asbon_state").val();

                        $.ajax({
                            url: 'buyers_available_server_auren_3.php?buyer_auren_state=' + buyer_auren_state +
                                '&state=' +
                                state + '&auren_state=' + auren_state + '&auren_zipcode=' + auren_zipcode +
                                '&auren_phone=' +
                                auren_phone,
                            method: 'GET',
                            dataType: 'json',
                            async: true,
                            beforeSend: function() {
                                //$('#buyer_aw').html('<div style="">&nbsp;</div>');
                            },
                            success: function(response) {
                                //////////////////////////////////////////////
                                $('#buyers_available_server_auren3').html(response
                                    .buyers_available_server_auren);
                                $('#buyers_available_server_auren3').css('color', getRandomColor());

                                setTimeout(function() {
                                    //ASBONfetchStatus();
                                }, 20 * 1000);
                                // setInterval(fetchStatus, 1000);
                            },
                            error: function() {
                                $('#live-status').text('Error').removeClass().addClass('badge bg-danger');
                            }
                        });
                    }

                    function ASBONfetchStatus() {
                        // return false;
                        ///$('#buyer_aw').html('<div style="">Checking...</div>');
                        state = $("select#state").val();
                        asbon_state = $("select#asbon_state").val();
                        asbon_zipcode = $("input#asbon_zipcode").val();
                        asbon_phone = $("input#asbon_phone").val();
                        buyer_auren_state = $("select#asbon_state").val();

                        $.ajax({
                            url: 'buyers_available_server_abs_on.php?buyer_auren_state=' + buyer_auren_state +
                                '&state=' +
                                state + '&asbon_state=' + asbon_state + '&asbon_zipcode=' + asbon_zipcode +
                                '&asbon_phone=' +
                                asbon_phone,
                            method: 'GET',
                            dataType: 'json',
                            async: true,
                            beforeSend: function() {
                                //$('#buyer_aw').html('<div style="">&nbsp;</div>');
                            },
                            success: function(response) {
                                // $('#buyer_aw').text(response.buyer_aw).css('color', getRandomColor());
                                // $('#buyer_asb').text(response.buyer_asb).css('color', getRandomColor());
                                $('#buyer_asb_on').text(response.buyer_asb_on).css('color', getRandomColor());
                                // $('#buyer_asb_test').text(response.buyer_asb_test).css('color', getRandomColor());
                                //////////////////////////////////////////////
                                // $('#buyer_asb_state').html(response.buyer_asb_state);
                                // $('#buyer_asb_state p').each(function() {
                                //     $(this).css('color', getRandomColor());
                                // });
                                //////////////////////////////////////////////
                                // $('#buyer_auren').html(response.buyer_auren);
                                // $('#buyer_auren th').each(function() {
                                //     $(this).css('color', getRandomColor());
                                // });
                                setTimeout(function() {
                                    //ASBONfetchStatus();
                                }, 20 * 1000);
                                // setInterval(fetchStatus, 1000);
                            },
                            error: function() {
                                $('#live-status').text('Error').removeClass().addClass('badge bg-danger');
                            }
                        });
                    }

                    function CBfetchStatus() {
                        // return false;
                        ///$('#buyer_aw').html('<div style="">Checking...</div>');
                        state = $("select#state").val();
                        asbon_state = $("select#asbon_state").val();
                        asbon_zipcode = $("input#asbon_zipcode").val();
                        asbon_phone = $("input#asbon_phone").val();
                        buyer_auren_state = $("select#asbon_state").val();

                        $.ajax({
                            url: 'buyers_available_server_cb.php?buyer_auren_state=' + buyer_auren_state +
                                '&state=' +
                                state + '&asbon_state=' + asbon_state + '&asbon_zipcode=' + asbon_zipcode +
                                '&asbon_phone=' +
                                asbon_phone,
                            method: 'GET',
                            dataType: 'json',
                            async: true,
                            beforeSend: function() {
                                //$('#buyer_aw').html('<div style="">&nbsp;</div>');
                            },
                            success: function(response) {
                                // $('#buyer_aw').text(response.buyer_aw).css('color', getRandomColor());
                                // $('#buyer_asb').text(response.buyer_asb).css('color', getRandomColor());
                                $('#buyer_asb_cb').html(response.buyer_asb_cb).css('color', getRandomColor());
                                // $('#buyer_asb_test').text(response.buyer_asb_test).css('color', getRandomColor());
                                //////////////////////////////////////////////
                                // $('#buyer_asb_state').html(response.buyer_asb_state);
                                // $('#buyer_asb_state p').each(function() {
                                //     $(this).css('color', getRandomColor());
                                // });
                                //////////////////////////////////////////////
                                // $('#buyer_auren').html(response.buyer_auren);
                                // $('#buyer_auren th').each(function() {
                                //     $(this).css('color', getRandomColor());
                                // });
                                setTimeout(function() {
                                    //ASBONfetchStatus();
                                }, 20 * 1000);
                                // setInterval(fetchStatus, 1000);
                            },
                            error: function() {
                                $('#live-status').text('Error').removeClass().addClass('badge bg-danger');
                            }
                        });
                    }
                </script>
            </div>

        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>