@extends('layouts.app')

@section('content')
<div class="container-fluid px-4 py-6">
    <div class="max-w-5xl mx-auto">
        <!-- Header -->
        <div class="d-flex align-items-center justify-content-between mb-4">
            <div class="d-flex align-items-center gap-3">
                <a href="{{ route('deployments.index') }}" class="btn btn-link text-decoration-none">
                    <i class="bi bi-arrow-left"></i> Back
                </a>
                <div>
                    <h2 class="mb-0">
                        {{ optional($deployment->ndrtOfficer)->name ?? (optional($deployment->ndrtOfficer)->first_name . ' ' . optional($deployment->ndrtOfficer)->surname) ?: 'NDRT Officer' }}
                    </h2>
                    <p class="text-muted mb-0">Deployment Details</p>
                </div>
            </div>
            <div class="d-flex gap-2">
                <a href="{{ route('deployments.edit', $deployment) }}" class="btn btn-outline-primary">
                    <i class="bi bi-pencil"></i> Edit
                </a>
                <form action="{{ route('deployments.destroy', $deployment) }}" method="POST" class="d-inline" onsubmit="return confirm('Delete this deployment?');">
                    @csrf
                    @method('DELETE')
                    <button type="submit" class="btn btn-outline-danger">
                        <i class="bi bi-trash"></i> Delete
                    </button>
                </form>
            </div>
        </div>

        <!-- Deployment Details -->
        <div class="card shadow-sm mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0"><i class="bi bi-info-circle"></i> Deployment Information</h5>
            </div>
            <div class="card-body">
                <div class="row g-4">
                    <div class="col-md-4">
                        <div class="border rounded p-3 h-100">
                            <div class="d-flex align-items-center mb-2">
                                <i class="bi bi-calendar3 text-white-50 me-2"></i>
                                <h6 class="mb-0">Period</h6>
                            </div>
                            <p class="mb-0">
                                {{ optional($deployment->start_date)->format('M d, Y') ?? '—' }}<br>
                                to {{ optional($deployment->end_date)->format('M d, Y') ?? '—' }}
                            </p>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="border rounded p-3 h-100">
                            <div class="d-flex align-items-center mb-2">
                                <i class="bi bi-geo-alt text-primary me-2"></i>
                                <h6 class="mb-0">Location</h6>
                            </div>
                            <p class="mb-0">{{ $deployment->mission_location ?? '—' }}</p>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="border rounded p-3 h-100">
                            <div class="d-flex align-items-center mb-2">
                                <i class="bi bi-flag text-primary me-2"></i>
                                <h6 class="mb-0">Status</h6>
                            </div>
                            <span class="badge {{ $deployment->status === 'completed' ? 'bg-secondary' : 'bg-success' }}">{{ ucfirst($deployment->status ?? 'active') }}</span>
                            @if($deployment->mission_end_date)
                                <div class="text-muted small mt-2">Completed: {{ $deployment->mission_end_date->format('M d, Y') }}</div>
                            @endif
                        </div>
                    </div>

                    <div class="col-md-4">
                        <div class="border rounded p-3 h-100">
                            <div class="d-flex align-items-center mb-2">
                                <i class="bi bi-person-check text-primary me-2"></i>
                                <h6 class="mb-0">Mentor</h6>
                            </div>
                            <p class="mb-0">
                                {{ $deployment->has_mentor ? ($deployment->mentor_name ?: 'Yes') : 'No' }}
                            </p>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="border rounded p-3 h-100">
                            <div class="d-flex align-items-center mb-2">
                                <i class="bi bi-arrow-repeat text-primary me-2"></i>
                                <h6 class="mb-0">Extended</h6>
                            </div>
                            <p class="mb-1">{{ $deployment->is_extended ? 'Yes' : 'No' }}</p>
                            @if($deployment->is_extended)
                                @if($deployment->new_completion_date)
                                    <div class="text-muted small">New completion: {{ $deployment->new_completion_date->format('M d, Y') }}</div>
                                @endif
                                @if($deployment->extension_reason)
                                    <div class="text-muted small">Reason: {{ $deployment->extension_reason }}</div>
                                @endif
                            @endif
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="border rounded p-3 h-100">
                            <div class="d-flex align-items-center mb-2">
                                <i class="bi bi-person text-primary me-2"></i>
                                <h6 class="mb-0">Reporting To</h6>
                            </div>
                            <p class="mb-0">{{ $deployment->reporting_to ?: '—' }}</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Mission Description -->
        <div class="card shadow-sm mb-4">
            <div class="card-header bg-info text-white">
                <h5 class="mb-0"><i class="bi bi-journal-text"></i> Mission Description</h5>
            </div>
            <div class="card-body">
                <p style="white-space: pre-wrap;">{{ $deployment->mission_description ?: '—' }}</p>
            </div>
        </div>

        <!-- Equipment Log -->
        <div class="card shadow-sm mb-4">
            <div class="card-header bg-warning">
                <h5 class="mb-0"><i class="bi bi-laptop"></i> Equipment Log</h5>
            </div>
            <div class="card-body">
                @if(is_array($deployment->equipment_log) && count($deployment->equipment_log) > 0)
                    <ul class="mb-0">
                        @foreach($deployment->equipment_log as $item)
                            <li>{{ $item }}</li>
                        @endforeach
                    </ul>
                @else
                    <p class="mb-0 text-muted">No equipment recorded.</p>
                @endif
            </div>
        </div>

        <!-- Report (if any) -->
        @if($deployment->report_path)
            <div class="card shadow-sm mb-4">
                <div class="card-header bg-secondary text-white">
                    <h5 class="mb-0"><i class="bi bi-file-earmark-text"></i> Report</h5>
                </div>
                <div class="card-body">
                    <a href="{{ Storage::url($deployment->report_path) }}" target="_blank" class="btn btn-outline-secondary">
                        <i class="bi bi-box-arrow-up-right"></i> View Report
                    </a>
                </div>
            </div>
        @endif

        <!-- Meta Information -->
        <div class="card shadow-sm">
            <div class="card-body bg-light">
                <div class="row text-muted small">
                    <div class="col-md-6">
                        <i class="bi bi-clock-history"></i> Created: {{ $deployment->created_at->format('M d, Y h:i A') }}
                    </div>
                    <div class="col-md-6 text-md-end">
                        <i class="bi bi-pencil-square"></i> Last Updated: {{ $deployment->updated_at->format('M d, Y h:i A') }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

