<?= message_box('success'); ?>
<?= message_box('error'); ?>
<?php
$created = can_action('88', 'created');
$edited = can_action('88', 'edited');
$appraisal_month_value = '';
if (!empty($appraisal_month)) {
    $appraisal_month_value = $appraisal_month;
} elseif (!empty($get_appraisal_info->appraisal_month)) {
    $appraisal_month_value = $get_appraisal_info->appraisal_month;
}

$technical_indicator_keys = array(
    'customer_experiece_management',
    'marketing',
    'management',
    'administration',
    'presentation_skill',
    'quality_of_work',
    'efficiency',
);
$behavioural_indicator_keys = array(
    'integrity',
    'professionalism',
    'team_work',
    'critical_thinking',
    'conflict_management',
    'attendance',
    'ability_to_meed_deadline',
);
$count_active_indicators = function ($details, $fields) {
    $count = 0;
    if (empty($details)) {
        return $count;
    }
    foreach ($fields as $field) {
        if (!empty($details->$field)) {
            $count++;
        }
    }
    return $count;
};
$technical_indicator_count = $count_active_indicators(!empty($performance_indicator_details) ? $performance_indicator_details : null, $technical_indicator_keys);
$behavioural_indicator_count = $count_active_indicators(!empty($performance_indicator_details) ? $performance_indicator_details : null, $behavioural_indicator_keys);
$selected_employee_name = '';
$selected_employee_role = '';
$selected_employee_id = !empty($get_appraisal_info->user_id) ? $get_appraisal_info->user_id : (!empty($user_id) ? $user_id : '');
$employee_lookup_groups = grouped_staff_lookup_groups();
if (!empty($selected_employee_id) && !empty($employee_lookup_groups)) {
    foreach ($employee_lookup_groups as $group) {
        if (empty($group['items'])) {
            continue;
        }
        foreach ($group['items'] as $employee) {
            if ((string) $employee['id'] === (string) $selected_employee_id) {
                $selected_employee_name = $employee['name'];
                $selected_employee_role = !empty($employee['meta']) ? $employee['meta'] : '';
                break 2;
            }
        }
    }
}
?>

<div class="space-y-4">
    <div class="grid gap-4 xl:grid-cols-[minmax(0,1.4fr)_320px]">
        <div class="rounded-2xl border border-border bg-card shadow-sm">
            <div class="border-b border-border px-5 py-4">
                <div class="flex items-center gap-2 text-sm font-semibold text-foreground">
                    <i data-lucide="users" class="h-5 w-5"></i>
                    <span><?= lang('select') . ' ' . lang('employee') ?></span>
                </div>
            </div>
            <div class="p-5">
                <form role="form" data-parsley-validate="" novalidate=""
                      action="<?php echo base_url() ?>admin/performance/give_performance_appraisal" method="post"
                      class="space-y-4">
                    <div class="grid grid-cols-1 gap-4 md:grid-cols-2">
                        <?= form_grouped_lookup_group(
                            'user_id',
                            lang('employee'),
                            $employee_lookup_groups,
                            $selected_employee_id,
                            $selected_employee_name . (!empty($selected_employee_role) ? ' (' . $selected_employee_role . ')' : ''),
                            true,
                            array('id' => 'employee_lookup_input'),
                            '',
                            array('helper' => 'Search by employee or department while keeping department grouping.')
                        ); ?>
                        <?= form_datepicker(
                            'appraisal_month',
                            lang('select') . ' ' . lang('month'),
                            $appraisal_month_value,
                            true,
                            array(
                                'id' => 'appraisal_month',
                                'data-type' => 'month',
                                'data-format' => 'Y-m',
                                'data-auto-close' => 'true',
                            )
                        ); ?>
                    </div>
                    <div class="flex justify-end">
                        <button id="btn_emp" type="submit"
                                class="inline-flex items-center gap-2 rounded-lg bg-indigo-600 px-4 py-2 text-xs font-semibold text-white shadow-sm hover:bg-indigo-500">
                            <i data-lucide="arrow-right" class="h-4 w-4"></i>
                            <?= lang('go') ?>
                        </button>
                    </div>
                </form>
            </div>
        </div>
        <div class="rounded-2xl border border-border bg-card shadow-sm">
            <div class="border-b border-border px-5 py-4">
                <div class="flex items-center gap-2 text-sm font-semibold text-foreground">
                    <i data-lucide="sparkles" class="h-5 w-5"></i>
                    <span>Appraisal Guidance</span>
                </div>
            </div>
            <div class="space-y-3 p-5 text-sm text-muted-foreground">
                <div class="rounded-xl border border-border bg-background/70 p-4">
                    <p class="font-semibold text-foreground"><?= lang('technical_competency') ?></p>
                    <p class="mt-1">Review role-specific skills, execution quality and functional readiness.</p>
                </div>
                <div class="rounded-xl border border-border bg-background/70 p-4">
                    <p class="font-semibold text-foreground"><?= lang('behavioural_competency') ?></p>
                    <p class="mt-1">Measure collaboration, professionalism, attendance and deadline discipline.</p>
                </div>
                <div class="rounded-xl border border-border bg-background/70 p-4">
                    <p class="font-semibold text-foreground"><?= lang('remarks') ?></p>
                    <p class="mt-1">Capture manager notes for coaching, improvement plans and final feedback.</p>
                </div>
            </div>
        </div>
    </div>
