
@extends('layouts.app')

@section('content')

<div class="container mt-4">

    <div class="card shadow-lg p-4">

        {{-- ================= HEADER ================= --}}
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h3>Application Details</h3>

            <span class="badge bg-{{ 
$application->status=='approved' ? 'success' : 
($application->status=='rejected' ? 'danger' : 
($application->status=='review' ? 'warning' : 'secondary')) 
}} fs-6">
                {{ strtoupper($application->status) }}
            </span>

        </div>

        {{-- ================= SUCCESS MESSAGE ================= --}}
        @if(session('success'))
        <div class="alert alert-success">
            {{ session('success') }}
        </div>
        @endif

        <hr>

        {{-- ================= PERSONAL INFO ================= --}}
        <h5 class="text-primary">Personal Information</h5>

        <div class="row">
            <div class="col-md-6"><strong>Name:</strong> {{ $application->full_name }}</div>
            <div class="col-md-6"><strong>Father:</strong> {{ $application->father_name }}</div>
            <div class="col-md-6"><strong>Mother:</strong> {{ $application->mother_name }}</div>
            <div class="col-md-6"><strong>DOB:</strong> {{ $application->dob }}</div>
            <div class="col-md-6"><strong>Gender:</strong> {{ $application->gender }}</div>
            <div class="col-md-6"><strong>NID:</strong> {{ $application->nid }}</div>
            <div class="col-md-6"><strong>Mobile:</strong> {{ $application->mobile }}</div>
            <div class="col-md-6"><strong>Email:</strong> {{ $application->email }}</div>
        </div>

        <hr>

        {{-- ================= ADDRESS ================= --}}
        <h5 class="text-primary">Address</h5>

        <div class="row">
            <div class="col-md-6"><strong>Present:</strong> {{ $application->present_address }}</div>
            <div class="col-md-6"><strong>Permanent:</strong> {{ $application->permanent_address }}</div>
            <div class="col-md-6"><strong>District:</strong> {{ $application->district }}</div>
            <div class="col-md-6"><strong>Division:</strong> {{ $application->division }}</div>
        </div>

        <hr>

        {{-- ================= PROFESSIONAL ================= --}}
        <h5 class="text-primary">Professional Information</h5>

        <div class="row">
            <div class="col-md-6"><strong>Education:</strong> {{ $application->education }}</div>
            <div class="col-md-6"><strong>University:</strong> {{ $application->university }}</div>
            <div class="col-md-6"><strong>Graduation Year:</strong> {{ $application->graduation_year }}</div>
            <div class="col-md-6"><strong>Experience:</strong> {{ $application->experience }}</div>
            <div class="col-md-6"><strong>Current Profession:</strong> {{ $application->current_profession }}</div>
            <div class="col-md-6"><strong>Previous Media:</strong> {{ $application->previous_media }}</div>
            <div class="col-md-6"><strong>Category:</strong> {{ $application->reporting_category }}</div>
            <div class="col-md-6"><strong>Working Area:</strong> {{ $application->working_area }}</div>
        </div>

        <hr>

        {{-- ================= ONLINE ================= --}}
        <h5 class="text-primary">Online Presence</h5>

        <div class="row">
            <div class="col-md-12">
                <strong>Portfolio:</strong>
                <a href="{{ $application->portfolio_link }}" target="_blank">
                    {{ $application->portfolio_link }}
                </a>
            </div>

            <div class="col-md-12">
                <strong>Facebook:</strong>
                <a href="{{ $application->facebook_link }}" target="_blank">
                    {{ $application->facebook_link }}
                </a>
            </div>

            <div class="col-md-12">
                <strong>YouTube:</strong>
                <a href="{{ $application->youtube_link }}" target="_blank">
                    {{ $application->youtube_link }}
                </a>
            </div>
        </div>

        <hr>

       {{-- ================= FILES ================= --}}
<h5 class="text-primary">Files</h5>
<div class="row">

{{-- ================= PHOTO / IMAGE ================= --}}
@if($application->photo)
<div class="col-md-4 mb-3">
    <strong>Photo</strong><br>

    @php
        $extension = strtolower(pathinfo($application->photo, PATHINFO_EXTENSION));
        $imageExtensions = ['jpg','jpeg','png','webp'];
        $photoUrl = 'https://bdcrimewatch.com/storage/app/public/' . ltrim($application->photo, '/');
    @endphp

    @if(in_array($extension, $imageExtensions))

        <img src="{{ $photoUrl }}"
             width="180"
             class="img-thumbnail">

    @else

        <a href="{{ $photoUrl }}"
           target="_blank"
           class="btn btn-primary btn-sm">
           Open File
        </a>

    @endif

</div>
@endif


{{-- ================= CV FILE ================= --}}
@if($application->cv_file)
<div class="col-md-4 mb-3">
    <strong>CV</strong><br>

    @php
        $cvUrl = 'https://bdcrimewatch.com/storage/app/public/' . ltrim($application->cv_file, '/');
    @endphp

    @if(str_contains($application->cv_file,'.pdf'))

        <a href="{{ $cvUrl }}"
           target="_blank"
           class="btn btn-danger btn-sm">
           📄 View PDF
        </a>

    @else

        <a href="{{ $cvUrl }}"
           target="_blank"
           class="btn btn-dark btn-sm">
           Download File
        </a>

    @endif

</div>
@endif


{{-- ================= NID FILE ================= --}}
@if($application->nid_copy)
<div class="col-md-4 mb-3">
    <strong>NID Copy</strong><br>

    @php
        $nidUrl = 'https://bdcrimewatch.com/storage/app/public/' . ltrim($application->nid_copy, '/');
    @endphp

    @if(str_contains($application->nid_copy,'.pdf'))

        <a href="{{ $nidUrl }}"
           target="_blank"
           class="btn btn-danger btn-sm">
           📄 View PDF
        </a>

    @else

        <img src="{{ $nidUrl }}"
             width="180"
             class="img-thumbnail">

    @endif

</div>
@endif

</div>

</div>

        <hr>

        {{-- ================= ADMIN UPDATE ================= --}}
        <h5 class="text-primary">Admin Update</h5>

        <form method="POST"
            action="{{ route('application.statusupdate',$application->id) }}">

            @csrf


            <div class="row">

                <div class="col-md-6 mb-3">
                    <label>Status</label>
                    <select name="status" class="form-select">
                        <option value="pending" {{ $application->status=='pending'?'selected':'' }}>Pending</option>
                        <option value="review" {{ $application->status=='review'?'selected':'' }}>Review</option>
                        <option value="approved" {{ $application->status=='approved'?'selected':'' }}>Approved</option>
                        <option value="rejected" {{ $application->status=='rejected'?'selected':'' }}>Rejected</option>
                    </select>
                </div>

                <div class="col-md-6 mb-3">
                    <label>Admin Note</label>
                    <textarea name="admin_note"
                        class="form-control"
                        rows="3">{{ $application->admin_note }}</textarea>
                </div>

            </div>

            <button type="submit" class="btn btn-success">
                Update Application
            </button>

        </form>

        <hr>

        <a href="{{ route('application.index') }}"
            class="btn btn-outline-dark">
            ⬅ Back To List
        </a>

    </div>
</div>

@endsection