<?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($training_info->user_id) ? $training_info->user_id : (!empty($user_id) ? $user_id : '');
$selected_employee_name_label = null;
$employee_lookup_groups = grouped_staff_lookup_groups();
if (!empty($training_info->user_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', $training_info->user_id);
	$user = $this->db->get()->row();
	if (!empty($user)) {
		$selected_employee_name_label = $user->fullname . (!empty($user->designations) ? ' (' . $user->designations . ')' : '');
	}
}


$status_val = !empty($training_info->status) ? $training_info->status : 0;
$performance_val = !empty($training_info->performance) ? $training_info->performance : 0;
$permissionL = !empty($training_info->permission) ? $training_info->permission : null;
	
if (!empty($created) || !empty($edited)) {
?>
	<div class="panel panel-custom">
		<div class="modal-body wrap-modal wrap">
			<?php echo form_open(base_url('admin/training/save_training/' . (!empty($training_info->training_id) ? $training_info->training_id : '')), array('class' => 'p-0 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('user_id', lang('employee'), $employee_lookup_groups, $selected_employee_name, $selected_employee_name_label, true, array(), '', array('append' => $new_employee_html, 'helper' => 'Pick an employee by department or search by name.')); ?>
							<?= form_input_group('training_name', lang('course_training'), (!empty($training_info->training_name) ? $training_info->training_name : ''), 'text', true); ?>
							<?= form_input_group('vendor_name', lang('vendor'), (!empty($training_info->vendor_name) ? $training_info->vendor_name : ''), 'text', true); ?>
							<?= form_input_group('training_cost', lang('training_cost'), (!empty($training_info->training_cost) ? $training_info->training_cost : ''), 'text', true); ?>
							<?= form_datepicker('start_date', lang('start_date'), !empty($training_info->start_date) ? date('Y-m-d', safe_strtotime($training_info->start_date)) : '', true, ['data-min' => '#finish_date', 'data-auto-close' => 'true']); ?>
							<?= form_datepicker('finish_date', lang('finish_date'), !empty($training_info->finish_date) ? date('Y-m-d', safe_strtotime($training_info->finish_date)) : '', true, ['data-min' => '#start_date', 'data-auto-close' => 'true']); ?>
							<?= form_select_group('status', lang('status'), array(
								0 => lang('pending'),
								1 => lang('started'),
								2 => lang('completed'),
								3 => lang('terminated'),
							), $status_val, true, array('multiple' => false, 'data-search' => true)); ?>
							<?= form_select_group('performance', lang('performance'), array(
								0 => lang('not_concluded'),
								1 => lang('satisfactory'),
								2 => lang('average'),
								3 => lang('poor'),
								4 => lang('excellent'),
							), $performance_val, true, array('multiple' => false, 'data-search' => true)); ?>
							<?= form_attachment_group('files[]', lang('attachments'), 'dropzone', [
								'dropzone_id' => 'attachements-files-dropzone',
								'list_id' => 'attachements-files-list',
								'comment' => true
							]); ?>
							<?= form_textarea_group('remarks', lang('remarks'), !empty($training_info->remarks) ? $training_info->remarks : '', 4); ?>
							<?= form_permission_modern($assign_user, $permissionL, lang('assined_to')); ?>
						
						</div>
						<div class="flex items-center gap-2 mt-6">
							<?= btn_update(!empty($training_info) ? lang('updates') : lang('save'), 'md') ?>

						</div>
					</div>

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