<?php
$uploaded_file = [];
if (!empty($training_info->upload_file)) {
	$uploaded_file = json_decode($training_info->upload_file);
}

$show_custom_fields = custom_form_label(15, $training_info->training_id);

$curency = $this->db->where('code', config_item('default_currency'))
	->get('tbl_currencies')->row();
?>

<div class="mx-auto max-w-5xl space-y-4">
	<div class="rounded-2xl bg-gradient-to-r from-emerald-500 via-sky-500 to-indigo-500 p-[1px] shadow-lg">
		<div class="rounded-2xl bg-white p-4 dark:bg-gray-800">
			<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
				<div>
					<p class="text-xs font-semibold uppercase tracking-[0.2em] text-emerald-600 dark:text-emerald-300">
						<?= lang('course_training') ?>
					</p>
					<p class="mt-1 text-lg font-semibold text-gray-900 dark:text-white">
						<?= $training_info->training_name ?>
					</p>
				</div>
				<div class="flex flex-wrap items-center gap-3">
					<div class="rounded-lg bg-emerald-50 px-3 py-2 text-sm text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200">
						<?= lang('start_date') ?>: <?= display_date($training_info->start_date) ?>
					</div>
					<div class="rounded-lg bg-sky-50 px-3 py-2 text-sm text-sky-700 dark:bg-sky-900/40 dark:text-sky-200">
						<?= lang('finish_date') ?>: <?= display_date($training_info->finish_date) ?>
					</div>
					<a href="<?= base_url('admin/training/training_letter_pdf/' . $training_info->training_id) ?>" class="inline-flex items-center gap-2 rounded-lg bg-indigo-600 px-3 py-2 text-xs font-semibold text-white transition hover:bg-indigo-700">
						<i data-lucide="file-text" class="h-4 w-4"></i>
						<span><?= lang('pdf') ?></span>
					</a>
					<a href="<?= base_url('admin/training/training_letter_print/' . $training_info->training_id) ?>" target="_blank" class="inline-flex items-center gap-2 rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-semibold text-gray-700 transition hover:bg-gray-50 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-200 dark:hover:bg-gray-800">
						<i data-lucide="printer" class="h-4 w-4"></i>
						<span><?= lang('print') ?></span>
					</a>
					<a href="<?= base_url('admin/training/send_training_letter/' . $training_info->training_id) ?>" class="inline-flex items-center gap-2 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs font-semibold text-emerald-700 transition hover:bg-emerald-100 dark:border-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-200 dark:hover:bg-emerald-900/40">
						<i data-lucide="mail" class="h-4 w-4"></i>
						<span><?= lang('email') ?></span>
					</a>
				</div>
			</div>
		</div>
	</div>

	<div class="grid grid-cols-1 gap-4 lg:grid-cols-12">
		<div class="space-y-4 lg:col-span-4">
			<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
				<p class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
					<?= lang('employee') ?>
				</p>
				<p class="mt-1 text-sm font-medium text-gray-800 dark:text-gray-100">
					<?php
					if (!empty($training_info->employment_id)) {
						echo $training_info->fullname . ' (' . $training_info->employment_id . ')';
					}
					?>
				</p>
			</div>

			<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
				<p class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
					<?= lang('vendor') ?>
				</p>
				<p class="mt-1 text-sm font-medium text-gray-800 dark:text-gray-100">
					<?= $training_info->vendor_name ?>
				</p>
			</div>

			<?php if (!empty($training_info->training_cost)) : ?>
				<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
					<p class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
						<?= lang('training_cost') ?>
					</p>
					<p class="mt-1 text-sm font-medium text-gray-800 dark:text-gray-100">
						<?= display_money($training_info->training_cost, $curency->symbol); ?>
					</p>
				</div>
			<?php endif; ?>

			<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
				<p class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
					<?= lang('status') ?>
				</p>
				<?php
				$statusClasses = [
					'0' => 'bg-yellow-100 text-yellow-800',
					'1' => 'bg-blue-100 text-blue-800',
					'2' => 'bg-green-100 text-green-800',
					'3' => 'bg-red-100 text-red-800',
				];
				?>
				<span class="mt-2 inline-flex items-center rounded px-2 py-1 text-xs <?= $statusClasses[$training_info->status] ?? 'bg-gray-100 text-gray-700' ?>">
					<?= lang(['pending', 'started', 'completed', 'terminated'][$training_info->status] ?? '') ?>
				</span>
			</div>

			<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
				<p class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
					<?= lang('performance') ?>
				</p>
				<?php
				$perfClasses = [
					'0' => 'bg-yellow-100 text-yellow-800',
					'1' => 'bg-blue-100 text-blue-800',
					'2' => 'bg-indigo-100 text-indigo-800',
					'3' => 'bg-red-100 text-red-800',
					'4' => 'bg-green-100 text-green-800',
				];
				?>
				<span class="mt-2 inline-flex items-center rounded px-2 py-1 text-xs <?= $perfClasses[$training_info->performance] ?? 'bg-gray-100 text-gray-700' ?>">
					<?= lang(['not_concluded', 'satisfactory', 'average', 'poor', 'excellent'][$training_info->performance] ?? '') ?>
				</span>
			</div>
		</div>

		<div class="space-y-4 lg:col-span-8">
			<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
				<p class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
					<?= lang('attachment') ?>
				</p>
				<?php if (!empty($uploaded_file)) : ?>
					<ul class="mt-3 grid grid-cols-1 gap-3 sm:grid-cols-2">
						<?php foreach ($uploaded_file as $fKey => $v_files) :
							if (!empty($v_files)) :
					?>
								<li class="rounded-lg border border-gray-200 bg-gray-50 p-3 dark:border-gray-700 dark:bg-gray-900">
									<div class="flex items-center gap-3">
										<?php if ($v_files->is_image == 1) : ?>
											<img src="<?= base_url() . $v_files->path ?>" class="h-12 w-12 rounded-md object-cover ring-1 ring-gray-200 dark:ring-gray-600">
										<?php else : ?>
											<div class="flex h-12 w-12 items-center justify-center rounded-md bg-gray-200 text-xs font-semibold text-gray-700 dark:bg-gray-700 dark:text-gray-100">FILE</div>
										<?php endif; ?>

										<div class="min-w-0 flex-1">
											<a href="<?= base_url() ?>admin/training/download_file/<?= $training_info->training_id . '/' . $fKey ?>" class="block truncate text-sm font-semibold text-indigo-600 hover:underline dark:text-indigo-300">
												<?= $v_files->fileName ?>
											</a>
											<div class="mt-1 flex items-center justify-between text-xs text-gray-500 dark:text-gray-400">
												<span><?= $v_files->size ?> <?= lang('kb') ?></span>
												<a href="<?= base_url() ?>admin/training/download_file/<?= $training_info->training_id . '/' . $fKey ?>" class="font-semibold text-indigo-600 dark:text-indigo-300">Download</a>
											</div>
										</div>
									</div>
								</li>
						<?php endif;
						endforeach; ?>
					</ul>
				<?php else : ?>
					<p class="mt-3 text-sm text-gray-500 dark:text-gray-400">No attachments available.</p>
				<?php endif; ?>
			</div>

			<?php if (!empty($show_custom_fields)) : ?>
				<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
					<p class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">Custom Fields</p>
					<div class="mt-3 divide-y divide-gray-200 dark:divide-gray-700">
						<?php foreach ($show_custom_fields as $c_label => $v_fields) :
							if (!empty($v_fields)) :
					?>
								<div class="grid grid-cols-12 gap-2 py-2">
									<div class="col-span-5 text-sm font-medium text-gray-700 dark:text-gray-300"><?= $c_label ?></div>
									<div class="col-span-7 text-sm text-gray-700 dark:text-gray-100"><?= $v_fields ?></div>
								</div>
						<?php endif;
						endforeach; ?>
					</div>
				</div>
			<?php endif; ?>

			<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-800">
				<p class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
					<?= lang('remarks') ?>
				</p>
				<div class="mt-3 rounded-lg border-l-4 border-emerald-500 bg-emerald-50 p-3 text-sm leading-6 text-gray-700 dark:border-emerald-400 dark:bg-emerald-900/20 dark:text-gray-200">
					<?= $training_info->remarks ?>
				</div>
			</div>
		</div>
	</div>
</div>
