@extends('layouts.front')

@section('content')

<div class="container mt-5">
<div class="card shadow p-4">

<h3 class="mb-4 text-center text-primary">Edit Journalist Application</h3>

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

<form method="POST"
      action="{{ route('application.update', $application->id) }}"
      enctype="multipart/form-data">

@csrf


<div class="row">

{{-- ================= PERSONAL INFO ================= --}}

<div class="col-md-6 mb-3">
<label class="form-label">Full Name</label>
<input type="text" name="full_name"
value="{{ $application->full_name }}"
class="form-control" required>
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Father Name</label>
<input type="text" name="father_name"
value="{{ $application->father_name }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Mother Name</label>
<input type="text" name="mother_name"
value="{{ $application->mother_name }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Date of Birth</label>
<input type="date" name="dob"
value="{{ $application->dob }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Gender</label>
<select name="gender" class="form-select">
<option value="">Select</option>
<option value="Male" {{ $application->gender=='Male'?'selected':'' }}>Male</option>
<option value="Female" {{ $application->gender=='Female'?'selected':'' }}>Female</option>
<option value="Other" {{ $application->gender=='Other'?'selected':'' }}>Other</option>
</select>
</div>

<div class="col-md-6 mb-3">
<label class="form-label">NID</label>
<input type="text" name="nid"
value="{{ $application->nid }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Mobile</label>
<input type="text" name="mobile"
value="{{ $application->mobile }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Email</label>
<input type="email" name="email"
value="{{ $application->email }}"
class="form-control">
</div>

{{-- ================= ADDRESS ================= --}}

<div class="col-md-6 mb-3">
<label class="form-label">Present Address</label>
<textarea name="present_address"
class="form-control">{{ $application->present_address }}</textarea>
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Permanent Address</label>
<textarea name="permanent_address"
class="form-control">{{ $application->permanent_address }}</textarea>
</div>

<div class="col-md-6 mb-3">
<label class="form-label">District</label>
<input type="text" name="district"
value="{{ $application->district }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Division</label>
<input type="text" name="division"
value="{{ $application->division }}"
class="form-control">
</div>

{{-- ================= PROFESSIONAL ================= --}}

<div class="col-md-6 mb-3">
<label class="form-label">Education</label>
<input type="text" name="education"
value="{{ $application->education }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">University</label>
<input type="text" name="university"
value="{{ $application->university }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Graduation Year</label>
<input type="text" name="graduation_year"
value="{{ $application->graduation_year }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Experience</label>
<textarea name="experience"
class="form-control">{{ $application->experience }}</textarea>
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Current Profession</label>
<input type="text" name="current_profession"
value="{{ $application->current_profession }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Previous Media</label>
<input type="text" name="previous_media"
value="{{ $application->previous_media }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Reporting Category</label>
<input type="text" name="reporting_category"
value="{{ $application->reporting_category }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Working Area</label>
<input type="text" name="working_area"
value="{{ $application->working_area }}"
class="form-control">
</div>

{{-- ================= ONLINE LINKS ================= --}}

<div class="col-md-6 mb-3">
<label class="form-label">Portfolio Link</label>
<input type="url" name="portfolio_link"
value="{{ $application->portfolio_link }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">Facebook Link</label>
<input type="url" name="facebook_link"
value="{{ $application->facebook_link }}"
class="form-control">
</div>

<div class="col-md-6 mb-3">
<label class="form-label">YouTube Link</label>
<input type="url" name="youtube_link"
value="{{ $application->youtube_link }}"
class="form-control">
</div>
</div>



<!-- =======================================  -->


{{-- ================= FILES ================= --}}

<div class="row mt-3">

{{-- ================= CV ================= --}}
<div class="col-md-4 mb-3">
    <label class="form-label">CV (PDF)</label>

    @if(!empty($application->cv_file))
    @php
      $cvUrl = 'https://bdcrimewatch.com/storage/app/public/' . ltrim($application->cv_file, '/');
      @endphp
        <div class="mb-2">
            <a href="{{$cvUrl}}"
               target="_blank"
               class="btn btn-sm btn-info">
               View Current
            </a>
        </div>
    @endif

    <input type="file" name="cv_file" class="form-control">
</div>


{{-- ================= PHOTO ================= --}}
<div class="col-md-4 mb-3">
    <label class="form-label">Photo</label>

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

        <div class="mb-2">
            @if(in_array($extension, $imageExtensions))
                <img src="{{ $photoUrl }}"
                     width="100"
                     class="img-thumbnail">
            @else
                <a href="{{$photoUrl }}"
                   target="_blank"
                   class="btn btn-primary btn-sm">
                   Open File
                </a>
            @endif
        </div>
    @endif

    <input type="file" name="photo" class="form-control">
</div>


{{-- ================= NID ================= --}}
<div class="col-md-4 mb-3">
    <label class="form-label">NID Copy</label>

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

        <div class="mb-2">
            @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="100"
                     class="img-thumbnail">
            @endif
        </div>
    @endif

    <input type="file" name="nid_copy" class="form-control">
</div>

</div>

<!-- ==============================================  -->



{{-- ================= SUBMIT ================= --}}

<div class="col-12 mt-3">
<button type="submit" class="btn btn-dark px-4">
Update Application
</button>
</div>

</div>

</form>

</div>
</div>

@endsection