<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php
global $wpdb;
$dialbunny_records = $wpdb->get_results("SELECT id, managed_number_code, managed_number, user FROM {$wpdb->prefix}dialbunny_phone_details WHERE managed_number_code != '' AND managed_number != '' LIMIT 100"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
?>
<div class="dialbunny-admin-wrap">
    <?php if (empty($dialbunny_records)) { echo wp_kses_post('<div class="dialbunny-notice dialbunny-notice-info"><p><strong>No Active Phone Numbers Were Found!</strong> You can request a phone number directly from the DialBunny dashboard or manually import one through the admin settings.</p><button class="dialbunny-notice-dismiss">Dismiss</button></div>'); }  ?>

    <div class="dialbunny-card">
        <h2 class="dialbunny-title">Active Phone Numbers</h2>
        <p class="dialbunny-description">The active phone numbers table below displays all phone numbers that are in use among different WordPress users. This does not include released phone numbers.</p>
        <div class="dialbunny-table-container">
                <table class="dialbunny-table">
                    <thead>
                        <tr>
                            <th>Phone Number</th>
                            <th>User</th>
                            <th class="actions">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ($dialbunny_records as $dialbunny_record) :
                        ?>
                            <tr>
                                <td><?php echo esc_html($dialbunny_record->managed_number_code . ' ' . dialbunny_formatNumber($dialbunny_record->managed_number)); ?></td>
                                <td><?php echo esc_html(get_user_by( 'id', $dialbunny_record->user )->user_login); ?></td>
                                <td class="actions">
                                    <button onclick="window.location.href='<?php echo esc_url(admin_url('admin.php?page=dialbunny_remove&phonenumbercode='.$dialbunny_record->managed_number_code.'&phonenumber='.$dialbunny_record->managed_number))?>'" type="button" class="dialbunny-button dialbunny-primary"><span class="dashicons dashicons-trash"></span></button>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
    </div>

</div>



