<div class="modal-body">
    <form id="form" role="form" enctype="multipart/form-data"
          action="<?php echo base_url() ?>admin/job_circular/change_application_status/<?php
          if (!empty($job_application_info->job_appliactions_id)) {
              echo $job_application_info->job_appliactions_id;
          }
          ?>" method="post" class="space-y-5">

        <div class="rounded-xl border border-border bg-card/60 p-4">
            <div class="mb-4">
                <div class="text-sm font-semibold text-foreground"><?= lang('change_status') ?></div>
                <div class="mt-1 text-xs text-muted-foreground"><?= lang('update') . ' ' . lang('application_status') ?></div>
            </div>

            <?php
            $status_options = array(
                '0' => lang('unread'),
                '2' => lang('primary_selected'),
                '3' => lang('call_for_interview'),
                '1' => lang('approved'),
                '4' => lang('rejected'),
            );
            echo form_select_group(
                'status',
                lang('status'),
                $status_options,
                !empty($job_application_info->application_status) ? $job_application_info->application_status : '0',
                true,
                array('id' => 'job_applicarion_status')
            );
            ?>
        </div>

        <input type="hidden" name="flag" value="1"/>

        <div id="interviewFields" class="space-y-4 rounded-xl border border-amber-200/70 bg-amber-50/40 p-4 dark:border-amber-900/40 dark:bg-amber-950/10" style="display: <?= ($job_application_info->application_status == 3 ? 'block' : 'none') ?>">
            <div>
                <div class="text-sm font-semibold text-foreground"><?= lang('call_for_interview') ?></div>
                <div class="mt-1 text-xs text-muted-foreground"><?= lang('send_email') . ' ' . lang('and') . ' ' . lang('interview_date') ?></div>
            </div>

            <div class="interview-field">
                <?= form_checkbox('send_email', lang('send_email'), (!empty($job_application_info->send_email) && $job_application_info->send_email == 'Yes'), false, array('value' => 'Yes')); ?>
            </div>

            <div class="interview-field">
                <?= form_textarea_group('interview_note', lang('note'), !empty($job_application_info->interview_note) ? $job_application_info->interview_note : '', 3, false, array('class' => 'interview_note')); ?>
            </div>

            <div class="interview-field">
                <?= form_datepicker('interview_date', lang('interview_date'), !empty($job_application_info->interview_date) ? $job_application_info->interview_date : '', false, array('class' => 'datepicker interview_date')); ?>
            </div>
        </div>

        <div class="flex items-center justify-end gap-2 border-t border-border pt-4">
            <button type="submit" class="inline-flex items-center gap-2 rounded-lg bg-indigo-600 px-4 py-2.5 text-sm font-semibold text-white shadow-sm transition hover:bg-indigo-500">
                <i data-lucide="save" class="h-4 w-4"></i>
                <?= lang('update') ?>
            </button>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var $status = $("#job_applicarion_status");
        var $interviewFields = $("#interviewFields");
        var $interviewInputs = $interviewFields.find("input, textarea, select");
        var $interviewDate = $(".interview_date");
        var $interviewNote = $(".interview_note");

        function toggleInterviewFields() {
            var isInterview = $status.val() == 3;

            if (isInterview) {
                $interviewFields.stop(true, true).slideDown(150);
                $interviewInputs.prop("disabled", false);
                $interviewDate.attr("required", true);
                $interviewNote.attr("required", true);
            } else {
                $interviewFields.stop(true, true).slideUp(150);
                $interviewInputs.prop("disabled", true);
                $interviewDate.removeAttr("required");
                $interviewNote.removeAttr("required");
            }
        }

        toggleInterviewFields();
        $status.on("change", toggleInterviewFields);
    });
</script>
