@extends('layouts.master')
@section('main-body')
@include('modals.confirmation')
<div class="container-fluid">
    <div class="page-header">
        <div class="row">
            <div class="col-sm-12">
                <h3>Professional Management</h3>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="/">Dashboard</a></li>
                    <li class="breadcrumb-item active"><a href="/professionals">Professionals</a></li>
                </ol>

            </div>
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-styling" id="profession-list">
                            <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Profession</th>
                                    <th>Email</th>
                                    <th>Registration Status</th>
                                    <th>Application Status</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($professionals as $professional)
                                <tr>
                                    <td>{!! $professional->profile->first_name . " " . $professional->profile->last_name !!}</td>
                                    <td>
                                        @if ($professional->profession)
                                            {!! $professional->profession->name !!}
                                        @else
                                        Not Available
                                        @endif
                                    </td>
                                    <td>{!! $professional->user->email !!}</td>
                                    <td>
                                        @if ($professional->user->verified)
                                            Email Verified
                                        @else
                                            New
                                        @endif
                                    </td>
                                    <td>@if ($professional->has_applied)
                                            @if ($professional->status == 'pending')
                                                For Review
                                            @else
                                                {!! ucfirst($professional->status) !!}
                                            @endif
                                        @else
                                            New
                                        @endif
                                    </td>
                                        <td>

                                            <div class="d-flex w-25"  style="font-size:30px;">
                                                @if ($loggedUser->can('review-professionals'))
                                                     @if($professional->has_applied)
                                                        <a href="#" class="m-auto text-dark" type="button" id="{{$professional->id}}" onclick="viewDetails(this)"><i class="fa fa-user"></i></a>
                                                        @if ($professional->status == 'pending')
                                                            {!! Form::open(array('route'=>array('professionals.update-status',$professional->id),'class'=>'d-flex justify-content-around align-items-center','method'=>'PUT','id'=>'application-form-'.$professional->id)) !!}
                                                                <i id = "{{ $professional->id }}-approve" onclick = "updateStatus(this)" data-feather="check-circle" class = "text-success" style= "cursor: pointer;margin-left:10px;"></i>
                                                                <i id = "{{ $professional->id }}-decline" onclick = "updateStatus(this)" data-feather="x-circle" class="text-danger"style="cursor: pointer;"></i>
                                                                {!! Form::hidden('status', '', ['id'=>'applicationStatus-'.$professional->id]) !!}
                                                            {!! Form::close() !!}
                                                        @endif
                                                    @endif
                                                @endif
                                            </div>
                                        </td>

                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div>
  <!-- Modal -->
  <div class="modal fade" id="professionalProfileModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl">
        <div style="border-radius: 1em" class="modal-content border-0 px-3 py-2">
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            <x-modal-body label="Details">
                <div class="d-flex align-items-center justify-content-around">

                    <div class="col-2">
                        <img style="width: 100%" class="rounded-circle" src="{{ asset('assets/images/user/avatar.png') }}" alt="My Profile Picture">
                    </div>

                    <div style="height: 12em" class="row flex-wrap col-9 justify-content-between align-content-between">
                        <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                            <label style="font-size: .8rem" for="value" class="fw-light">FirstName</label>
                            <p id = "profileFirstName" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                        </div>
                        <div style="height: 12em" class="row flex-wrap col-9 justify-content-between align-content-between">
                        <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                            <label style="font-size: .8rem" for="value" class="fw-light">MiddleName</label>
                            <p id = "profileMiddleName" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                        </div>
                        <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                            <label style="font-size: .8rem" for="value" class="fw-light">LastName</label>
                            <p id = "profileLastName" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                        </div>
                        <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                            <label style="font-size: .8rem" for="value" class="fw-light">Gender</label>
                            <p id = "profileGender" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                        </div>
                        <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                            <label style="font-size: .8rem" for="value" class="fw-light">Email</label>
                            <p id = "profileEmail" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                        </div>
                        <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                            <label style="font-size: .8rem" for="value" class="fw-light">Mobile Number</label>
                            <p id = "profileMobileNumber" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                        </div>
                    </div>
                </div>
            </x-modal-body>

            <x-modal-body label="Profession">
                <div style="height: 12em" class="row flex-wrap col-11 justify-content-between align-content-between m-auto">
                    <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                        <label style="font-size: .8rem" for="value" class="fw-light">Profession</label>
                        <p id = "profileProfession" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                    </div>
                    <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                        <label style="font-size: .8rem" for="value" class="fw-light">Specialty</label>
                        <p id = "profileSpecialty" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                    </div>
                    <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                        <label style="font-size: .8rem" for="value" class="fw-light">HMO</label>
                        <p id = "profileHMO" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                    </div>
                    <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                        <label style="font-size: .8rem" for="value" class="fw-light">Afiliations</label>
                        <p id = "profileAfiliations" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                    </div>
                </div>
            </x-modal-body>

             <x-modal-body label="Professional Practice">
                <div style="height: 12em" class="row flex-wrap col-11 justify-content-between align-content-between m-auto">
                    <x-read-only-text label="Clinic / Hospital" value="East Avenue Medical Center"/>
                    <x-read-only-text label="Address" value="East Ave, Diliman, Quezon City, 1100 Metro Manila"/>
                    <x-read-only-text label="Region / Provinces" value="National Capital Region"/>
                    <x-read-only-text label="Country" value="Phillipines"/>
                    <x-read-only-text label="City" value="Quezon City"/>
                    <x-read-only-text label="Postal Code" value="1100"/>
                </div>
            </x-modal-body>

            <x-modal-body label="Schedule Section" displayLine="block">
                <div class="row flex-wrap col-10 justify-content-between align-content-between m-auto">
                    <div style="background: #dcdfe0 ;border-radius: 2em" class="p-3">
                        <p class="mx-4 mb-2 fs-5 fw-bold mt-0">Schedules</p>
                    <table style="border-radius: 2em; border-collapse:separate; border-spacing: 0 .3em;" class="table text-center border-0">
                        <thead class="fw-bold">
                            <tr>
                                <td style="border-radius: 1em 0 0 0">Day</td>
                                <td>Time</td>
                                <td style="border-radius: 0 1em 0 0">Consultation Fee</td>
                            </tr>
                        </thead>
                        <tbody class="table-hover">
                            <tr>
                                <td>Monday</td>
                                <td>00:00 PM - 00:00 PM</td>
                                <td>Php 1,000.00</td>
                            </tr>
                            <tr>
                                <td>Teusday</td>
                                <td>00:00 PM - 00:00 PM</td>
                                <td>Php 1,000.00</td>
                        </tr>
                        <tr>
                            <td>Wednesday</td>
                            <td>00:00 PM - 00:00 PM</td>
                            <td>Php 1,000.00</td>
                        </tr>
                        <tr>
                            <td>Thursday</td>
                            <td>00:00 PM - 00:00 PM</td>
                            <td>Php 1,000.00</td>
                        </tr>
                        <tr>
                            <td>Friday</td>
                            <td>00:00 PM - 00:00 PM</td>
                            <td>Php 1,000.00</td>
                        </tr>
                        <tr>
                            <td>Saturday</td>
                            <td>00:00 PM - 00:00 PM</td>
                            <td>Php 1,000.00</td>
                        </tr>
                        <tr>
                            <td style="border-radius: 0 0 0 1em">Sunday</td>
                            <td>00:00 PM - 00:00 PM</td>
                            <td style="border-radius: 0 0 1em 0">Php 1,000.00</td>
                        </tr>
                    </tbody>
                    </table>
                </div>
                </div>
            </x-modal-body>

            <x-modal-body label="Identity Verification Section" displayLine="none">
                <div style="height: 35em" class="row flex-wrap col-11 justify-content-between align-content-between m-auto pb-5">
                    <div style="min-width: 10em;" class="col-auto flex-fill text-muted">
                        <label style="font-size: .8rem" for="value" class="fw-light">PRC Number</label>
                        <p id = "profilePRCNumber" style="font-weight:500" class="fs-5 m-0" id="value" ></p>
                    </div>
                    <x-read-only-text label="Date of Admission" id="dateOfAdmission" value="08/18/22"/>
                    <x-read-only-text label="Birthdate" value="012345"/>

                    <div style="height: 30em" class="row justify-content-between">
                        <div  class = "text-muted col-8">
                            <label style="font-size: .8rem" for="value" class="fw-light">PRC</label>
                            <div style="border-color:  rgb(154, 196, 95) !important; height: 28.5em;" class="border border-3 rounded">
                                <img id = "profilePRCID" style="height: 28em; width: 100%; object-fit: fill"  alt="My Profile Picture">
                            </div>
                        </div>
                        <div  class = "text-muted col-4">
                            <label style="font-size: .8rem" for="value" class="fw-light">PRC</label>
                            <div style="border-color:  rgb(154, 196, 95) !important; height: 28.5em;" class="border border-3 rounded">
                                <img id = "profileSignature" style="height: 28em; width: 100%; object-fit: fill"  alt="My Profile Picture">
                            </div>
                        </div>
                    </div>
                </div>
            </x-modal-body>

        <div class="text-center border-0 p-2">
            <button type="button" id = "profileDecline" class="btn btn-secondary mx-2" data-bs-dismiss="modal">Decline</button>
            <button type="button" id = "profileApprove" class="btn btn-primary mx-2">Approve</button>
        </div>
        </div>
    </div>
