<?php
$not_found = '<div class="col-md-12"><div class="wow_content"><div class="empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M15.5,12C18,12 20,14 20,16.5C20,17.38 19.75,18.21 19.31,18.9L22.39,22L21,23.39L17.88,20.32C17.19,20.75 16.37,21 15.5,21C13,21 11,19 11,16.5C11,14 13,12 15.5,12M15.5,14A2.5,2.5 0 0,0 13,16.5A2.5,2.5 0 0,0 15.5,19A2.5,2.5 0 0,0 18,16.5A2.5,2.5 0 0,0 15.5,14M7,15V17H9C9.14,18.55 9.8,19.94 10.81,21H5C3.89,21 3,20.1 3,19V5C3,3.89 3.89,3 5,3H19A2,2 0 0,1 21,5V13.03C19.85,11.21 17.82,10 15.5,10C14.23,10 13.04,10.37 12.04,11H7V13H10C9.64,13.6 9.34,14.28 9.17,15H7M17,9V7H7V9H17Z" /></svg> ' . $wo["lang"]["no_result"] . '</div></div></div>';
$type_to_find = '<div class="empty_state"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M9.62,12L12,5.67L14.37,12M11,3L5.5,17H7.75L8.87,14H15.12L16.25,17H18.5L13,3H11Z" /></svg> ' . $wo["lang"]["what_are_looking_for"] . '</div>';

$page = isset($_GET['page-id']) ? $_GET['page-id'] : 1;
$filter_keyword = (!empty($_GET['query'])) ? Wo_Secure($_GET['query']) : '';
$db->pageLimit = 20;
$link = '';
$users    = $db->arraybuilder()->orderBy('user_id', 'DESC')->paginate(T_USERS, $page);

?>
<div class="page-margin">
	<div class="page-margin mt-0">
		<div class="wow_content popular_posts_hdr">
			<h2 class="flex">
				<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" class="icon_main" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 13a3 3 0 1 0 0 -6a3 3 0 0 0 0 6z"></path><path d="M6.201 18.744a4 4 0 0 1 3.799 -2.744h4a4 4 0 0 1 3.798 2.741"></path><path d="M19.875 6.27c.7 .398 1.13 1.143 1.125 1.948v7.284c0 .809 -.443 1.555 -1.158 1.948l-6.75 4.27a2.269 2.269 0 0 1 -2.184 0l-6.75 -4.27a2.225 2.225 0 0 1 -1.158 -1.948v-7.285c0 -.809 .443 -1.554 1.158 -1.947l6.75 -3.98a2.33 2.33 0 0 1 2.25 0l6.75 3.98h-.033z"></path></svg>&nbsp;
				<p><?php echo $wo['lang']['welcome_discover'] ?> <?php echo $wo['lang']['users'] ?><b><?php echo($wo['lang']['explore_diverse_community']) ?></b></p>
			</h2>
		</div>
	</div>
	
    <div class="row">
		<div class="col-md-3 leftcol">
			<div class="user_prnt"><?php echo Wo_LoadPage("directory/left-sidebar"); ?></div>
		</div>
		
    <div class="col-md-9 singlecol">
    <div class="wo_search_page">
        <div class="tab-content">
            <div id="users" class="tab-pane fade in active">
                <div id="users-cont" class="row cool-style-album-row wow_frnd_usr">
                    <?php
                        if (count($users) != 0) {
                            foreach ($users as $user) {
                                $wo['result'] = Wo_UserData($user['user_id']);
                                $wo['result'] = (array) $wo['result'];
                                $wo['result']['details'] = (array) $wo['result']['details'];

                                if (!empty($wo['result']['avatar'])) {
                                    $wo['result']['avatar'] = Wo_GetMedia($wo['result']['avatar_full']);
                                }
                                echo Wo_LoadPage('search/user-result');
                            }
                        } else {
                            echo $not_found;
                        }
                    ?>
                </div>
                <div class="clear"></div>
                <?php if (!empty($users)) { ?>
                    <div class="wo-admincp-feturepager">
                        <div class="">
                        <span>
                          <?php echo "Showing $page out of " . $db->totalPages; ?>
                        </span>
                        </div>
                        <div class="">
                            <nav>
                                <ul class="pagination">
                                    <li>
                                        <a href="<?php echo Wo_Link('directory/users?page-id=1').$link; ?>" data-ajax="?link1=directory-users&page-id=1<?php echo($link); ?>" class="waves-effect" title='First Page'>
                                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M11 7l-5 5l5 5"></path><path d="M17 7l-5 5l5 5"></path></svg>
                                        </a>
                                    </li>
                                    <?php if ($page > 1) {  ?>
                                        <li>
                                            <a href="<?php echo Wo_Link('directory/users?page-id=' . ($page - 1)).$link; ?>"  data-ajax="?link1=directory-users&page-id=<?php echo($page - 1).$link; ?>" class="waves-effect" title='Previous Page'>
                                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M15 6l-6 6l6 6"></path></svg>
                                            </a>
                                        </li>
                                    <?php  } ?>

                                    <?php
                                    $nums       = 0;
                                    $nums_pages = ($page > 4) ? ($page - 4) : $page;

                                    for ($i=$nums_pages; $i <= $db->totalPages; $i++) {
                                        if ($nums < 20) {
                                            ?>
                                            <li class="<?php echo ($page == $i) ? 'active' : ''; ?>">
                                                <a href="<?php echo Wo_Link('directory/users?page-id=' . ($i)).$link; ?>"  data-ajax="?link1=directory-users&page-id=<?php echo($i).$link; ?>" class="waves-effect">
                                                    <?php echo $i ?>
                                                </a>
                                            </li>

                                        <?php } $nums++; }?>

                                    <?php if ($db->totalPages > $page) { ?>
                                        <li>
                                            <a href="<?php echo Wo_Link('directory/users?page-id=' . ($page + 1)).$link; ?>" data-ajax="?link1=directory-users&page-id=<?php echo($page + 1).$link; ?>"  class="waves-effect" title="Next Page">
                                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M9 6l6 6l-6 6"></path></svg>
                                            </a>
                                        </li>
                                    <?php } ?>
                                    <li>
                                        <a href="<?php echo Wo_Link('directory/users?page-id=' . ($db->totalPages)).$link; ?>" data-ajax="?link1=directory-users&page-id=<?php echo($db->totalPages) ?><?php echo($link); ?>" class="waves-effect" title='Last Page'>
                                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 7l5 5l-5 5"></path><path d="M13 7l5 5l-5 5"></path></svg>
                                        </a>
                                    </li>
                                </ul>
                            </nav>
                        </div>
                    </div>
                <?php } ?>
            </div>




        </div>
        <div class="clear"></div>
    </div>
    </div></div>
