<?php
/**
 * Template to display Dashboard Menu.
 *
 * @package voidempo
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

?>
<?php
/**
 * Description: Redirects users if not logged in.
 *
 * @package voidempo
 */

if ( ! is_user_logged_in() ) {
	wp_safe_redirect( wp_login_url() );
	exit;
}
$voidempo_is_manager_admin  = ( current_user_can( 'voidempo_manager_access' ) || current_user_can( 'manage_options' ) ) ?? '';

$voidempo_dashboard_menu = array(
	'dashboard'    => array(
		'label' => 'Dashboard',
		'icon'  => 'fas fa-tachometer-alt',
	),
	'projects'     => array(
		'label' => 'My Projects',
		'icon'  => 'fas fa-folder',
	),
	'voidempo_eod' => array(
		'label' => 'Add EOD',
		'icon'  => 'fas fa-plus-circle',
	),
	'eod_list'     => array(
		'label' => 'EOD Lists',
		'icon'  => 'fas fa-list',
	),
	'task_summary' => array(
		'label' => 'Task Summary',
		'icon'  => 'fas fa-tasks',
	),
	'leave'        => array(
		'label' => 'Apply Leave',
		'icon'  => 'fas fa-calendar-check',
	),
	'eod_summary'  => array(
		'label' => 'EOD Summary',
		'icon'  => 'fas fa-chart-line',
	),
);

if ( $voidempo_is_manager_admin ) {
	$voidempo_dashboard_menu = array_slice( $voidempo_dashboard_menu, 0, 1, true ) +
						array(
							'calendar_view' => array(
								'label' => 'Calendar',
								'icon'  => 'fas fa-calendar-alt',
							),
							'add_projects' => array(
								'label' => 'Projects',
								'icon'  => 'fas fa-folder',
							),
						) +
						array_slice( $voidempo_dashboard_menu, 1, null, true );
}
$voidempo_dashboard_menu = apply_filters( 'voidempo_dashboard_menu_labels', $voidempo_dashboard_menu );

if ( $voidempo_is_manager_admin ) {
	$voidempo_dashboard_menu['users'] = array(
		'label' => 'Users',
		'icon'  => 'fas fa-users',
	);
}
$current_user = wp_get_current_user();
$voidempo_first_name   = $current_user->first_name;
$voidempo_last_name    = $current_user->last_name;

?>

<?php wp_head(); ?>
<div class="dashboard-container-fluid">
	<!-- Sidebar Wrapper -->
	<div class="sidebar-wrapper" id="sidebar-wrapper">
		<!-- Hamburger Button -->
		<div class="openbtn" id="hamburger">
			<span></span><span></span><span></span>
		</div>
		<!-- Sidebar -->
		<div class="sidebar" id="sidebar">
			<input type="hidden" name="security"
				value="<?php echo esc_attr( wp_create_nonce( 'voidempo_dashboard_nonce' ) ); ?>">
			<div class="row">
				<h3 style="margin-top: -50px; padding: 0px 20px;">Dashboard </h3>
			</div>
			<p class="user_name">
				<?php echo 'Welcome ' . esc_html( $voidempo_first_name . ' ' . $voidempo_last_name ); ?>
			</p>
			<hr style="margin: 5px 0px 0px; width: 100%;">
			<?php foreach ( $voidempo_dashboard_menu as $voidempo_key => $voidempo_item ) : ?>
			<a href="<?php echo esc_url( home_url( '/user-dashboard/' . esc_attr( $voidempo_key ) ) ); ?>"
				class="menu-item <?php echo isset( $voidempo_item['submenus'] ) ? 'has-submenu' : ''; ?>"
				data-page="<?php echo esc_attr( $voidempo_key ); ?>">
				<i class="<?php echo esc_attr( $voidempo_item['icon'] ); ?>"></i>
				<span class="menu-label"><?php echo esc_html( $voidempo_item['label'] ); ?></span>
			</a>
			<?php if ( ! empty( $voidempo_item['submenu'] ) && is_array( $voidempo_item['submenu'] ) ) : ?>
					<div class="submenu">
						<?php foreach ( $voidempo_item['submenu'] as $voidempo_sub_key => $voidempo_sub_item ) : ?>
							<a href="<?php echo esc_url( home_url( '/user-dashboard/' . esc_attr( $voidempo_sub_key ) ) ); ?>"
								class="submenu-item"
								data-page="<?php echo esc_attr( $voidempo_sub_key ); ?>">
								<i class="<?php echo esc_attr( $voidempo_sub_item['icon'] ); ?>"></i>
								<span class="menu-label"><?php echo esc_html( $voidempo_sub_item['label'] ); ?></span>
							</a>
						<?php endforeach; ?>
					</div>
				<?php endif; ?>
			<?php endforeach; ?>
				<a class="btn_logout" href="<?php echo esc_url( wp_logout_url( home_url( '/wp-login.php' ) ) ); ?>"  >
				<i class="fa fa-sign-out"></i><span class="menu-label"> Logout</span>
			</a>
		</div>
	</div>

	<!-- Dashboard Content -->
	<div class="dashboard-content" id="dashboard-content">
		<!-- Content goes here -->
	</div>
</div>
<?php wp_footer(); ?>

