<?php 

function support_cb() {
	global $app;
	global $post_meta;
	$user_meta = $app->user_meta;
	$msg = MessagingOps::getInstance();
	$user = new user;
	$admin_staff = get_select_options_from_user(['role' => 'admin', 'status' => 'active']);
	$super_admin_staff = get_select_options_from_user(['role' => 'super_admin', 'status' => 'active']);
	$teacher = get_select_options_from_user(['role' => 'teacher', 'status' => 'active']);
	$students = get_select_options_from_user(['role' => 'student', 'status' => 'active']);
	$recipients = ['SUPER ADMINISTRATORS' => $super_admin_staff, 'ADMINISTRATORS' => $admin_staff, 'TEACHERS' => $teacher, 'STUDENTS' => $students];
	$last_massages = $msg->get_last_messages();
	?>
	<link rel="stylesheet" href="https://unpkg.com/simplebar@latest/dist/simplebar.min.css" />
	<div class="modal fade" id="mediumModal" tabindex="-1" role="dialog" aria-labelledby="mediumModalLabel" aria-hidden="true">
	    <div class="modal-dialog modal-lg" role="document">
	        <div class="modal-content">
	            <div class="modal-header">
	                <h5 class="modal-title" id="mediumModalLabel">New Chat</h5>
	                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
	                    <span aria-hidden="true">&times;</span>
	                </button>
	            </div>
	            <form id="new_chat_form" method="post">
	            <div class="modal-body">
	                	<?php 
	                	alert();
	                	selectgrp(['label' => 'Receiver', 'id' => 'receiver', 'class' => 'standardSelect', "tabindex"=>"1"], $recipients); 
	                	textarea(['label' => 'Message', 'id' => 'new_message']);
	                	?>
	            </div>
	            <div class="modal-footer">
	            	<input type="hidden" name="action" value="new_chat">
	                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
	                <button type="button" class="btn btn-primary" id="submit_new"><i class="fa fa-paper-plane" aria-hidden="true"></i>&nbsp;Send</button>
	            </div>
	            </form>
	        </div>
	    </div>
	</div>
<link rel="stylesheet" type="text/css" href="<?php echo messaging::$plugin_root ?>\css\support.css">
<div id="chat-body">
	<div id="frame">
		<div id="sidepanel">
			<div id="profile">
				<div class="wrap">
					<img id="profile-img" src="<?php echo get_user_image($user_meta['id']); ?>" class="online" alt="" />
					<p><?php echo get_fullname($user_meta, true); ?></p>
					<i class="fa fa-chevron-down expand-button" aria-hidden="true"></i>
					<div id="status-options">
						<ul>
							<li id="status-online" class="active"><span class="status-circle"></span> <p>Online</p></li>
							<li id="status-away"><span class="status-circle"></span> <p>Away</p></li>
							<li id="status-busy"><span class="status-circle"></span> <p>Busy</p></li>
							<li id="status-offline"><span class="status-circle"></span> <p>Offline</p></li>
						</ul>
					</div>
					<!-- <div id="expanded">
						<label for="twitter"><i class="fa fa-facebook fa-fw" aria-hidden="true"></i></label>
						<input name="twitter" type="text" value="mikeross" />
						<label for="twitter"><i class="fa fa-twitter fa-fw" aria-hidden="true"></i></label>
						<input name="twitter" type="text" value="ross81" />
						<label for="twitter"><i class="fa fa-instagram fa-fw" aria-hidden="true"></i></label>
						<input name="twitter" type="text" value="mike.ross" />
					</div> -->
				</div>
			</div>
			<div id="search">
				<label for=""><i class="fas fa-search" aria-hidden="true"></i></label>
				<input type="text" placeholder="Search contacts..." />
			</div>
			<div id="contacts" data-simplebar>
				<ul>
					<?php if($last_massages): foreach ($last_massages as $last_msg_meta): 
						$second_party = ($last_msg_meta['sender'] == $user_meta['id']) ? $last_msg_meta['receiver'] : $last_msg_meta['sender'];
					?>
					<li class="contact" data-trend="<?php echo $last_msg_meta['trend'] ?>" data-id="<?php echo $user_meta['id'] ?>">
						<div class="wrap">
							<span class="contact-status online"></span>
							<img src="<?php echo get_user_image($second_party); ?>" alt="pix" />
							<div class="meta">
								<p class="name"><?php echo get_fullname($second_party); ?></p>
								<p class="preview"><?php echo ($last_msg_meta['sender'] == $user_meta['id']) ? 'You: ' : ''; echo $last_msg_meta['message']; ?></p>
							</div>
						</div>
					</li>
					<?php endforeach; endif; ?>
				</ul>
			</div>
			<div id="bottom-bar">
				<!-- <button id="addcontact"><i class="fa fa-user-plus fa-fw" aria-hidden="true"></i> <span>Add contact</span></button> -->
				<button id="settings"  type="button" class="btn btn-secondary mb-1" data-toggle="modal" data-target="#mediumModal"><i class="fa fa-envelope fa-fw" aria-hidden="true"></i> <span>New Chat</span></button>
			</div>
		</div>
		<div class="chat-content">
			<div class="contact-profile">
				<img src="images/default-user.png" alt="">
				<p class="fullName"></p>
				<!-- <div class="social-media">
					<i class="fa fa-facebook" aria-hidden="true"></i>
					<i class="fa fa-twitter" aria-hidden="true"></i>
					 <i class="fa fa-instagram" aria-hidden="true"></i>
				</div> -->
			</div>
			<div class="messages">
				<ul>
					
				</ul>
			</div>
			<div class="message-input">
				<div class="wrap">
				<input type="text" placeholder="Write your message..." />
				<!-- <i class="fa fa-paperclip attachment" aria-hidden="true"></i> -->
				<button class="submit"><i class="fa fa-paper-plane" aria-hidden="true"></i></button>
				</div>
			</div>
		</div>
	</div>
</div>
	<?php
	$post_meta['plugin_name'] = messaging::$plugin_name;
	add_page_javascript('contents/plugins/messaging/js/support.js');
	add_page_javascript('contents/plugins/messaging/js/simplebarjs.js');
	add_page_javascript('contents/plugins/messaging/js/new-chat.js');
}