</div>

<script>
    $('.wow_main_blogs_bg').css('height', ($('.wow_main_float_head').height()) + 'px');

    $(document).on('click', '.wow_srch_drp_mnu', function (e) {
        e.stopPropagation();
    });

    jQuery(document).ready(function($) {
        //Load more users
        $(".load-more-users").click(function(event) {
            var form = document.getElementById('search_form');
            var formdata = new FormData(form);
            var u_offset = ($("[data-search-type=user]").length > 0) ? $("[data-search-type=user]").last().attr('data-id') : 0;
            $.ajax({
                processData: false,
                url: Wo_Ajax_Requests_File()+'?f=load-more-users&offset='+u_offset,
                type: 'POST',
                dataType: 'json',
                data: formdata,
                contentType: false,
                success:function(data){
                    if (data['status'] == 200) {
                        $("#users-cont").append(data['html'])
                    }else{$(".load-more-users").remove()}
                }
            })
        });
        //Load more groups
        $(".load-more-groups").click(function(event) {
            var g_offset = ($("[data-search-type=group]").length > 0) ? $("[data-search-type=group]").last().attr('data-id') : 0;
            $.ajax({
                url: Wo_Ajax_Requests_File(),
                type: 'GET',
                dataType: 'json',
                data: {f: 'load-more-groups',offset:g_offset,query:$("#query").val()},
                success:function(data){
                    if (data['status'] == 200) {
                        $("#groups-cont").append(data['html'])
                    }else{$(".load-more-groups").remove()}
                }
            })
        });
        //Load more pages
        $(".load-more-pages").click(function(event) {
            var p_offset = ($("[data-search-type=page]").length > 0) ? $("[data-search-type=page]").last().attr('data-id') : 0;
            $.ajax({
                url: Wo_Ajax_Requests_File(),
                type: 'GET',
                dataType: 'json',
                data: {f: 'load-more-pages',offset:p_offset,query:$("#query").val()},
                success:function(data){
                    if (data['status'] == 200) {
                        $("#pages-cont").append(data['html'])
                    }else{$(".load-more-pages").remove()}
                }
            })
        });


        $("#input").hover(function(event) {
            $("#input").focus()
        });

    });
</script>