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

    <div class="copuloo-card">
        <h2 class="copuloo-title">Active Phone Numbers</h2>
        <p class="copuloo-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="copuloo-table-container">
                <table class="copuloo-table">
                    <thead>
                        <tr>
                            <th>Phone Number</th>
                            <th>User</th>
                            <th class="actions">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ($copuloo_records as $copuloo_record) :
                        ?>
                            <tr>
                                <td><?php echo esc_html($copuloo_record->managed_number_code . ' ' . copuloo_formatNumber($copuloo_record->managed_number)); ?></td>
                                <td><?php echo esc_html(get_user_by( 'id', $copuloo_record->user )->user_login); ?></td>
                                <td class="actions">
                                    <button onclick="window.location.href='<?php echo esc_url(admin_url('admin.php?page=copuloo_remove&phonenumbercode='.$copuloo_record->managed_number_code.'&phonenumber='.$copuloo_record->managed_number))?>'" type="button" class="copuloo-button copuloo-primary"><span class="dashicons dashicons-trash"></span></button>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
    </div>

</div>



