<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php
$edited = can_action('24', 'edited');
$role_label = '';
if (!empty($user_info)) {
	if ((int) $user_info->role_id === 1) {
		$role_label = lang('admin');
	} elseif ((int) $user_info->role_id === 3) {
		$role_label = lang('staff');
	} else {
		$role_label = lang('client');
	}
}
$department_name = !empty($department->deptname) ? $department->deptname : lang('undefined_department');
$designation_name = !empty($designation->designations) ? $designation->designations : '';

$avatar = base_url() . staffImage($profile_info->user_id);
$project_hours = $this->user_model->get_time_spent_result($project_time);
$task_hours = $this->user_model->get_time_spent_result($task_time);
?>

<div class="space-y-6">
	<?= message_box('success'); ?>
	<?= message_box('error'); ?>

	<div class="rounded-2xl border border-border bg-card p-6 shadow-sm">
		<div class="flex flex-col gap-6 lg:flex-row lg:items-center lg:justify-between">
			<div class="flex items-center gap-4">
				<img src="<?= $avatar; ?>" alt="<?= html_escape($profile_info->fullname); ?>" class="h-16 w-16 rounded-full border border-border object-cover">
				<div>
					<h2 class="text-xl font-semibold text-foreground"><?= html_escape($profile_info->fullname); ?></h2>
					<p class="text-sm text-muted-foreground">
						<?= lang('emp_id'); ?>: <?= html_escape($profile_info->employment_id); ?>
						<?php if (!empty($role_label)) { ?>
							<span class="text-muted-foreground">•</span> <?= html_escape($role_label); ?>
						<?php } ?>
					</p>
					<p class="text-sm text-muted-foreground">
						<?= html_escape($department_name); ?>
						<?php if (!empty($designation_name)) { ?>
							<span class="text-muted-foreground">•</span> <?= html_escape($designation_name); ?>
						<?php } ?>
					</p>
				</div>
			</div>
			<?php if (!empty($edited)) { ?>
				<div class="flex items-center gap-2">
					<?= btn_edit('admin/user/create/edit_user/' . $profile_info->user_id); ?>
				</div>
			<?php } ?>
		</div>
	</div>

	<div class="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('open') . ' ' . lang('project'); ?></p>
			<p class="mt-3 text-xl font-bold text-foreground"><?= $project_stats['open']; ?></p>
			<a href="<?= base_url('admin/projects'); ?>" class="mt-2 inline-flex text-xs font-semibold text-primary hover:underline"><?= lang('more_info'); ?></a>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('complete') . ' ' . lang('project'); ?></p>
			<p class="mt-3 text-xl font-bold text-foreground"><?= $project_stats['completed']; ?></p>
			<a href="<?= base_url('admin/projects/create/completed'); ?>" class="mt-2 inline-flex text-xs font-semibold text-primary hover:underline"><?= lang('more_info'); ?></a>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('open') . ' ' . lang('tasks'); ?></p>
			<p class="mt-3 text-xl font-bold text-foreground"><?= $task_stats['open']; ?></p>
			<a href="<?= base_url('admin/tasks/all_task'); ?>" class="mt-2 inline-flex text-xs font-semibold text-primary hover:underline"><?= lang('more_info'); ?></a>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('complete') . ' ' . lang('tasks'); ?></p>
			<p class="mt-3 text-xl font-bold text-foreground"><?= $task_stats['completed']; ?></p>
			<a href="<?= base_url('admin/tasks/create/completed'); ?>" class="mt-2 inline-flex text-xs font-semibold text-primary hover:underline"><?= lang('more_info'); ?></a>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('monthly') . ' ' . lang('attendance'); ?></p>
			<p class="mt-3 text-xl font-bold text-foreground"><?= $total_attendance; ?> / <?= $total_days; ?></p>
			<a href="<?= base_url('admin/attendance/attendance_report'); ?>" class="mt-2 inline-flex text-xs font-semibold text-primary hover:underline"><?= lang('more_info'); ?></a>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('monthly') . ' ' . lang('leave'); ?></p>
			<p class="mt-3 text-xl font-bold text-foreground"><?= $total_leave; ?></p>
			<a href="<?= base_url('admin/leave_management'); ?>" class="mt-2 inline-flex text-xs font-semibold text-primary hover:underline"><?= lang('more_info'); ?></a>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('monthly') . ' ' . lang('absent'); ?></p>
			<p class="mt-3 text-xl font-bold text-foreground"><?= $total_absent; ?></p>
			<a href="<?= base_url('admin/attendance/attendance_report'); ?>" class="mt-2 inline-flex text-xs font-semibold text-primary hover:underline"><?= lang('more_info'); ?></a>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('total') . ' ' . lang('award'); ?></p>
			<p class="mt-3 text-xl font-bold text-foreground"><?= $total_award; ?></p>
			<a href="<?= base_url('admin/award'); ?>" class="mt-2 inline-flex text-xs font-semibold text-primary hover:underline"><?= lang('more_info'); ?></a>
		</div>
	</div>

	<div class="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('project') . ' ' . lang('hours'); ?></p>
			<p class="mt-3 text-2xl font-bold text-foreground"><?= $project_hours; ?></p>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('tasks') . ' ' . lang('hours'); ?></p>
			<p class="mt-3 text-2xl font-bold text-foreground"><?= $task_hours; ?></p>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('this_month_working') . ' ' . lang('hours'); ?></p>
			<p class="mt-3 text-2xl font-bold text-foreground"><?= $this_month_working_total; ?></p>
		</div>
		<div class="rounded-2xl border border-border bg-card p-4 shadow-sm">
			<p class="text-xs uppercase tracking-widest text-muted-foreground"><?= lang('working') . ' ' . lang('hours'); ?></p>
			<p class="mt-3 text-2xl font-bold text-foreground"><?= $all_working_total; ?></p>
		</div>
	</div>

	<?php $this->load->view('admin/common/tabs'); ?>
</div>
