

<?php $__env->startSection('title', 'NDRT Surge Profile'); ?>

<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="page-header">
        <h1>NDRT Surge Profile</h1>
        <div>
            <a href="<?php echo e(route('ndrt.edit', $ndrt)); ?>" class="btn btn-warning">
                <i class="fas fa-edit"></i> Edit Profile
            </a>
            <a href="<?php echo e(route('ndrt.index')); ?>" class="btn btn-secondary">
                <i class="fas fa-arrow-left"></i> Back to List
            </a>
        </div>
    </div>

    <?php if(session('success')): ?>
        <div class="alert alert-success"><?php echo e(session('success')); ?></div>
    <?php endif; ?>

    <div class="row">
        <!-- Left Column -->
        <div class="col-md-4">
            <!-- Photo Card -->
            <div class="card text-center">
                <div class="card-body">
                    <?php if($ndrt->photo_path): ?>
                        <img src="<?php echo e(Storage::url($ndrt->photo_path)); ?>" 
                             alt="<?php echo e($ndrt->full_name); ?>" 
                             class="img-fluid rounded mb-3" 
                             style="max-width: 250px;">
                    <?php else: ?>
                        <div class="officer-photo-placeholder mx-auto mb-3" style="width: 150px; height: 150px; font-size: 48px;">
                            <?php echo e(substr($ndrt->first_name, 0, 1)); ?><?php echo e(substr($ndrt->surname, 0, 1)); ?>

                        </div>
                    <?php endif; ?>
                    
                    <h3><?php echo e($ndrt->full_name); ?></h3>
                    <p class="text-muted"><?php echo e($ndrt->id_type); ?>: <?php echo e($ndrt->id_number); ?></p>
                    
                    <div class="mt-3">
                        <?php if($ndrt->available_for_deployment): ?>
                            <span class="badge bg-success fs-6">Available for Deployment</span>
                        <?php else: ?>
                            <span class="badge bg-danger fs-6">Not Available</span>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <!-- Quick Stats -->
            <div class="card mt-3">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Quick Stats</h5>
                </div>
                <div class="card-body">
                    <table class="table table-sm">
                        <tr>
                            <th>Age:</th>
                            <td><?php echo e($ndrt->age); ?> years</td>
                        </tr>
                        <tr>
                            <th>Gender:</th>
                            <td><?php echo e($ndrt->gender); ?></td>
                        </tr>
                        <tr>
                            <th>Blood Group:</th>
                            <td><?php echo e($ndrt->blood_group ?? 'N/A'); ?></td>
                        </tr>
                        <tr>
                            <th>Total Deployments:</th>
                            <td><span class="badge bg-info"><?php echo e($ndrt->deployment_count); ?></span></td>
                        </tr>
                        <tr>
                            <th>Active Deployments:</th>
                            <td><span class="badge bg-warning"><?php echo e($ndrt->active_deployments); ?></span></td>
                        </tr>
                        <tr>
                            <th>Completed:</th>
                            <td><span class="badge bg-success"><?php echo e($ndrt->completed_deployments); ?></span></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

        <!-- Right Column -->
        <div class="col-md-8">
            <!-- Personal Information -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Personal Information</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <strong>Date of Birth:</strong><br>
                            <?php echo e($ndrt->date_of_birth->format('d M Y')); ?>

                        </div>
                        <div class="col-md-6 mb-3">
                            <strong>Physical Address:</strong><br>
                            <?php echo e($ndrt->physical_address ?? 'N/A'); ?>

                        </div>
                    </div>
                </div>
            </div>

            <!-- Location -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Location</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-4 mb-3">
                            <strong>Location Type:</strong><br>
                            <?php echo e($ndrt->location_type); ?>

                        </div>
                        <div class="col-md-4 mb-3">
                            <strong>Branch:</strong><br>
                            <?php echo e($ndrt->branch->name ?? 'N/A'); ?>

                        </div>
                        <div class="col-md-4 mb-3">
                            <strong>Unit:</strong><br>
                            <?php echo e($ndrt->unit ?? 'N/A'); ?>

                        </div>
                    </div>
                </div>
            </div>

            <!-- Contact Details -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Contact Details</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-4 mb-3">
                            <strong>Primary Phone:</strong><br>
                            <?php echo e($ndrt->phone_1); ?>

                        </div>
                        <div class="col-md-4 mb-3">
                            <strong>Secondary Phone:</strong><br>
                            <?php echo e($ndrt->phone_2 ?? 'N/A'); ?>

                        </div>
                        <div class="col-md-4 mb-3">
                            <strong>Email:</strong><br>
                            <?php echo e($ndrt->email ?? 'N/A'); ?>

                        </div>
                    </div>
                </div>
            </div>

            <!-- Emergency Contact -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Emergency Contact / Next of Kin</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <strong>Name:</strong><br>
                            <?php echo e($ndrt->emergency_contact_name); ?>

                        </div>
                        <div class="col-md-6 mb-3">
                            <strong>Relation:</strong><br>
                            <?php echo e($ndrt->emergency_contact_relation); ?>

                        </div>
                        <div class="col-md-4 mb-3">
                            <strong>Primary Phone:</strong><br>
                            <?php echo e($ndrt->emergency_contact_phone_1); ?>

                        </div>
                        <div class="col-md-4 mb-3">
                            <strong>Secondary Phone:</strong><br>
                            <?php echo e($ndrt->emergency_contact_phone_2 ?? 'N/A'); ?>

                        </div>
                        <div class="col-md-12 mb-3">
                            <strong>Address:</strong><br>
                            <?php echo e($ndrt->emergency_contact_address ?? 'N/A'); ?>

                        </div>
                    </div>
                </div>
            </div>

            <!-- Other Details -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Other Details</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-12 mb-3">
                            <strong>Languages Spoken:</strong><br>
                            <?php if($ndrt->languages_spoken): ?>
                                <?php $__currentLoopData = $ndrt->languages_spoken; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lang): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <span class="badge bg-secondary"><?php echo e($lang); ?></span>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php else: ?>
                                N/A
                            <?php endif; ?>
                        </div>
                        <div class="col-md-12 mb-3">
                            <strong>Health Conditions:</strong><br>
                            <?php echo e($ndrt->health_conditions ?? 'None reported'); ?>

                        </div>
                        <div class="col-md-6 mb-3">
                            <strong>Disability Status:</strong><br>
                            <?php if($ndrt->has_disability): ?>
                                <span class="badge bg-info">Yes</span>
                                <br><small><?php echo e($ndrt->disability_details); ?></small>
                            <?php else: ?>
                                <span class="badge bg-secondary">No</span>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Education -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Education</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <strong>Education Level:</strong><br>
                            <?php echo e($ndrt->education_level ?? 'N/A'); ?>

                        </div>
                        <div class="col-md-6 mb-3">
                            <strong>Area of Study:</strong><br>
                            <?php echo e($ndrt->area_of_study ?? 'N/A'); ?>

                        </div>
                    </div>
                </div>
            </div>

            <!-- Work Experience -->
            <?php if($ndrt->work_experience): ?>
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Work Experience</h5>
                </div>
                <div class="card-body">
                    <?php $__currentLoopData = $ndrt->work_experience; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $exp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="mb-3 pb-3 border-bottom">
                            <h6><?php echo e($exp['position'] ?? ''); ?> (<?php echo e($exp['year'] ?? ''); ?>)</h6>
                            <p class="mb-1"><strong>Institution:</strong> <?php echo e($exp['institution'] ?? ''); ?></p>
                            <p class="mb-0"><small><?php echo e($exp['description'] ?? ''); ?></small></p>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>
            <?php endif; ?>

            <!-- Competencies -->
            <?php if($ndrt->competencies): ?>
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Competencies / Specializations</h5>
                </div>
                <div class="card-body">
                    <?php $__currentLoopData = $ndrt->competencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $comp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <span class="badge bg-success me-2 mb-2"><?php echo e($comp); ?></span>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>
            <?php endif; ?>

            <!-- Training History -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Training History</h5>
                </div>
                <div class="card-body">
                    <?php
                        // Pull trainings where this officer's id is inside trainings.participants (JSON array)
                        $jsonTrainings = \App\Models\Training::whereJsonContains('participants', (string) $ndrt->id)->orderByDesc('start_date')->get();
                        // Load existing grades
                        $grades = \App\Models\TrainingGrading::where('ndrt_officer_id', $ndrt->id)
                            ->whereIn('training_id', $jsonTrainings->pluck('id'))
                            ->get()
                            ->keyBy('training_id');
                    ?>
                    <?php if($jsonTrainings->count() > 0): ?>
                        <div class="table-responsive">
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th>Training Name</th>
                                        <th>Date</th>
                                        <th>Location</th>
                                        <th>Grade</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $jsonTrainings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $training): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        $existingGrade = $grades->get($training->id);
                                    ?>
                                    <tr>
                                        <td><?php echo e($training->name); ?></td>
                                        <td><?php echo e(optional($training->start_date)->format('d M Y')); ?></td>
                                        <td><?php echo e($training->location); ?></td>
                                        <td>
                                            <?php if($existingGrade): ?>
                                                <span class="badge bg-info">
                                                    <?php if($existingGrade->grade == '1-Needs further training'): ?>
                                                        1 - Needs further training
                                                    <?php elseif($existingGrade->grade == '2-Deploy with Support'): ?>
                                                        2 - Deploy with Support
                                                    <?php elseif($existingGrade->grade == '3-Strong'): ?>
                                                        3 - Strong
                                                    <?php else: ?>
                                                        <?php echo e($existingGrade->grade); ?>

                                                    <?php endif; ?>
                                                </span>
                                            <?php else: ?>
                                                <span class="text-muted">Not graded</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#gradeModal<?php echo e($training->id); ?>">
                                                <i class="fas fa-star"></i> Grade NDRT
                                            </button>
                                        </td>
                                    </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    <?php else: ?>
                        <p class="text-muted">No training records yet.</p>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Deployment Months -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Deployment Months</h5>
                </div>
                <div class="card-body">
                    <?php
                        $deployment_months = json_decode($ndrt->deployment_months ?? '[]', true);
                    ?>
                    <?php if($deployment_months->count() > 0): ?>
                        <?php $__currentLoopData = $deployment_months; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $month): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <span class="badge bg-secondary"><?php echo e($month); ?></span>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php else: ?>
                        <p class="text-muted">No deployment months yet.</p>
                    <?php endif; ?>
                </div>
            </div>

            <!-- Training Sector -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Training Sector</h5>
                </div>            
                <div class="card-body">
                    <span class="badge bg-secondary"><?php echo e($ndrt->training_sector ?? 'N/A'); ?></span>
                </div>
            </div>

            <!-- Deployment History -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">Deployment History</h5>
                </div>
                <div class="card-body">
                    <?php if($ndrt->deployments->count() > 0): ?>
                        <div class="table-responsive">
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th>Mission Location</th>
                                        <th>Start Date</th>
                                        <th>End Date</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $__currentLoopData = $ndrt->deployments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $deployment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e($deployment->mission_location); ?></td>
                                        <td><?php echo e($deployment->start_date->format('d M Y')); ?></td>
                                        <td><?php echo e($deployment->end_date->format('d M Y')); ?></td>
                                        <td>
                                            <?php if($deployment->status == 'Active'): ?>
                                                <span class="badge bg-warning">Active</span>
                                            <?php else: ?>
                                                <span class="badge bg-success">Completed</span>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    <?php else: ?>
                        <p class="text-muted">No deployment records yet.</p>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Grade Modals -->