</div>
</div>
</div>
@include('modals.professional-profile')

@endsection

@section('page-script')

function viewDetails(elem) {
    window.location.replace('/professionals/'+elem.id+'/application-details');
}

function updateStatus(elem) {

    let element = elem.id.split('-');
    let professionalId = element[0];
    let status = element[1];
    
    if (status === 'approve') {
        $('#confirmation-title').html('Approve');
        $('#confirmation-body').html("Are you sure you want to approve this professional?" );
        $('#submit-btn').html('Approve');
        $('#submit-btn').removeClass('btn-danger');
        $('#submit-btn').addClass('btn-primary');
        $('#applicationStatus-'+professionalId).val('approved');
    } else {
        $('#confirmation-title').html('Decline');
        $('#confirmation-body').html("Are you sure you want to decline this professional?" );
        $('#submit-btn').html('Decline');
        $('#submit-btn').addClass('btn-danger');
        $('#applicationStatus-'+professionalId).val('declined');
    }

    $('#submit-btn').val(professionalId);
    console.log(professionalId)
    console.log('Tess', $('#applicationStatus-'+professionalId).val())
    $('#confirmationModal').modal('show');
}

function submitForm(elem) {
    $('#application-form-'+elem.value).submit();
}

@include('notifications.index')

@endsection
