<?php
$created = can_action('100', 'created');
$edited = can_action('100', 'edited');

$new_employee_html = form_lookup_add_link(
	'user_id',
	base_url('admin/user/create'),
	lang('create') . ' ' . lang('employee'),
	'2xl'
);


$selected_employee_name = !empty($resignations->employee_id) ? $resignations->employee_id : (!empty($employee_id) ? $employee_id : '');
$selected_employee_name_label = null;
$employee_lookup_groups = grouped_staff_lookup_groups();
if (!empty($resignations->employee_id)) {
	$this->db->select('tbl_account_details.fullname, tbl_designations.designations');
	$this->db->from('tbl_account_details');
	$this->db->join('tbl_designations', 'tbl_designations.designations_id = tbl_account_details.designations_id', 'left');
	$this->db->where('tbl_account_details.user_id', $resignations->employee_id);
	$user = $this->db->get()->row();
	if (!empty($user)) {
		$selected_employee_name_label = $user->fullname . (!empty($user->designations) ? ' (' . $user->designations . ')' : '');
	}
}

if (!empty($created) || !empty($edited)) {
?>
	<div class="panel panel-custom">
		<div class="modal-body wrap-modal wrap">
			<?php echo form_open(base_url('admin/resignation/save_resignation/' . (!empty($resignations->id) ? $resignations->id : '')), array('class' => 'p-6 space-y-6 ', 'enctype' => 'multipart/form-data', 'data-parsley-validate' => 'true', 'role' => 'form')); ?>

			<div class="grid gap-8">
				<!-- Main columns -->
				<div class="lg:col-span-2 space-y-4">

					<div class="bg-slate-50 p-4 rounded-xl border border-slate-200 dark:bg-slate-800 dark:border-slate-700">
						<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
							<?= form_grouped_lookup_group('employee_id', lang('employee'), $employee_lookup_groups, $selected_employee_name, $selected_employee_name_label, true, array(), '', array('append' => $new_employee_html, 'helper' => 'Select an employee by department or search directly.')); ?>
							<?= form_datepicker('notice_date', lang('notice_date'), !empty($resignations->notice_date) ? date('Y-m-d', safe_strtotime($resignations->notice_date)) : '', true); ?>
							<?= form_datepicker('resignation_date', lang('resignation_date'), !empty($resignations->resignation_date) ? date('Y-m-d', safe_strtotime($resignations->resignation_date)) : '', true); ?>
							
							<?= form_textarea_group('description', lang('description'), !empty($resignations->description) ? $resignations->description : '', 4); ?>
						
						</div>
						<div class="flex items-center gap-2 mt-6">
							<?= btn_update(!empty($resignations) ? lang('updates') : lang('save'), 'md') ?>

						</div>
					</div>

					<?php echo form_close(); ?>
				</div>
			</div>
		</div>
	</div>
<?php } ?>
