<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php
$edited = can_action('24', 'edited');
$user_info = isset($user_info) ? $user_info : null;
$designation_name = !empty($designation->designations) ? $designation->designations : '';
$department_name = !empty($department->deptname) ? $department->deptname : '';

$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');
	}
}

$status_badges = array();
if (!empty($user_info)) {
	if (!empty($user_info->activated)) {
		$status_badges[] = '<span class="inline-flex items-center rounded-full bg-emerald-100 px-2 py-0.5 text-xs font-semibold text-emerald-700">' . lang('active') . '</span>';
	} else {
		$status_badges[] = '<span class="inline-flex items-center rounded-full bg-rose-100 px-2 py-0.5 text-xs font-semibold text-rose-700">' . lang('deactive') . '</span>';
	}
	if (!empty($user_info->banned)) {
		$status_badges[] = '<span class="inline-flex items-center rounded-full bg-amber-100 px-2 py-0.5 text-xs font-semibold text-amber-700">' . lang('banned') . '</span>';
	}
}
$status_html = implode(' ', $status_badges);

$fields = array(
	array('label' => lang('emp_id'), 'value' => $profile_info->employment_id),
	array('label' => lang('fullname'), 'value' => $profile_info->fullname),
	array('label' => lang('user_type'), 'value' => $role_label, 'show_empty' => true),
	array('label' => lang('status'), 'html' => $status_html, 'show_empty' => true),
);

if (!empty($department_name)) {
	$fields[] = array('label' => lang('department'), 'value' => $department_name);
}
if (!empty($designation_name)) {
	$fields[] = array('label' => lang('designation'), 'value' => $designation_name);
}

if ($this->session->userdata('user_type') == 1 && !empty($user_info)) {
	$fields[] = array('label' => lang('username'), 'value' => $user_info->username);
	$fields[] = array(
		'label' => lang('password'),
		'html' => btn_modal(
			'admin/user/reset_password/' . $user_info->user_id,
			lang('reset_password'),
			lang('reset_password'),
			'md',
			'',
			array('class' => 'inline-flex items-center justify-center gap-1 rounded-md border border-rose-200 bg-rose-50 px-2.5 py-1.5 text-xs font-semibold text-rose-700 hover:bg-rose-100')
		),

		'show_empty' => true,
	);
}

if (!empty($profile_info->joining_date)) {
	$fields[] = array(
		'label' => lang('joining_date'),
		'value' => display_date($profile_info->joining_date),
	);
}
if (!empty($profile_info->gender)) {
	$fields[] = array('label' => lang('gender'), 'value' => lang($profile_info->gender));
}
if (!empty($profile_info->date_of_birth)) {
	$fields[] = array(
		'label' => lang('date_of_birth'),
		'value' => display_date($profile_info->date_of_birth),
	);
}
if (!empty($profile_info->maratial_status)) {
	$fields[] = array('label' => lang('maratial_status'), 'value' => lang($profile_info->maratial_status));
}
if (!empty($profile_info->father_name)) {
	$fields[] = array('label' => lang('fathers_name'), 'value' => $profile_info->father_name);
}
if (!empty($profile_info->mother_name)) {
	$fields[] = array('label' => lang('mother_name'), 'value' => $profile_info->mother_name);
}
if (!empty($user_info->email)) {
	$fields[] = array('label' => lang('email'), 'value' => $user_info->email);
}
if (!empty($profile_info->phone)) {
	$fields[] = array('label' => lang('phone'), 'value' => $profile_info->phone);
}
if (!empty($profile_info->mobile)) {
	$fields[] = array('label' => lang('mobile'), 'value' => $profile_info->mobile);
}
if (!empty($profile_info->skype)) {
	$fields[] = array('label' => lang('skype_id'), 'value' => $profile_info->skype);
}
if (!empty($profile_info->passport)) {
	$fields[] = array('label' => lang('passport'), 'value' => $profile_info->passport);
}
if (!empty($profile_info->present_address)) {
	$fields[] = array('label' => lang('present_address'), 'value' => $profile_info->present_address);
}

if (!empty($custom_fields)) {
	foreach ($custom_fields as $c_label => $v_fields) {
		if (!empty($v_fields)) {
			$fields[] = array('label' => $c_label, 'value' => $v_fields);
		}
	}
}

$actions = '';
if (!empty($edited)) {
	$actions = btn_modal(
		'admin/user/update_contact/1/' . $profile_info->account_details_id,
		lang('update'),
		lang('update'),
		'lg',
		'',
		array('class' => 'inline-flex items-center justify-center gap-1 rounded-md border border-rose-200 bg-rose-50 px-2.5 py-1.5 text-xs font-semibold text-rose-700 hover:bg-rose-100')
			// array('class' => 'text-primary hover:underline')
	);
}

$this->load->view('admin/common/details_grid', array(
	'title' => $profile_info->fullname,
	'fields' => $fields,
	'actions' => $actions,
));
