@extends('layouts.admin')
@section('head')
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.css" />
@endsection
@section('content')
    <style>
        .table tbody tr:last-child td,
        .table tbody tr:last-child th{
            border-bottom: none;
        }
        .card-body .table{
            margin-bottom: 0;
        }
        .long-description {
            max-width: 600px;  /* Limit width */
            max-height: 150px; /* Limit height */
            overflow: auto;    /* Enable scrolling for overflow */
            word-wrap: break-word; /* Ensure long words break properly */
            white-space: pre-line; /* Preserve line breaks */
            padding: 5px;
            border: 1px solid #ddd; /* Optional: add a border */
            background-color: #f8f9fa; /* Light background for readability */
            border-radius: 5px;
        }

        #statusDropdown {
            height: 25px;
            padding: 0 0px 0px 8px;
        }

        #map {
            height: 500px;
            width: 100%;
        }

    </style>

   <!-- start page title -->
   <div class="row">
    <div class="col-12">
        <div class="page-title-box d-sm-flex align-items-center justify-content-between bg-galaxy-transparent">
            <h4 class="mb-sm-0">User Details</h4>

            <div class="page-title-right">
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Home</a></li>
                    <li class="breadcrumb-item"><a href="javascript: void(0);">Users</a></li>
                    <li class="breadcrumb-item active">User Details</li>
                </ol>
            </div>
        </div>
    </div>
</div>
<!-- end page title -->