<?php if(isset($jsonTrainings) && $jsonTrainings->count() > 0): ?>
    <?php $__currentLoopData = $jsonTrainings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $training): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php
        $existingGrade = isset($grades) ? $grades->get($training->id) : null;
    ?>
    <div class="modal fade" id="gradeModal<?php echo e($training->id); ?>" tabindex="-1" aria-labelledby="gradeModalLabel<?php echo e($training->id); ?>" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="gradeModalLabel<?php echo e($training->id); ?>">Grade NDRT - <?php echo e($training->name); ?></h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <form action="<?php echo e(route('ndrt.grade', ['ndrt' => $ndrt->id, 'training' => $training->id])); ?>" method="POST">
                    <?php echo csrf_field(); ?>
                    <div class="modal-body">
                        <div class="mb-3">
                            <label class="form-label"><strong>Select Grade:</strong></label>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="grade" id="grade1_<?php echo e($training->id); ?>" value="1-Needs further training" <?php echo e($existingGrade && $existingGrade->grade == '1-Needs further training' ? 'checked' : ''); ?> required>
                                <label class="form-check-label" for="grade1_<?php echo e($training->id); ?>">
                                    1 - Needs further training
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="grade" id="grade2_<?php echo e($training->id); ?>" value="2-Deploy with Support" <?php echo e($existingGrade && $existingGrade->grade == '2-Deploy with Support' ? 'checked' : ''); ?> required>
                                <label class="form-check-label" for="grade2_<?php echo e($training->id); ?>">
                                    2 - Deploy with Support
                                </label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="grade" id="grade3_<?php echo e($training->id); ?>" value="3-Strong" <?php echo e($existingGrade && $existingGrade->grade == '3-Strong' ? 'checked' : ''); ?> required>
                                <label class="form-check-label" for="grade3_<?php echo e($training->id); ?>">
                                    3 - Strong
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-primary">Submit Grade</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php endif; ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\wamp64\www\ndrt-system\resources\views/ndrt/show.blade.php ENDPATH**/ ?>