<h2><?php _e( 'المحاضرين', 'm7md' ) ?></h2>


<table class="wp-list-table widefat fixed striped pages">
    <thead>
    <tr>
        <td>#</td>
        <td><?php _e( 'الاسم', 'm7md' ) ?></td>
        <td><?php _e( 'عدد الدورات', 'm7md' ) ?></td>
        <td><?php _e( 'البريد الالكتروني', 'm7md' ) ?></td>
        <td><?php _e( 'رقم الجوال', 'm7md' ) ?></td>
        <td>Action</td>
    </tr>
    </thead>
    <tbody id="the-list">
    <?php

    $instructors = get_users(
        array(
            // 'role' => 'editor',
            'meta_query' => array(
                // 'relation' => 'AND',
                array(
                    'key' => 'user_membership',
                    'value' => 'instructor',
                    'compare' => '=='
                ),
            )
        )
    );
    // Array of WP_User objects.
    $instructorsCount = count($instructors);
    if ($instructorsCount) {
        foreach ($instructors as $instructor) {
            $user_id = $instructor->ID;
            ?>
            <tr class="">
                <td>
                    <?php echo $user_id; ?>
                </td>

                <td>
                    <?php echo get_the_author_meta('nickname', $user_id); ?>
                </td>

                <td>
                    <?php
                    echo count_user_posts( $user_id , "courses");
                    ?>
                </td>



                <td>
                    <?php
                     //get_the_author_meta( 'com_email', $user_id );
                    echo $instructor->user_email;
                        echo $instructor->user_cv; 
                    ?>
                </td>

                <td>
                    <?php echo get_the_author_meta('com_mobile', $user_id); ?>
                </td>

                <td>
                    <a class="btn btn-primary"
                       href="<?php echo site_url(); ?>/wp-admin/user-edit.php?user_id=<?php echo $user_id; ?>">
                        <?php _e( 'تعديل', 'm7md' ) ?>
                    </a>



                    <a class="btn btn-danger"
                       href="<?php echo wp_nonce_url("users.php?action=delete&amp;user={$user_id}", 'bulk-users') ?>">
                        <?php _e( ' حذف', 'm7md' ) ?>
                    </a>

                    <label class="switch">
                        <input type="checkbox"
                               class="mycheck"
                               value="<?php echo $user_id ?>"
                            <?php echo (get_field('user_status', 'user_' . $user_id) == 'activate' ? 'checked' : '');?> />
                        <span class="slider"></span>
                    </label>

                </td>


            </tr>


        <?php }
    } ?>


    </tbody>

</table>



<script type="text/javascript">
    jQuery('.mycheck').change(function() {
        if(jQuery(this).is(':checked')){
            var status = 'activate';
        }else{
            var status = 'deactivate';
        }
        var userid = jQuery(this).val();
        jQuery.ajax( {
            type: 'POST',
            url: '<?php echo get_site_url()?>/wp-admin/admin-ajax.php',
            dataType: 'json',
            data: { 'action': 'myFunctionuser', 'status' : status, 'userid' : userid},

            success: function (data) {
console.log(data);
            },
            error: function (data) {
                console.log(data);
            }

        } );
    });

</script>
<style>
    .switch {
        position: relative;
        display: inline-block;
        width: 60px;
        height: 34px;
    }

    .switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }

    .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #ccc;
        -webkit-transition: .4s;
        transition: .4s;
    }

    .slider:before {
        position: absolute;
        content: "";
        height: 26px;
        width: 26px;
        left: 4px;
        bottom: 4px;
        background-color: #fff;
        -webkit-transition: .4s;
        transition: .4s;
    }

    input:checked + .slider {
        background-color: #2196F3;
    }

    input:focus + .slider {
        box-shadow: 0 0 1px #2196F3;
    }

    input:checked + .slider:before {
        -webkit-transform: translateX(26px);
        -ms-transform: translateX(26px);
        transform: translateX(26px);
    }
</style>