</div>

<?php if (!empty($indicator_flag)) { ?>
    <div class="space-y-4 mt-4">
        <?php if (!empty($appraisal_once_given)) { ?>
            <div class="rounded-lg border border-red-200 bg-red-50 px-4 py-2 text-sm text-red-600 text-center">
                <?= lang('appraisal_already_provided') ?> <?= date('F Y', safe_strtotime($appraisal_month)) ?>
            </div>
        <?php } ?>

        <form role="form" id="give_performance_appraisal"
              action="<?php echo base_url() ?>admin/performance/save_performance_appraisal/<?php
              if (!empty($get_appraisal_info->performance_appraisal_id)) {
                  echo $get_appraisal_info->performance_appraisal_id;
              }
              ?>" method="post" class="space-y-6">
            <div class="rounded-2xl border border-border bg-card shadow-sm">
                <div class="border-b border-border px-5 py-5">
                    <div class="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
                        <div class="flex items-center gap-3">
                            <span class="inline-flex shrink-0 h-11 w-11 items-center justify-center rounded-2xl bg-primary/10 text-primary">
                                <i data-lucide="clipboard-list" class="h-5 w-5"></i>
                            </span>
                            <div>
                                <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">Appraisal Workspace</p>
                                <h3 class="text-lg font-semibold text-foreground"><?= lang('give_performance_appraisal') ?></h3>
                            </div>
                        </div>
                        <div class="grid gap-3 sm:grid-cols-3">
                            <div class="rounded-xl border border-border bg-background/70 px-4 py-3">
                                <p class="text-[11px] font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('employee') ?></p>
                                <p class="mt-1 text-sm font-semibold text-foreground"><?= !empty($selected_employee_name) ? html_escape($selected_employee_name) : lang('not_set') ?></p>
                            </div>
                            <div class="rounded-xl border border-border bg-background/70 px-4 py-3">
                                <p class="text-[11px] font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('technical_competency') ?></p>
                                <p class="mt-1 text-sm font-semibold text-foreground"><?= $technical_indicator_count ?> indicators</p>
                            </div>
                            <div class="rounded-xl border border-border bg-background/70 px-4 py-3">
                                <p class="text-[11px] font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('behavioural_competency') ?></p>
                                <p class="mt-1 text-sm font-semibold text-foreground"><?= $behavioural_indicator_count ?> indicators</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="p-5 space-y-6">
                    <div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
                        <div class="overflow-hidden rounded-2xl border border-border bg-card shadow-sm">
                            <div class="border-b border-border px-4 py-3">
                                <h4 class="text-sm font-semibold text-foreground"><?= lang('technical_competency') ?></h4>
                                <p class="mt-1 text-xs text-muted-foreground">Score each functional competency against the expected proficiency level.</p>
                            </div>
                            <div class="overflow-x-auto p-4">
                                <table class="appraisal-table min-w-full text-left text-sm">
                                    <thead>
                                    <tr>
                                        <th><?= lang('performance_indicator') ?></th>
                                        <th><?= lang('expected_value') ?></th>
                                        <th><?= lang('set_value') ?></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                        <td><?= lang('customer_experience_management') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->customer_experiece_management) && $performance_indicator_details->customer_experiece_management == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->customer_experiece_management) && $performance_indicator_details->customer_experiece_management == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->customer_experiece_management) && $performance_indicator_details->customer_experiece_management == 3) {
                                                echo lang('advanced');
                                            } elseif (!empty($performance_indicator_details->customer_experiece_management) && $performance_indicator_details->customer_experiece_management == 4) {
                                                echo lang('expert_leader');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->customer_experiece_management) && $performance_indicator_details->customer_experiece_management != 0) { ?>
                                                <select name="customer_experiece_management" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->customer_experiece_management) && $get_appraisal_info->customer_experiece_management == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->customer_experiece_management) && $get_appraisal_info->customer_experiece_management == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->customer_experiece_management) && $get_appraisal_info->customer_experiece_management == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                    <option value="4" <?= (!empty($get_appraisal_info->customer_experiece_management) && $get_appraisal_info->customer_experiece_management == 4 ? 'selected' : '') ?>><?= lang('expert_leader') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('marketing') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->marketing) && $performance_indicator_details->marketing == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->marketing) && $performance_indicator_details->marketing == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->marketing) && $performance_indicator_details->marketing == 3) {
                                                echo lang('advanced');
                                            } elseif (!empty($performance_indicator_details->marketing) && $performance_indicator_details->marketing == 4) {
                                                echo lang('expert_leader');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->marketing) && $performance_indicator_details->marketing != 0) { ?>
                                                <select name="marketing" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->marketing) && $get_appraisal_info->marketing == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->marketing) && $get_appraisal_info->marketing == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->marketing) && $get_appraisal_info->marketing == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                    <option value="4" <?= (!empty($get_appraisal_info->marketing) && $get_appraisal_info->marketing == 4 ? 'selected' : '') ?>><?= lang('expert_leader') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('management') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->management) && $performance_indicator_details->management == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->management) && $performance_indicator_details->management == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->management) && $performance_indicator_details->management == 3) {
                                                echo lang('advanced');
                                            } elseif (!empty($performance_indicator_details->management) && $performance_indicator_details->management == 4) {
                                                echo lang('expert_leader');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->management) && $performance_indicator_details->management != 0) { ?>
                                                <select name="management" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->management) && $get_appraisal_info->management == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->management) && $get_appraisal_info->management == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->management) && $get_appraisal_info->management == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                    <option value="4" <?= (!empty($get_appraisal_info->management) && $get_appraisal_info->management == 4 ? 'selected' : '') ?>><?= lang('expert_leader') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('administration') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->administration) && $performance_indicator_details->administration == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->administration) && $performance_indicator_details->administration == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->administration) && $performance_indicator_details->administration == 3) {
                                                echo lang('advanced');
                                            } elseif (!empty($performance_indicator_details->administration) && $performance_indicator_details->administration == 4) {
                                                echo lang('expert_leader');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->administration) && $performance_indicator_details->administration != 0) { ?>
                                                <select name="administration" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->administration) && $get_appraisal_info->administration == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->administration) && $get_appraisal_info->administration == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->administration) && $get_appraisal_info->administration == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                    <option value="4" <?= (!empty($get_appraisal_info->administration) && $get_appraisal_info->administration == 4 ? 'selected' : '') ?>><?= lang('expert_leader') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('presentation_skill') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->presentation_skill) && $performance_indicator_details->presentation_skill == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->presentation_skill) && $performance_indicator_details->presentation_skill == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->presentation_skill) && $performance_indicator_details->presentation_skill == 3) {
                                                echo lang('advanced');
                                            } elseif (!empty($performance_indicator_details->presentation_skill) && $performance_indicator_details->presentation_skill == 4) {
                                                echo lang('expert_leader');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->presentation_skill) && $performance_indicator_details->presentation_skill != 0) { ?>
                                                <select name="presentation_skill" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->presentation_skill) && $get_appraisal_info->presentation_skill == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->presentation_skill) && $get_appraisal_info->presentation_skill == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->presentation_skill) && $get_appraisal_info->presentation_skill == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                    <option value="4" <?= (!empty($get_appraisal_info->presentation_skill) && $get_appraisal_info->presentation_skill == 4 ? 'selected' : '') ?>><?= lang('expert_leader') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('quality_of_work') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->quality_of_work) && $performance_indicator_details->quality_of_work == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->quality_of_work) && $performance_indicator_details->quality_of_work == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->quality_of_work) && $performance_indicator_details->quality_of_work == 3) {
                                                echo lang('advanced');
                                            } elseif (!empty($performance_indicator_details->quality_of_work) && $performance_indicator_details->quality_of_work == 4) {
                                                echo lang('expert_leader');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->quality_of_work) && $performance_indicator_details->quality_of_work != 0) { ?>
                                                <select name="quality_of_work" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->quality_of_work) && $get_appraisal_info->quality_of_work == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->quality_of_work) && $get_appraisal_info->quality_of_work == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->quality_of_work) && $get_appraisal_info->quality_of_work == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                    <option value="4" <?= (!empty($get_appraisal_info->quality_of_work) && $get_appraisal_info->quality_of_work == 4 ? 'selected' : '') ?>><?= lang('expert_leader') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('efficiency') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->efficiency) && $performance_indicator_details->efficiency == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->efficiency) && $performance_indicator_details->efficiency == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->efficiency) && $performance_indicator_details->efficiency == 3) {
                                                echo lang('advanced');
                                            } elseif (!empty($performance_indicator_details->efficiency) && $performance_indicator_details->efficiency == 4) {
                                                echo lang('expert_leader');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->efficiency) && $performance_indicator_details->efficiency != 0) { ?>
                                                <select name="efficiency" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->efficiency) && $get_appraisal_info->efficiency == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->efficiency) && $get_appraisal_info->efficiency == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->efficiency) && $get_appraisal_info->efficiency == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                    <option value="4" <?= (!empty($get_appraisal_info->efficiency) && $get_appraisal_info->efficiency == 4 ? 'selected' : '') ?>><?= lang('expert_leader') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>

                        <div class="overflow-hidden rounded-2xl border border-border bg-card shadow-sm">
                            <div class="border-b border-border px-4 py-3">
                                <h4 class="text-sm font-semibold text-foreground"><?= lang('behavioural_competency') ?> / <?= lang('organizational') ?></h4>
                                <p class="mt-1 text-xs text-muted-foreground">Evaluate behaviour, collaboration and operational discipline.</p>
                            </div>
                            <div class="overflow-x-auto p-4">
                                <table class="appraisal-table min-w-full text-left text-sm">
                                    <thead>
                                    <tr>
                                        <th><?= lang('performance_indicator') ?></th>
                                        <th><?= lang('expected_value') ?></th>
                                        <th><?= lang('set_value') ?></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                        <td><?= lang('integrity') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->integrity) && $performance_indicator_details->integrity == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->integrity) && $performance_indicator_details->integrity == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->integrity) && $performance_indicator_details->integrity == 3) {
                                                echo lang('advanced');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->integrity) && $performance_indicator_details->integrity != 0) { ?>
                                                <select name="integrity" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->integrity) && $get_appraisal_info->integrity == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->integrity) && $get_appraisal_info->integrity == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->integrity) && $get_appraisal_info->integrity == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('professionalism') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->professionalism) && $performance_indicator_details->professionalism == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->professionalism) && $performance_indicator_details->professionalism == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->professionalism) && $performance_indicator_details->professionalism == 3) {
                                                echo lang('advanced');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->professionalism) && $performance_indicator_details->professionalism != 0) { ?>
                                                <select name="professionalism" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->professionalism) && $get_appraisal_info->professionalism == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->professionalism) && $get_appraisal_info->professionalism == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->professionalism) && $get_appraisal_info->professionalism == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('team_work') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->team_work) && $performance_indicator_details->team_work == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->team_work) && $performance_indicator_details->team_work == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->team_work) && $performance_indicator_details->team_work == 3) {
                                                echo lang('advanced');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->team_work) && $performance_indicator_details->team_work != 0) { ?>
                                                <select name="team_work" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->team_work) && $get_appraisal_info->team_work == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->team_work) && $get_appraisal_info->team_work == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->team_work) && $get_appraisal_info->team_work == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('critical_thinking') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->critical_thinking) && $performance_indicator_details->critical_thinking == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->critical_thinking) && $performance_indicator_details->critical_thinking == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->critical_thinking) && $performance_indicator_details->critical_thinking == 3) {
                                                echo lang('advanced');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->critical_thinking) && $performance_indicator_details->critical_thinking != 0) { ?>
                                                <select name="critical_thinking" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->critical_thinking) && $get_appraisal_info->critical_thinking == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->critical_thinking) && $get_appraisal_info->critical_thinking == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->critical_thinking) && $get_appraisal_info->critical_thinking == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('conflict_management') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->conflict_management) && $performance_indicator_details->conflict_management == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->conflict_management) && $performance_indicator_details->conflict_management == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->conflict_management) && $performance_indicator_details->conflict_management == 3) {
                                                echo lang('advanced');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->conflict_management) && $performance_indicator_details->conflict_management != 0) { ?>
                                                <select name="conflict_management" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->conflict_management) && $get_appraisal_info->conflict_management == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->conflict_management) && $get_appraisal_info->conflict_management == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->conflict_management) && $get_appraisal_info->conflict_management == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('attendance') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->attendance) && $performance_indicator_details->attendance == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->attendance) && $performance_indicator_details->attendance == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->attendance) && $performance_indicator_details->attendance == 3) {
                                                echo lang('advanced');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->attendance) && $performance_indicator_details->attendance != 0) { ?>
                                                <select name="attendance" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->attendance) && $get_appraisal_info->attendance == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->attendance) && $get_appraisal_info->attendance == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->attendance) && $get_appraisal_info->attendance == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><?= lang('ability_to_meet_deadline') ?></td>
                                        <td><?php
                                            if (!empty($performance_indicator_details->ability_to_meed_deadline) && $performance_indicator_details->ability_to_meed_deadline == 1) {
                                                echo lang('beginner');
                                            } elseif (!empty($performance_indicator_details->ability_to_meed_deadline) && $performance_indicator_details->ability_to_meed_deadline == 2) {
                                                echo lang('intermediate');
                                            } elseif (!empty($performance_indicator_details->ability_to_meed_deadline) && $performance_indicator_details->ability_to_meed_deadline == 3) {
                                                echo lang('advanced');
                                            } else {
                                                echo "<span style='color:red;font - style: italic;line - height:2.4;'>" . lang('not_set') . "</span>";
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php if (!empty($performance_indicator_details->ability_to_meed_deadline) && $performance_indicator_details->ability_to_meed_deadline != 0) { ?>
                                                <select name="ability_to_meed_deadline" class="form-control">
                                                    <option value=""><?= lang('none') ?></option>
                                                    <option value="1" <?= (!empty($get_appraisal_info->ability_to_meed_deadline) && $get_appraisal_info->ability_to_meed_deadline == 1 ? 'selected' : '') ?>><?= lang('beginner') ?></option>
                                                    <option value="2" <?= (!empty($get_appraisal_info->ability_to_meed_deadline) && $get_appraisal_info->ability_to_meed_deadline == 2 ? 'selected' : '') ?>><?= lang('intermediate') ?></option>
                                                    <option value="3" <?= (!empty($get_appraisal_info->ability_to_meed_deadline) && $get_appraisal_info->ability_to_meed_deadline == 3 ? 'selected' : '') ?>><?= lang('advanced') ?></option>
                                                </select>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>

                    <?php if (!empty($performance_indicator_details)) { ?>
                        <div class="border-t border-border pt-4">
                            <?php if (!empty($created) || !empty($edited)) { ?>
                                <div class="grid grid-cols-1 gap-4 lg:grid-cols-[minmax(0,1fr)_220px]">
                                    <div class="rounded-2xl border border-border bg-background/60 p-4">
                                        <?= form_textarea_group('general_remarks', lang('remarks'), !empty($get_appraisal_info->general_remarks) ? $get_appraisal_info->general_remarks : '', 3); ?>
                                    </div>
                                    <div class="flex items-end justify-end">
                                        <button id="btn_emp" type="submit"
                                                class="inline-flex items-center gap-2 rounded-lg bg-indigo-600 px-4 py-2 text-xs font-semibold text-white shadow-sm hover:bg-indigo-500">
                                            <i data-lucide="save" class="h-4 w-4"></i>
                                            <?= lang('update') ?>
                                        </button>
                                    </div>
                                </div>
                            <?php } ?>

                            <input type="hidden" name="user_id" value="<?php
                            if (!empty($user_id)) {
                                echo $user_id;
                            } elseif (!empty($get_appraisal_info->user_id)) {
                                echo $get_appraisal_info->user_id;
                            }
                            ?>">
                            <input type="hidden" name="appraisal_month" value="<?php
                            if (!empty($appraisal_month)) {
                                echo $appraisal_month;
                            } elseif (!empty($get_appraisal_info->appraisal_month)) {
                                echo $get_appraisal_info->appraisal_month;
                            }
                            ?>">
                        </div>
                    <?php } else { ?>
                        <div class="rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-700 text-center">
                            <?= lang('atleast_one_appraisal') ?>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </form>
    </div>
<?php } ?>

<script>
    (function () {
        const appraisalForm = document.getElementById("give_performance_appraisal");
        if (appraisalForm) {
            appraisalForm.querySelectorAll("select").forEach((select) => {
                if (!select.classList.contains("select_box")) {
                    select.classList.add("w-full", "rounded-xl", "border", "border-input", "bg-background", "px-3", "py-2.5", "text-sm", "text-foreground", "shadow-sm", "focus:border-primary", "focus:outline-none", "focus:ring-2", "focus:ring-primary/20");
                }
            });

            appraisalForm.querySelectorAll(".appraisal-table thead").forEach((thead) => {
                thead.classList.add("border-b", "border-border", "bg-muted/40", "text-xs", "uppercase", "tracking-wide", "text-muted-foreground");
            });

            appraisalForm.querySelectorAll(".appraisal-table th").forEach((cell) => {
                cell.classList.add("px-4", "py-3", "font-semibold");
            });

            appraisalForm.querySelectorAll(".appraisal-table td").forEach((cell) => {
                cell.classList.add("border-b", "border-border/70", "px-4", "py-3", "align-top", "text-foreground");
            });

            appraisalForm.querySelectorAll(".appraisal-table tbody tr").forEach((row) => {
                row.classList.add("transition", "hover:bg-muted/30");
            });
        }

    })();
</script>