<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header border-0">
                <div class="row align-items-center gy-3">
                    <div class="col-sm">
                        <h5 class="card-title mb-0">User Details <strong>{{ $user->user_number }}</strong></h5>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <div class="row">
                    <!-- Left Column: Contact Information, Documents, Additional Information, Options -->
                    <div class="col-lg-6">
                        <div class="card mb-3">
                            <div class="card-header py-2" style="background-color: var(--vz-primary);">
                                <h4 class="mb-0 text-white">User Basic Information</h4>
                            </div>
                            <div class="card-body">
                                <table class="table table-sm">
                                    <tr>
                                        <td style="width: 30%;">Full Name</td>
                                        <td style="width: 70%;">{{ $user->name }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 30%;">Nick Name</td>
                                        <td style="width: 70%;">{{ $user->nick_name }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 30%;">Email</td>
                                        <td style="width: 70%;">{{ $user->email }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 30%;">Phone</td>
                                        <td style="width: 70%;">{{ $user->dial_code }} {{ $user->phone }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 30%;">Status</td>
                                        <td style="width: 70%;">{{ $user->status == 1? 'Active':'Inactive' }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 30%;">Nationality</td>
                                        <td style="width: 70%;">{{ $user->nationality->name ?? 'N/A' }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 30%;">Is Mother Uae Nationality</td>
                                        <td style="width: 70%;">{{ $user->is_mother_uae_national?"YES":"NO" }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 30%;">Is User Uae Resident</td>
                                        <td style="width: 70%;">{{ $user->is_user_uae_nationality?"YES":"NO" }}</td>
                                    </tr>
                                    
                                    <tr>
                                        <td style="width: 30%;">Emirate</td>
                                        <td style="width: 70%;">{{ $user->emirate->name ?? 'N/A' }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 30%;">Registered On</td>
                                        <td style="width: 70%;">{{ $user->created_at->format('d/m/y H:i A') }}</td>
                                    </tr>
                                    @if($user->gardien_relation || $user->gardien_phone_number)
                                    <tr>
                                        <td colspan="2" class="bg-light"><strong>Guardian Information</strong></td>
                                    </tr>
                                    @if($user->parent_name)
                                    <tr>
                                        <td style="width: 30%;">Guardian Name</td>
                                        <td style="width: 70%;">{{ $user->parent_name }}</td>
                                    </tr>
                                    @endif
                                    @if($user->gardien_relation)
                                    <tr>
                                        <td style="width: 30%;">Guardian Relation</td>
                                        <td style="width: 70%;">{{ $user->gardien_relation }}</td>
                                    </tr>
                                    @endif
                                    @if($user->gardien_phone_number)
                                    <tr>
                                        <td style="width: 30%;">Guardian Phone</td>
                                        <td style="width: 70%;">{{ $user->gardien_phone_dial_code }} {{ $user->gardien_phone_number }}</td>
                                    </tr>
                                    @endif
                                    @endif
                                </table>
                            </div>
                        </div>
                        
                    </div>

                    <!-- Right Column: Shipping Information, Billing Information, Order Summary -->
                        <div class="col-lg-6">
                            <div class="card mb-3">
                                <div class="card-header py-2" style="background-color: var(--vz-primary);">
                                    <h4 class="mb-0 text-white">Subscription Plan Information</h4>
                                </div>
                                <div class="card-body">
                                    <table class="table table-sm">
                                        <tr>
                                            <td style="width: 30%;">Name</td>
                                            <td style="width: 70%;">{{ $user->plan->name??'N/A' }}</td>
                                        </tr>
                                        <tr>
                                            <td style="width: 30%;">Type</td>
                                            <td style="width: 70%;">{{ $user->plan->type??'N/A' }}</td>
                                        </tr>
                                        <tr>
                                            <td style="width: 30%;">Price</td>
                                            <td style="width: 70%;">{{ $user->plan->price??'N/A' }} {{$user->plan->currency??'N/A'}}</td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                </div>
                <div class="row">
                    <!-- Left Column: Contact Information, Documents, Additional Information, Options -->
                    <div class="col-lg-12">
                        <div class="card mb-3">
                            <div class="card-header py-2" style="background-color: var(--vz-primary);">
                                <h4 class="mb-0 text-white">User Details</h4>
                            </div>
                            <div class="card-body">
                                <table class="table table-sm">
                                    <tr>
                                        <td style="width: 20%;">Sect</td>
                                        <td style="width: 40%;">{{ $user->details->sect->name??'N/A' }}</td>
                                        <td style="width: 40%;">{{ $user->details->sect->name_ar??'N/A' }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Education</td>
                                        <td style="width: 40%;">{{ $user->details->education->name??'N/A' }}</td>
                                        <td style="width: 40%;">{{ $user->details->education->name_ar??'N/A' }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Profession</td>
                                        <td style="width: 40%;">{{ $user->details->profession->name??'N/A' }}</td>
                                        <td style="width: 40%;">{{ $user->details->profession->name_ar??'N/A' }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Marital Status</td>
                                        <td style="width: 40%;">{{ $user->details->maritalStatus->name??'N/A' }}</td>
                                        <td style="width: 40%;">{{ $user->details->maritalStatus->name_ar??'N/A' }}</td>
                                    </tr>
                                    @foreach($user->children as $ch)
                                    <tr>
                                        <td style="width: 20%;">Children Age {{$ch->age}}</td>
                                        <td style="width: 40%;">{{$ch->kid_count}}</td>
                                        <td style="width: 40%;"></td>
                                    </tr>
                                    @endforeach
                                    <tr style="display:none;">
                                        <td style="width: 20%;">Dress Code</td>
                                        <td style="width: 40%;">{{ $user->details->dressCode->name??'N/A' }}</td>
                                        <td style="width: 40%;">{{ $user->details->dressCode->name_ar??'N/A' }}</td>
                                    </tr>
                                    @if(isset($user->details->genetic_disease) && $user->details->genetic_disease == 1)
                                    <tr>
                                        <td style="width: 20%;">Genetic Disease</td>
                                        <td style="width: 40%;">Yes</td>
                                        <td style="width: 40%;">
                                            @foreach($user->geneticDiseases??[] as $disease)
                                            - {{$disease->geneticDisease->name??''}} - {{$disease->geneticDisease->name_ar??''}} <br>
                                            @endforeach
                                        </td>
                                    </tr>
                                    @else
                                    <tr>
                                        <td style="width: 20%;">Genetic Disease</td>
                                        <td style="width: 40%;">No</td>
                                        <td style="width: 40%;"></td>
                                    </tr>
                                    @endif
                                    <tr>
                                        <td style="width: 20%;">Height</td>
                                        <td style="width: 40%;">{{isset($user->details->height_cm)?$user->details->height_cm.' cm':'N/A'}}</td>
                                        <td style="width: 40%;">{{isset($user->details->height_cm)?$user->details->height_ft.' ft':'N/A'}}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Weight</td>
                                        <td style="width: 40%;">{{isset($user->details->weight_kg)?$user->details->weight_kg.' kg':'N/A'}}</td>
                                        <td style="width: 40%;">{{isset($user->details->weight_lbs)?$user->details->weight_lbs.' lbs':'N/A'}}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Smoking</td>
                                        <td style="width: 40%;">{{ isset($user->details->smoking) && $user->details->smoking == 1 ? 'Yes' : 'No' }}</td>
                                        <td style="width: 40%;"></td>
                                    </tr>
                                    <tr style="display:none;">
                                        <td style="width: 20%;">Religious Practice</td>
                                        <td style="width: 40%;">
                                            @if(isset($user->details->religious_practice))
                                                {{getRelegiousCount($user->details->religious_practice)}}
                                            @else
                                                N/A
                                            @endif
                                        </td>
                                        <td style="width: 40%;">
                                            @if(isset($user->details->religious_practice))
                                                {{getRelegiousCount($user->details->religious_practice, 'ar')}}
                                            @else
                                                N/A
                                            @endif</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Activities</td>
                                        <td style="width: 40%;">@foreach($user->activities as $activity)- {{$activity->activity->name}} @endforeach</td>
                                        <td style="width: 40%;">@foreach($user->activities as $activity)- {{$activity->activity->name_ar}} @endforeach</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Sports</td>
                                        <td style="width: 40%;">@foreach($user->sports as $sport)- {{$sport->sport->name}} <br>@endforeach</td>
                                        <td style="width: 40%;">@foreach($user->sports as $sport)- {{$sport->sport->name_ar}} <br>@endforeach</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Known Language</td>
                                        <td style="width: 40%;">@foreach($user->known_languages??[] as $lang) - {{$lang->language->name}} @endforeach</td>
                                        <td style="width: 40%;"></td>
                                    </tr>
                                    @if($user->gender == 'Male' && isset($user->details->maritalStatus) && $user->details->maritalStatus->show_wife_children_option == true)
                                    <tr style="display:none;">
                                        <td style="width: 20%;">Wives</td>
                                        <td style="width: 40%;">{{isset($user->details->wives)?$user->details->wives:0}}</td>
                                        <td style="width: 40%;"></td>
                                    </tr>
                                    @endif
                                    @if(isset($user->details->children) && $user->details->children > 0)
                                    <tr>
                                        <td style="width: 20%;">Children</td>
                                        <td style="width: 40%;">{{$user->details->children}}</td>
                                        <td style="width: 40%;">@foreach($user->children??[] as $child) Child # {{$child->kid_count}} > {{$child->age}} year <br> @endforeach</td>
                                    </tr>
                                    @endif
                                    <tr style="display:none;">
                                        <td style="width: 20%;">About</td>
                                        <td style="width: 40%;">{{$user->details->about??'N/A'}}</td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <!-- Left Column: Contact Information, Documents, Additional Information, Options -->
                    <div class="col-lg-12">
                        <div class="card mb-3">
                            <div class="card-header py-2" style="background-color: var(--vz-primary);">
                                <h4 class="mb-0 text-white">User Images/Files</h4>
                            </div>
                            <div class="card-body">
                                @foreach($user->images??[] as $image)
                                <a data-fancybox="gallery" href="{{$image->image_url}}">
                                    <img src="{{$image->image_url}}" width="200" height="150" alt="" />
                                </a>
                                @endforeach
                                <a href="{{$user->mothers_emirates_id}}" target="_blank">
                                    Mother's Emirates ID
                                </a>
                                <br>
                                <a href="{{$user->birth_certificate}}" target="_blank">
                                    Birth Certificate
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <!-- Left Column: Contact Information, Documents, Additional Information, Options -->
                    <div class="col-lg-12">
                        <div class="card mb-3">
                            <div class="card-header py-2" style="background-color: var(--vz-primary);">
                                <h4 class="mb-0 text-white">User Preference</h4>
                            </div>
                            <div class="card-body">
                                <table class="table table-sm">
                                    <tr>
                                        <td style="width: 20%;">Sect </td>
                                        <td style="width: 40%;">
                                            @if($user->sects->count() > 0)
                                                @foreach($user->sects as $sect)
                                                    {{$sect->sect?->name??''}}@if(!$loop->last), @endif 
                                                @endforeach
                                            @else
                                                Any
                                            @endif
                                        <td style="width: 40%;">
                                            @if($user->sects->count() > 0)
                                                @foreach($user->sects as $sect)
                                                    {{$sect->sect?->name_ar??''}}@if(!$loop->last), @endif 
                                                @endforeach
                                            @else
                                                لجميع
                                            @endif
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Education</td>
                                        <td style="width: 40%;">
                                            @if($user->educations->count() > 0)
                                                @foreach($user->educations as $ed)
                                                    {{$ed->education?->name??''}}@if(!$loop->last), @endif 
                                                @endforeach
                                            @else
                                                Any
                                            @endif
                                        <td style="width: 40%;">
                                            @if($user->educations->count() > 0)
                                                @foreach($user->educations as $ed)
                                                    {{$ed->education?->name_ar??''}}@if(!$loop->last), @endif 
                                                @endforeach
                                            @else
                                                لجميع
                                            @endif
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Profession</td>
                                        <td style="width: 40%;">
                                            @if($user->professions->count() > 0)
                                                @foreach($user->professions as $ed)
                                                    {{$ed->profession?->name??''}}@if(!$loop->last), @endif  
                                                @endforeach
                                            @else
                                                Any
                                            @endif
                                        <td style="width: 40%;">
                                            @if($user->professions->count() > 0)
                                                @foreach($user->professions as $ed)
                                                    {{$ed->profession?->name_ar??''}}@if(!$loop->last), @endif  
                                                @endforeach
                                            @else
                                                لجميع
                                            @endif
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Marital Status</td>
                                        <td style="width: 40%;">
                                            @if($user->maritalStatuses->count() == 0)
                                            Any
                                            @else
                                            @foreach($user->maritalStatuses??[] as $maritalStatus)
                                            {{ $maritalStatus->maritalStatus->name??'' }}@if(!$loop->last), @endif
                                            @endforeach
                                            @endif
                                         </td>
                                        <td style="width: 40%;">
                                            @if($user->maritalStatuses->count() == 0)
                                            الجميع
                                            @else
                                            @foreach($user->maritalStatuses??[] as $maritalStatus)
                                            {{ $maritalStatus->maritalStatus->name_ar??'' }}@if(!$loop->last), @endif
                                            @endforeach
                                            @endif
                                        </td>
                                    </tr>
                                    <tr style="display:none;">
                                        <td style="width: 20%;">Dress Code</td>
                                        <td style="width: 40%;">
                                            @if($user->dressCodes->count() == 0)
                                            Any
                                            @else
                                            @foreach($user->dressCodes??[] as $dressCode)
                                            {{ $dressCode->dressCode->name??'' }}@if(!$loop->last), @endif
                                            @endforeach
                                            @endif
                                         </td>
                                        <td style="width: 40%;">
                                            @if($user->dressCodes->count() == 0)
                                            الجميع
                                            @else
                                            @foreach($user->dressCodes??[] as $dressCode)
                                            {{ $dressCode->dressCode->name_ar??'' }}@if(!$loop->last), @endif
                                            @endforeach
                                            @endif
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Height</td>
                                        @if(isset($user->preference->height_all) && $user->preference->height_all)
                                        <td style="width: 40%;">All</td>
                                        <td style="width: 40%;">الجميع</td>
                                        @else
                                        @if(empty($user->preference->from_height_cm) && empty($user->preference->to_height_cm))
                                        <td style="width: 40%;">Any</td>
                                        @else
                                            <td style="width: 40%;">{{ number_format($user->preference->from_height_cm??0, 2) }}-{{ number_format($user->preference->to_height_cm??0, 2) }} cm</td>
                                        @endif
                                        @if(empty($user->preference->from_height_ft) && empty($user->preference->to_height_ft))
                                        <td style="width: 40%;">الجميع</td>
                                        @else
                                            <td style="width: 40%;">{{ number_format($user->preference->from_height_ft??0, 2) }}-{{ number_format($user->preference->to_height_ft??0, 2) }} ft</td>
                                        @endif
                                        @endif
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Weight</td>
                                        @if(isset($user->preference->weight_all) && $user->preference->weight_all)
                                        <td style="width: 40%;">Any</td>
                                        <td style="width: 40%;">الجميع</td>
                                        @else
                                        @if(empty($user->preference->from_weight_kg) && empty($user->preference->to_weight_kg))
                                        <td style="width: 40%;">Any</td>
                                        @else
                                            <td style="width: 40%;">{{ number_format($user->preference->from_weight_kg??0, 2) }}-{{ number_format($user->preference->to_weight_kg??0, 2) }} kg</td>
                                        @endif
                                        @if(empty($user->preference->from_weight_lbs) && empty($user->preference->to_weight_lbs))
                                        <td style="width: 40%;">الجميع</td>
                                        @else
                                            <td style="width: 40%;">{{ number_format($user->preference->from_weight_lbs??0, 2) }}-{{ number_format($user->preference->to_weight_lbs??0, 2) }} lbs</td>
                                        @endif
                                        @endif
                                    </tr>
                                    <tr style="display:none;">
                                        <td style="width: 20%;">Religious</td>
                                        <td style="width: 40%;">{{getRelegiousCount($user->details->religious_practice??null) }}</td>
                                        <td style="width: 40%;">{{getRelegiousCount($user->details->religious_practice??null, 'ar') }}</td>
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">Smoke</td>
                                        @if($user->preference->smoking=="")
                                        <td style="width: 40%;">Any</td>
                                        <td style="width: 40%;">الجميع</td>
                                        @else
                                        <td style="width: 40%;">{{ $user->preference->smoking == 1?'Yes':'No' }}</td>
                                        <td style="width: 40%;">{{ $user->preference->smoking == 1?'نعم':'لا' }}</td>
                                        @endif
                                    </tr>
                                    <tr>
                                        <td style="width: 20%;">City Of Residence</td>
                                        <td style="width: 40%;">{{ $user->preference->city_emirate?($user->preference->city_emirate->name??""):"" }}</td>
                                        <td style="width: 40%;">{{ $user->preference->city_emirate?($user->preference->city_emirate->name_ar??""):"" }}</td>
                                    </tr>
                                    
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Back Button -->
                <div class="hstack gap-2 justify-content-between mt-3">
                    <a href="{{ $back }}" class="btn btn-success">Back</a>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="fileViewerModal" tabindex="-1" aria-labelledby="fileViewerModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="fileViewerModalLabel">File Viewer</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <!-- Iframe for supported file types -->
                <embed id="fileViewerIframe" src="" width="100%" height="500px">
                
                <!-- Message for unsupported files -->
               
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      
      <img src = "" width = "100%" class = "img img-thumbnail" id = "display-image">                  

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



@endsection
@section('script')
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js"></script>
<script>
        Fancybox.bind('[data-fancybox="gallery"]', {
        //
      });  

        $("body").on('click', '#updateStatus', function () {
            // Open the modal
            var bookingId = $(this).data('id'); // Get the booking ID from the clicked item
            var currentStatus = $(this).data('status'); // Get the current status
            
            // Set the booking ID in the hidden input field
            $('#bookingId').val(bookingId);
            
            // Disable the current status option in the dropdown
            $('#statusDropdown option').each(function () {
                if ($(this).val() === currentStatus) {
                    $(this).attr('disabled', 'disabled');
                } else {
                    $(this).removeAttr('disabled');
                }
            });
            var firstEnabledOption = $('#statusDropdown option:not(:disabled):first');
            if (firstEnabledOption.length) {
                firstEnabledOption.prop('selected', true);
            }

            // Show the modal
            $('#statusModal').modal('show');
        });

        $("#saveStatus").on('click', function () {
            var newStatus = $('#statusDropdown').val();
            var bookingId = $('#bookingId').val();

            // Send AJAX request to update status
            $.ajax({
                url: updateUrl,
                type: 'PATCH',
                dataType: 'json',
                data: {
                    _token: $('meta[name="csrf-token"]').attr('content'),
                    status: newStatus
                },
                success: function (response) {
                    if (response.status === "success") {
                           
                            Swal.fire({
                                    iconHtml: `<img src="${ASSET_PATH}/success-circle.svg" class="img-fluid">`,
                                    text: response.message,
                                    confirmButtonText: "OK",
                                    customClass: {
                                        confirmButton: 'custom-ok-button-class w-sm'
                                    }
                            }).then(() => {
                                location.reload(); // Redirect to company list
                            });

                        // Close the modal
                        $('#statusModal').modal('hide');
                        // Optionally, reload or update the UI with the new status
                    } else {
                       
                        Swal.fire({
                                    title: "Error!",
                                    text: response.message,
                                    icon: "error",
                                    confirmButtonText: "OK",
                                    confirmButtonColor: "#299cdb"
                                });
                    }
                },
                error: function (xhr) {
                    Swal.fire({
                                    title: "Error!",
                                    text: "Something went wrong. Please try again later.",
                                    icon: "error",
                                    confirmButtonText: "OK",
                                    confirmButtonColor: "#299cdb"
                                });
                }
            });
        });

    </script>

<script>
$(document).ready(function () {
    $(document).on('click','.img-view',function(){
            console.log('asdfasdfasd')
            let src = $(this).attr('src');
            $('#display-image').attr('src',src);
            $('#exampleModalCenter').modal('show');
        })
    $('.view-file-btn').on('click', function () {
        const fileUrl = $(this).data('file-url'); // Get the file URL
        const fileExtension = fileUrl.split('.').pop().toLowerCase();

        if (fileExtension === 'pdf') {
            // Handle PDF file (using native PDF viewer)
            $('#fileViewerIframe').attr('src', fileUrl); 
            $('#fileViewerIframe').attr('type', 'application/pdf');
        } 
        else if (['doc', 'docx'].includes(fileExtension)) {
            // Use Microsoft Office Online Viewer for DOC/DOCX files
            const officeViewerUrl = 'https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(fileUrl);
            $('#fileViewerIframe').attr('src', officeViewerUrl);
        } 
        else {
            // For unsupported file formats, display a message
            $('#fileViewerIframe').attr('src', ''); // Clear iframe
            $('.modal-body').html('<p>Unsupported file format</p>'); // Show message
        }

        // Show the modal
        $('#fileViewerModal').modal('show');
    });
});

    </script>
@endsection

