@extends('admin.layouts.app')
@section('title')
    {{ __('customer_list') }}
@endsection
@php
use Carbon\Carbon;
@endphp
@section('content')
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <div class="row">
                        <div class="col-sm-12 col-md-3 p-1">
                            <h3 class="card-title line-height-36">{{ __('customer_list') }} ({{ @$totalCandidatesCount }})</h3>
                            @if (userCan('followup.view'))
                            <a href="{{ route('candidate.getFollowup') }}" class="ml-2 text-light btn bg-danger mx-0">
                                Pending FollowUp
                                <span
                                    class="badge rounded-pill bg-info">
                                     {{ @$todaysfollupscount }}
                                </span>
                            </a>
                            @endif
                            {{-- <button data-toggle="tooltip" data-placement="top"
                            title="Followup"
                            class="text-light btn bg-warning float-right">
                         
                            <span class="ml-1 text-light    ">
                                Followup
                                <span
                                    class="badge rounded-pill bg-info">
                                     {{ @$todaysfollupscount }}
                                </span>
                            </span>
                        </button> --}}
                        </div>
                        <div class="col align-self-end p-1">
                            @if (userCan('candidate.create'))
                            <a href="{{ route('candidate.create') }}" class="btn bg-primary float-right d-flex align-items-center justify-content-center"><i
                                    class="fas fa-plus mr-1"></i> {{ __('create') }}
                            </a>
                            @endif
                            @if (request('trashed') === 'true') 
                                @if (userCan('candidate.restore'))
                                    <button id="DeleteButton" onclick="MultiRestore()" data-toggle="tooltip" data-placement="top"
                                    title="Restore Selected Customer"
                                    class="DeleteButton d-none mr-1 btn bg-success float-right align-items-center justify-content-center">
                                    <i class="fas fa-trash-restore"></i>
                                    <span class="ml-1">
                                        {{ __('restore') }}
                                        <span id="selectedCount"
                                            class="badge rounded-pill bg-info">
                                        </span>
                                    </span>
                                </button>
                                @endif
                                <a href="{{ route('candidate.index') }}" class="btn mr-1 bg-warning float-right"><i
                                    class="fas fa-arrow-left mr-1"></i>Back
                                </a>
                            @else
                            @if (userCan('candidate.restore'))
                            <a href="{{ route('candidate.index', ['trashed' => 'true']) }}" class="btn mr-1 bg-warning float-right"><i
                                class="fas fa-trash"></i>&nbsp;Trashed
                            </a>
                            @endif
                                @if (userCan('candidate.delete'))
                                    <button id="DeleteButton" onclick="MultiDelete()" data-toggle="tooltip" data-placement="top"
                                    title="Delete Selected Customer"
                                    class="DeleteButton d-none mr-3 btn bg-danger float-right align-items-center justify-content-center">
                                    <i class="fas fa-trash"></i>
                                    <span class="ml-1">
                                        {{ __('delete') }}
                                        <span id="selectedCount"
                                            class="badge rounded-pill bg-info">
                                        </span>
                                    </span>
                                </button>
                                @endif
                            @endif
                    
                            <span class="float-right d-flex align-items-center mx-1 justify-content-center">
                                <span class="mx-2">Sort By: </span>
                            <form id="formSubmit" action="{{ route('candidate.index') }}" method="GET" onchange="this.submit();">
                                                            
                                    {{-- <div class="col-4">
                                        <label>{{ __('search') }}</label>
                                        <input name="keyword" type="text" placeholder="{{ __('search') }}" class="form-control"
                                            value="{{ request('keyword') }}">
                                    </div> --}}
                               
                                    <select name="sort_by"  class="form-control w-100-p">
                                        <option {{ !request('sort_by') || request('sort_by') == 'latest' ? 'selected' : '' }}
                                            value="latest" selected>
                                            {{ __('latest') }}
                                        </option>
                                        <option {{ request('sort_by') == 'last_activity_date' ? 'selected' : '' }} value="last_activity_date">
                                            {{ __('latest') }} {{ __('last') }} {{ __('activity') }}
                                        </option>
                                        {{-- <option {{ request('sort_by') == 'oldest' ? 'selected' : '' }} value="oldest">
                                            {{ __('oldest') }}
                                        </option>

                                        <option {{ request('sort_by') == 'oldestUpdate' ? 'selected' : '' }} value="oldestUpdate">
                                            {{ __('oldest') }} {{ __('last') }} {{ __('activity') }}
                                        </option> --}}
                                    </select>
                                
                            </form>
                            </span>
                                                    
                          
                        </div>
                    </div>
                   
                </div>

              

                {{-- Table  --}}
                <div class="card-body table-responsive p-0">
                    <table class="ll-table table table-hover text-nowrap" style="min-height: 300px !important;">
                        <thead>
                            <tr>
                                @if (userCan('candidate.delete'))
                                @if ($candidates->count() > 0)
                                    <th width="1%">
                                        <div class="icheck-primary ml-1">
                                            <input type="checkbox" id="checkboxAll">
                                            <label for="checkboxAll">
                                            </label>
                                        </div>
                                    </th>
                                @endif
                                @endif
                                <th>ID</th>
                                <th>{{ __('student') }}</th>
                                <th>{{ __('country') }}</th>
                                <th>{{ __('phone') }}</th>
                                <th>{{ __('Source') }}</th>
                                <th>{{ __('Stage') }}</th>
                                <th>{{ __('intake') }}</th>
                                <th>{{ __('category') }}</th>
                                @if (userCan('candidate.update'))
                                {{-- <th width="10%">{{ __('account') }} {{ __('status') }}</th> --}}
                                @endif
                                @if (userCan('candidate.update'))
                                {{-- <th>{{ __('email_verification') }}</th> --}}
                                @endif
                                {{-- <th>{{ __('joined_date') }}</th> --}}
                                <th>{{ __('create') }} {{ __('date') }}</th>
                                <th>{{ __('last') }} {{ __('activity') }}</th>
                                @if (userCan('admin.assign') || userCan('admin.assign_list'))
                                <th width="10%">Assign To</th>
                                @endif
                                <th>Follow up</th>
                                @if (userCan('candidate.update') || userCan('candidate.delete'))
                                    <th>{{ __('action') }}</th>
                                @endif
                            </tr>
                        </thead>
                        <tbody>
                            @if (request('trashed') !== 'true') 
                            <tr>
                                <form id="formSubmit" action="{{ route('candidate.index') }}" method="GET">
                                    @if (userCan('candidate.delete'))
                                    @if ($candidates->count() > 0)
                                    <td>
                                       
                                    </td>
                                    @endif
                                    @endif
                                    @if (userCan('candidate.delete'))
                                    <td>
                                        <input id="id" name="id" type="text" placeholder="ID"
                                        class="form-control" value="{{ request('id') }}">
                                    </td>
                                    @else
                                    <td>
                                        <input id="id" name="id" type="text" placeholder="ID"
                                        class="form-control" value="{{ request('id') }}">
                                    </td>
                                    @endif
                                   
                                    <td>
                                        <input name="name"  id="name" type="text" placeholder="{{ __('name') }} Or {{ __('email') }}"
                                        class="form-control" value="{{ request('name') }}">
                                        {{-- <x-forms.input type="text" name="name"
                                        value="{{ request('name') }}"
                                        placeholder="{{ __(' name') }}" /> --}}
                                        {{-- <input name="name" type="text" placeholder="{{ __('name') }}"
                                            class="" value="{{ request('name') }}"> --}}
                                    </td>
                                    {{-- <td>
                                        <input name="email" id="email"  type="text" placeholder="{{ __('email') }}"
                                            class="form-control" value="{{ request('email') }}">
                                    </td> --}}
                                    <td>
                                        <input id="country" name="country" type="text" placeholder="{{ __('country') }}"
                                            class="form-control" value="{{ request('country') }}">
                                    </td>
                                    <td>
                                        <input name="phone" id="phone" type="text" placeholder="{{ __('phone') }}"
                                            class="form-control" value="{{ request('phone') }}">
                                    </td>
                                    <td>
                                        <select name="source" id="source" class="form-control mr-3">
                                            <option class="d-none" value="">Select</option>
                                            @foreach ($sourcesData as $sd)
                                            <optgroup label="{{ $sd->name }}"> 
                                                @foreach ($sd->source as $ssd)
                                                <option
                                                {{ request('source') == $ssd->name ? 'selected' : '' }}
                                                value="{{ $ssd->name }}"> {{ $ssd->name }}</option>
                                                @endforeach
                                            </optgroup>
                                            @endforeach
                                        </select>
                                    </td>
                                    <td>
                                        <select name="stages"
                                        class="form-control @error('stages') is-invalid @enderror w-100-p select2bs4"
                                        id="stageSelect">
                                        <option>stages</option>
                                        </select>
                                
                                    </td>
                                    <td>
                                        <select name="intake" id="intake"
                                        class="form-control  select2bs4 @error('intake') is-invalid @enderror">
                                        <option value="" class="d-none">
                                            {{ __('select_intake') }}
                                        </option>
                                        <option
                                            {{ "Sept'23" == request('intake') ? 'selected' : '' }}
                                            value="Sept'23">Sept'23</option>
                                        <option
                                            {{ "Jan'24" == request('intake') ? 'selected' : '' }}
                                            value="Jan'24">Jan'24</option>
                                        <option
                                            {{ "Mar'24" == request('intake') ? 'selected' : '' }}
                                            value="Mar'24">Mar'24</option>    
                                        <option
                                            {{ "May'24" == request('intake') ? 'selected' : '' }}
                                            value="May'24">May'24</option>
                                        <option
                                            {{ "E46 Sept'24" == request('intake') ? 'selected' : '' }}
                                            value="E46 Sept'24">E46 Sept'24</option>
                                        <option
                                            {{ "Sept'24" == request('intake') ? 'selected' : '' }}
                                            value="Sept'24">Sept'24</option>

                                        <option
                                            {{ "Jan'25" == request('intake') ? 'selected' : '' }}
                                            value="Jan'25">Jan'25</option>
                                        <option
                                            {{ "May'25" == request('intake') ? 'selected' : '' }}
                                            value="May'25">May'25</option>
                                        <option
                                            {{ "Sept'25" == request('intake') ? 'selected' : '' }}
                                            value="Sept'25">Sept'25</option>

                                            <option
                                            {{ "Jan'26" == request('intake') ? 'selected' : '' }}
                                            value="Jan'26">Jan'26</option>
                                        <option
                                            {{ "May'26" == request('intake') ? 'selected' : '' }}
                                            value="May'26">May'26</option>
                                        <option
                                            {{ "Sept'26" == request('intake') ? 'selected' : '' }}
                                            value="Sept'26">Sept'26</option>
                                     
                                            
                                        </select>
                                     
                                    </td>

                                    <td>
                                        <select name="student_category" id="student_category"
                                        class="form-control  @error('student_category') is-invalid @enderror">
                                        <option value="" class="d-none">
                                            {{ __('select_student_category') }}
                                        </option>
                                        <option
                                            {{ 'Gold' == request('student_category') ? 'selected' : '' }}
                                            value="Gold">{{ __('Gold') }}</option>
                                        <option
                                            {{ 'Silver' == request('student_category') ? 'selected' : '' }}
                                            value="Silver">{{ __('Silver') }}</option>
                                        <option
                                            {{ 'Bronze' == request('student_category') ? 'selected' : '' }}
                                            value="Bronze">{{ __('Bronze') }}</option>
                                        </select>
                                    </td>
                               
                                    <td>
                                        <input type="text" id="daterange" name="daterange" value="{{ request('daterange') }}" class="form-control" autocomplete="off" id="my_txtbox" placeholder="Date Range" readonly/>
                                        @error('start_date')
                                            <span class="text-danger">{{ $message }}</span>
                                        @enderror
                                    </td>
                                     
                                    <td>
                                        <input type="text" id="daterange_activity" name="daterange_activity" value="{{ request('daterange_activity') }}" class="form-control" autocomplete="off" id="my_txtbox_activity" placeholder="Activity Date " readonly/>
                                        @error('start_date')
                                            <span class="text-danger">{{ $message }}</span>
                                        @enderror
                                    </td>
                                    @if (userCan('admin.assign') || userCan('admin.assign_list'))
                                    <td>
                                        <select name="assign_to" id="assign_to" class="form-control mr-3">
                                            <option value="">Assign To</option>
                                            @foreach ($admin_list as $option)
                                                @if (!@empty($option))
                                                <option value="{{ $option['id'] }}"
                                                {{ request('assign_to') == $option['id'] ? 'selected' : '' }}>
                                                {{ $option['name'] }}
                                            </option>
                                                    {{-- <option value="{{ $option['id'] }}"
                                                        {{ old('assign_to', auth('admin')->user()->id) === $option['id'] ? 'selected' : '' }}>
                                                        {{ $option['name'] }}
                                                    </option> --}}
                                                @endif
                                            @endforeach
                                        </select>
                                    </td>
                                    @endif
                                    <td>
                                        <select name="followUp" id="followUp" class="form-control mr-3">
                                            <option value="">FollowUp</option>
                                            <option value="all"   {{ request('followUp') == 'all' ? 'selected' : '' }}>ALL FollowUp</option>
                                            <option value="no_followUp"   {{ request('followUp') == 'no_followUp' ? 'selected' : '' }}>Not FollowUp</option>
                                        </select>
                                    </td>
                                    @if (request('name') || request('student_category') || request('intake') ||request('id') || request('email') || request('source') || request('phone') || request('daterange') || request('country') || request('daterange_activity') || request('stages') || request('followUp'))
                                    <td width="10%">
                                        @if (request('name') || request('student_category') || request('intake') || request('id') || request('email') || request('source') || request('phone') || request('daterange') || request('daterange_activity') || request('stages') || request('followUp') || request('country'))
                                        <a href="{{ route('candidate.index') }}"
                                            class="btn btn-danger align-items-center justify-content-center"><i
                                                class="fas fa-times"></i>
                                        </a>
                                        @endif
                                        <button type="submit" class="btn btn-primary"><i
                                            class="fas fa-search"></i></button>
                                      

                                    </td>
                                    @else
                                    <td>
                                        <button type="submit" class="btn btn-primary"><i
                                            class="fas fa-search mr-2"></i></button>
                                    </a>
                                    </td>
                                    @endif
                                </form>
                            </tr>
                            @endif
                            @if ($candidates->count() > 0)
                                @foreach ($candidates as $candidate)
                                    <tr>
                                        @if (userCan('candidate.delete'))
                                        @if ($candidate->count() > 0)
                                        <td class="text-center items-center">
                                            <div class="icheck-primary ml-1">
                                                <input type="checkbox" data-id={{ $candidate->user_id }}
                                                    class="sub_chk" id="checkbox{{ $candidate->user_id }}">
                                                <label for="checkbox{{ $candidate->user_id }}">
                                                </label>
                                            </div>
                                        </td>
                                        @endif
                                        @endif
                                        <td>{{ $candidate->user_id }}</td>
                                        <td tabindex="0">
                                            <a href="{{ route('candidate.edit', $candidate->id) }}"  class="company">
                                                {{-- <img src="{{ $candidate->photo }}" alt="image"> --}}
                                                <div>
                                                    <h2>{{ @$candidate->user->name }} {{ @$candidate->user->middle_name }} {{ @$candidate->user->last_name }}
                                                        @if(@$candidate->open_auth_id)
                                                        <i class="fas fa-info-circle" data-toggle="tooltip" data-placement="top"
                                                        title="{{ ucwords(adminIdToNameGet($candidate->open_auth_id)) }}"></i>
                                                        @endif
                                                    </h2>
                                                    <p>{{ @$candidate->user->email }}</p>
                                                </div>
                                            </a>
                                        </td>
                                        {{-- <td tabindex="0">
                                            <p class="job-role">{{ $candidate->jobRole->name }}</p>
                                        </td> --}}
                                        {{-- <td tabindex="0">
                                            {{ $candidate->applied_jobs_count }} {{ __('applied_jobs') }}
                                        </td> --}}
                                        <td tabindex="0">
                                            {{ @$candidate->user->country }} 
                                        </td>
                                        <td tabindex="0">
                                            @if(!empty($candidate->user->country_code))
                                            + {{ @$candidate->user->country_code }}  
                                            @endif
                                            {{ @$candidate->user->phone }} 
                                        </td>
                                        <td>
                                            {!! sourceToIcon(@$candidate->user->source) !!}
                                            {{-- {{ @$candidate->user->source }}  --}}
                                        </td>
                                        <td>
                                            {{ @$candidate->user->stages }}  
                                            @php
                                            $document_names_array = array(
                                                'Class 10 Marksheet',
                                                'Class 12 Marksheet',
                                                'Bachelors Degree',
                                                'Masters Degree',
                                                'Diploma',
                                                'Resume',
                                            );

                                            $additional_document_names_array = array(
                                                'LOR 1',
                                                'LOR 2',
                                                'SOP'
                                            );
                                        
                
                                            $found_value = [];
                                            $document_name_toggle_string = "-NA-";
                                            $additional_found_value = [];
                                            $additional_document_name_toggle_string = "-NA-";
                                            
                                            if (!empty(@$candidate->documents)) {
                                                foreach (@$candidate->documents as $key => $value) {
                                                    if ($value->document_subcategory_id == 37) {
                                                        $found_value[] = 'Class 10 Marksheet';
                                                    } elseif ($value->document_subcategory_id == 12) {
                                                        $found_value[] = 'Class 12 Marksheet';
                                                    } elseif ($value->document_subcategory_id == 10) {
                                                        $found_value[] = 'Bachelors Degree';
                                                    } elseif ($value->document_subcategory_id == 11) {
                                                        $found_value[] = 'Masters Degree';
                                                    } elseif ($value->document_subcategory_id == 38) {
                                                        $found_value[] = 'Diploma';
                                                    } elseif ($value->document_subcategory_id == 1) {
                                                        $found_value[] = 'Resume';
                                                    } elseif ($value->document_subcategory_id == 2) {
                                                        $additional_found_value[] = 'LOR 1';
                                                    } elseif ($value->document_subcategory_id == 3) {
                                                        $additional_found_value[] = 'LOR 2';
                                                    } elseif ($value->document_subcategory_id == 5) {
                                                        $additional_found_value[] = 'SOP';
                                                    }
                                                }
                                        
                                                // Keep only unique values
                                                $found_value = array_unique($found_value);
                                                $additional_found_value = array_unique($additional_found_value);

                                                $unique_value = array_diff($document_names_array, $found_value);
                                                $document_name_toggle_string = implode(', ', $unique_value);

                                                $additional_unique_value = array_diff($additional_document_names_array, $additional_found_value);
                                                $additional_document_name_toggle_string = implode(', ', $additional_unique_value);

                                               
                                            }
                                          
                                        @endphp
                                        
                                            @if(@$candidate->user->stages == 'Additional Documents required')
                                            <i class="fas fa-info-circle" data-toggle="tooltip" data-placement="top"
                                            title="{{ @$additional_document_name_toggle_string }}"></i>

                                            @elseif(@$candidate->user->stages == 'Document pending')
                                            <i class="fas fa-info-circle" data-toggle="tooltip" data-placement="top"
                                            title="{{ @$document_name_toggle_string }}"></i>
                                            @endif

                                            
                                            
                                        </td>
                                        @if(!empty(@$candidate->destination[0]->intake))
                                         <td>{{ @$candidate->destination[0]->intake }} </td>
                                        @else
                                         <td>--</td>
                                        @endif

                                        <td>
                                            @if(@$candidate->student_category == 'Gold')
                                            <i class='fas fa-medal' style='color:gold' data-toggle="tooltip" data-placement="top"
                                            title="Gold"></i>
                                            @elseif(@$candidate->student_category == 'Silver')
                                            <i class='fas fa-medal' style='color:Silver' data-toggle="tooltip" data-placement="top"
                                            title="Silver"></i>
                                            @elseif(@$candidate->student_category == 'Bronze')
                                            <i class='fas fa-medal' style='color:#CD7F32' data-toggle="tooltip" data-placement="top"
                                            title="Bronze"></i>
                                            @else
                                            --
                                            @endif  
                                        </td>
                                       
                                        @if (userCan('candidate.update'))
                                            {{-- <td tabindex="0">
                                                <a href="javascript:void(0)" class="active-status">
                                                    <label class="switch ">
                                                        <input data-id="{{ $candidate->user_id }}" type="checkbox"
                                                            class="success status-switch change-active-status"
                                                            {{ $candidate->user->status == 1 ? 'checked' : '' }}>
                                                        <span class="slider round"></span>
                                                    </label>
                                                    <p class="{{ $candidate->user->status == 1 ? 'active' : '' }}" id="status_{{ $candidate->user_id }}">
                                                        {{ $candidate->user->status == 1 ? __('activated') : __('deactivated') }}</p>
                                                </a>
                                            </td> --}}
                                        @endif
                                        @if (userCan('candidate.update'))
                                            {{-- <td tabindex="0">
                                                <a href="javascript:void(0)" class="active-status">
                                                    <label class="switch ">
                                                        <input data-userid="{{ $candidate->user_id }}" type="checkbox"
                                                            class="success email-verification-switch"
                                                            {{ $candidate->user->email_verified_at ? 'checked' : '' }}>
                                                        <span class="slider round"></span>
                                                    </label>
                                                    <p class="{{ $candidate->user->email_verified_at ? 'active' : '' }}" id="verification_status_{{ $candidate->user_id }}">
                                                        {{ $candidate->user->email_verified_at ? __('verified') : __('unverified') }}</p>
                                                </a>
                                            </td> --}}
                                        @endif
                                        <td>
                                            @if (!empty($candidate->user->created_at))
                                                @if (Carbon::parse($candidate->user->created_at)->isToday())
                                                    
                                                    <span data-toggle="tooltip" data-placement="top"
                                                    title="{{ dateMonthTimeFormat($candidate->user->created_at) }}"> {{ date('h:i A', strtotime($candidate->user->created_at)) }}
                                                   </span>
                                                @else
                                                <span data-toggle="tooltip" data-placement="top"
                                                title="{{ dateMonthTimeFormat($candidate->user->created_at) }}"> {{ date('d M', strtotime($candidate->user->created_at)) }}
                                               </span>
                                                @endif
                                            @endif
                                            {{-- @if(!empty($candidate->user->created_at))
                                            {{dateMonthTimeFormat($candidate->user->created_at)}}
                                            @endif --}}
                                        </td>
                                        <td>
                                            @if(!empty($candidate->user->last_activity_date))
                                            <span data-toggle="tooltip" data-placement="top"
                                            title="{{ dateMonthTimeFormat($candidate->user->last_activity_date) }}"> {{ date('d M', strtotime($candidate->user->last_activity_date)) }}
                                           </span>
                                            @else
                                             --
                                            @endif
                                        </td>
                                        @if (userCan('admin.assign'))
                                       
                                        <td>
                                            <div class="assigneeNamehide assign_to_hide{{$candidate->id}}" data-id="{{$candidate->id}}"  >     
                                                @if(!empty($candidate->user->assign_to))
                                               <span class="assigneeNameText{{$candidate->user_id}}"> {{ ucwords(adminIdToNameGet($candidate->user->assign_to)) }} </span>
                                                @else 
                                                <span class="assigneeNameText{{$candidate->user_id}}"> NA </span>
                                                @endif
                                                <i class="fa fa-pencil-alt"></i>
                                            </div>
                                            <div class="assigneeNameShow assign_to_show{{$candidate->id}} d-none" data-id="{{$candidate->id}}"  >   
                                                <select name="assign_to_change" id="" class="form-control mr-3" onchange="assignToChange({{$candidate->user_id}}, this)">
                                                    <option value="">Unassign</option>
                                                    {{-- @foreach ($admin_list->active() as $option) --}}
                                                    @foreach (array_filter($admin_list, function($item) {
                                                        return $item['status'] == 1; // Assuming 'status' is the field indicating active/inactive
                                                    }) as $option)
                                                        @if (!@empty($option))
                                                            <option value="{{ $option['id'] }}"
                                                                {{ old('assign_to', @$candidate->user->assign_to) === $option['id'] ? 'selected' : '' }}>
                                                                {{ $option['name'] }}
                                                            </option>
                                                        @endif
                                                    @endforeach
                                                </select>
                                            </div>
                                        
                                        </td>
                                        @elseif(userCan('admin.assign_list'))
                                        <td>
                                        <div class="" data-id="{{$candidate->id}}"  >     
                                            @if(!empty($candidate->user->assign_to))
                                           <span class=""> {{ ucwords(adminIdToNameGet($candidate->user->assign_to)) }} </span>
                                            @else 
                                            <span class=""> NA </span>
                                            @endif
                                        
                                        </div>
                                        </td>

                                        @else 
                                        <td> <span class=""> NA </span> </td>

                                        @endif
                                        
                                        <td>
                                        <div class="badge-container">
                                            @if(!$candidate->followup->isEmpty())
                                            @if ($candidate->followup->count() > 0)
                                                @foreach ($candidate->followup as $key => $followup)
                                                @if($key == 4)
                                                @break
                                                @endif
                                                {{-- <span class="badge badge-info " data-bs-toggle="popover" title="Type: '{{ @$followup->type }}'  Date: '{{ dateMonthTimeFormat(@$followup->created_at) }}'" data-content="{!! @$followup->comment !!}" data-trigger="hover focus"  data-placement="top">{{ dateMonthTimeFormatOne(@$followup->created_at) }}</span> --}}

                                                @if($followup->follow_up_status == 'Not Connected')
                                                <span class="badge badge-danger " data-bs-toggle="popover" title="@if(!empty($followup->datetime)){{ dateMonthTimeFormat(@$followup->datetime) }}@else {{ dateMonthTimeFormat(@$followup->created_at) }}@endif" data-content="{!! @$followup->comment !!}" data-trigger="hover focus"  data-placement="top">@if(!empty($followup->datetime)){{ dateMonthTimeFormatOne(@$followup->datetime) }}@else {{ dateMonthTimeFormatOne(@$followup->created_at) }}@endif</span>
                                                @else
                                                <span class="badge badge-info " data-bs-toggle="popover" title="@if(!empty($followup->datetime)){{ dateMonthTimeFormat(@$followup->datetime) }}@else {{ dateMonthTimeFormat(@$followup->created_at) }}@endif" data-content="{!! @$followup->comment !!}" data-trigger="hover focus"  data-placement="top">@if(!empty($followup->datetime)){{ dateMonthTimeFormatOne(@$followup->datetime) }}@else {{ dateMonthTimeFormatOne(@$followup->created_at) }}@endif</span>
                                                @endif 
                                                {{-- @if($followup->followup_up == "yes")
                                                <span class="badge badge-info " data-bs-toggle="popover" title="{{ dateMonthTimeFormat(@$followup->datetime) }}" data-content="{!! @$followup->comment !!}" data-trigger="hover focus"  data-placement="top">@if(!empty($followup->datetime)){{ dateMonthTimeFormatOne(@$followup->datetime) }}@else {{ dateMonthTimeFormatOne(@$followup->created_at) }}@endif</span>
                                                @else
                                                <span class="badge badge-info " data-bs-toggle="popover" title="{{ dateMonthTimeFormat(@$followup->created_at) }}" data-content="{!! @$followup->comment !!}" data-trigger="hover focus"  data-placement="top">{{ dateMonthTimeFormatOne(@$followup->created_at) }}</span>
                                                @endif --}}
                                               
                                                @endforeach
                                            @endif
                                            @else
                                            <span class="badge badge-danger">Not Followed</span>
                                            @endif
                                        </div>
                                        </td>
                                        {{-- <td tabindex="0">
                                            {{ Carbon\Carbon::parse($candidate->created_at)->format('d M, Y') }}
                                        </td> --}}
                                        @if (request('trashed') === 'true') 
                                        <td>
                                            @if (userCan('candidate.restore'))
                                            <button onclick="confirmAndRestore({{ $candidate->user_id }});" class="btn ll-p-0">
                                                <i class="fas fa-trash-restore"></i>
                                                {{ __('restore') }}
                                            </button>
                                            @endif 
                                        </td>
                                      
                                        @else
                                            @if (userCan('candidate.update') || userCan('candidate.delete'))
                                            <td class="actions">
                                                <div class="card-header-right">
                                                <div class="btn-group card-option">
                                                <button type="button" class="btn dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                    <svg width="16" height="16" fill="currentColor" class="bi bi-three-dots-vertical" viewBox="0 0 16 16">
                                                        <path d="M9.5 13a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"></path>
                                                        </svg>
                                                </button>
                                                <ul class="list-unstyled card-option dropdown-menu dropdown-menu-right" x-placement="bottom-end" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(45px, 29px, 0px);">
                                                @if (userCan('candidate.update'))
                                                <li>
                                                    <a href="{{ route('candidate.edit', $candidate->id) }}"
                                                        class="dropdown-item">
                                                        <i class="fas fa-edit"></i> 
                                                        Edit
                                                    </a>
                                                </li> 
                                                @endif
                                                @if (userCan('candidate.delete'))
                                                <li>
                                                <form action="{{ route('candidate.destroy', $candidate->id) }}"
                                                    method="POST" class="dropdown-item">
                                                    @method('DELETE')
                                                    @csrf
                                                    <button
                                                        onclick="return confirm('{{ __('are_you_sure_you_want_to_delete_this_item') }}');"
                                                        class="btn ll-p-0">
                                                        <i class="fas fa-trash"></i>
                                                        Delete
                                                    </button>
                                                </form>
                                                </li>
                                                @endif
                                            
                                                @if (userCan('candidate.passwordUpdate'))
                                                <li>
                                                <form action="{{ route('candidate.passwordUpdate', $candidate->user_id) }}"
                                                    method="POST" class="dropdown-item">
                                                    @method('POST')
                                                    @csrf
                                                    <button
                                                    onclick="return confirm('Are you sure you want to update password ?');"
                                                        class="btn ll-p-0">
                                                        
                                                        <i class="fas fa-envelope"></i>
                                                        {{__('password')}} {{__('email')}}
                                                    </button>
                                                </form>
                                                </li>
                                                @endif
                                                @if (userCan('candidate.sendEmail'))
                                                <li>
                                                <form action="{{ route('candidate.welcomeEmail', $candidate->user_id) }}"
                                                    method="POST" class="dropdown-item">
                                                    @method('POST')
                                                    @csrf
                                                    <button
                                                    onclick="return confirm('Are you sure you want to Send Welcome Email ?');"
                                                        class="btn ll-p-0">
                                                        
                                                        <i class="fas fa-envelope"></i>
                                                        Welcome Email
                                                    </button>
                                                </form>
                                                </li>
                                                @endif
                                                @if (userCan('candidate.sendEmail'))
                                                <li>
                                                <form action="{{ route('candidate.callBackEmail', $candidate->user_id) }}"
                                                    method="POST" class="dropdown-item">
                                                    @method('POST')
                                                    @csrf
                                                    <button
                                                    onclick="return confirm('Are you sure you want to Send Call Back Email ?');"
                                                        class="btn ll-p-0">
                                                        
                                                        <i class="fas fa-envelope"></i>
                                                        Call Back Email
                                                    </button>
                                                </form>
                                                </li>
                                                @endif
                                                @if (userCan('candidate.sendEmail'))
                                                <li>
                                                    <a href="#" class="dropdown-item" data-toggle="modal" data-target="#exampleModal_customEmail" data-candidate-id="{{ $candidate->user_id }}" data-candidate-name="{{ @$candidate->user->name }}" data-candidate-email="{{ @$candidate->user->email }}">  
                                                        <i class="fas fa-envelope"></i>
                                                        Custom Email
                                                    </a>
                                                </li>
                                                @endif
                                                @if (userCan('candidate.sendWhatsApp'))
                                                    <li>
                                                        <a href="#" class="btn form-control  dropdown-item" data-toggle="modal" data-target="#exampleModal_customWhatsApp" data-candidate-id="{{ $candidate->user_id }}" data-candidate-name="{{ @$candidate->user->name }}" data-candidate-phone="{{ @$candidate->user->phone }}">  
                                                            <i class="fab fa-whatsapp-square"></i>
                                                            WhatsApp Message
                                                        </a>
                                                    </li>
                                                @endif
                                                </ul>
                                                </div>
                                                </div>
                                            </td>
                                            @endif
                                        @endif
                                      
                                        {{-- @if (userCan('candidate.update') || userCan('candidate.delete'))
                                            <td>
                                                @if (userCan('candidate.view'))
                                                    <a href="{{ route('candidate.show', $candidate->id) }}"
                                                        class="btn ll-btn ll-border-none">
                                                        {{__('view_profile')}}
                                                        <x-svg.table-btn-arrow />
                                                    </a>
                                                @endif
                                                @if (userCan('candidate.update'))
                                                    <a href="{{ route('candidate.edit', $candidate->id) }}"
                                                        class="btn ll-mr-4 ll-p-0">
                                                        <x-svg.table-edit />
                                                    </a>
                                                @endif
                                                @if (userCan('candidate.delete'))
                                                    <form action="{{ route('candidate.destroy', $candidate->id) }}"
                                                        method="POST" class="d-inline">
                                                        @method('DELETE')
                                                        @csrf
                                                        <button
                                                            onclick="return confirm('{{ __('are_you_sure_you_want_to_delete_this_item') }}');"
                                                            class="btn ll-p-0">
                                                            <x-svg.table-delete />
                                                        </button>
                                                    </form>
                                                @endif
                                            </td>
                                        @endif --}}
                                    </tr>
                                @endforeach
                            @else
                                <tr>
                                    <td colspan="8">
                                        {{ __('no_data_found') }}
                                    </td>
                                </tr>
                            @endif
                        </tbody>
                    </table>
                    @if ($candidates->count())
                        <div class="mt-3 d-flex justify-content-center">
                            {{ $candidates->onEachSide(1)->links() }}
                        </div>
                    @endif
                </div>
            </div>
        </div>

        {{-- notes model --}}
        <div class="modal fade" id="exampleModal_customEmail" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Template Email (<span class="templates_user_name">User</span>)</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <input type="hidden" id="templates_id">
                        <div class="row">
                            <div class="col-md-6">
                                <x-forms.label name="Templates Type" :required="false"/> 
                                <select name="templates_type" id="templates_type"
                                class="form-control  @error('student_category') is-invalid @enderror">
                                <option value="" class="d-none">
                                    Select Templates
                                </option>

                               
                                {{-- <option
                                    {{ 'welcomeEmail' == old('templates_type') ? 'selected' : '' }}
                                    value="welcomeEmail">Welcome Email</option>
                                <option
                                    {{ 'callBackEmail' == old('templates_type') ? 'selected' : '' }}
                                    value="callBackEmail">Call Back Email</option> --}}
                                    <option
                                    value="enquiryEmail"  data-class="enquiryEmail">Study Abroad Enquiry</option> 
                                    <option
                                    value="offerLetter"  data-class="offerLetter">Offer Letter</option> 
                                <option
                                    value="customEmail"  data-class="customEmail">Custom Email</option>
                                </select>
                            </div>
                          
                            <div class="col-md-6">
                                <x-forms.label class="optional-field enquiryEmail offerLetter customEmail" name="Subject" :required="false"/>
                                <x-forms.input class="optional-field enquiryEmail offerLetter customEmail templates_subject" type="text" name="templates_subject" value="Custom Email" placeholder="Subject" />
                            </div>
                        </div>
                        <div class="row optional-field customEmail">
                            <div class="col-md-6">
                                <x-forms.label class="optional-field customEmail" name="Attachment File" :required="false"/>
                                <x-forms.input class="optional-field customFile customEmail" id="customFile" type="file" name="customFile" placeholder="File" 
                                    accept=".pdf, .doc, .docx"
                                    onchange="checkFile(this)" 
                                />
                                <small id="fileHelp" class="form-text text-muted">Allowed file extensions: .pdf, .doc, .docx. Maximum file size: 20MB.</small>
                            </div>
                        </div>
                        <div class="row  optional-field enquiryEmail">
                            <div class="col-md-12">
                                <x-forms.label class=" optional-field enquiryEmail" name="Message" :required="false"/>
                            <textarea  id="editor_enquiryEmail" rows="8" type="text" class="form-control editor1" name="templates_message" placeholder="{{ __('enter') }} {{ __('notes') }}">
                                
                              </textarea>
                            </div> 
                        </div>
                        <div class="row  optional-field customEmail">
                            <div class="col-md-12">
                                <x-forms.label class=" optional-field customEmail" name="Message" :required="false"/>
                            <textarea  id="editor_customEmail" rows="8" type="text" class="form-control editor1" name="templates_message" placeholder="{{ __('enter') }} {{ __('notes') }}">
                                
                              </textarea>
                            </div> 
                        </div>
                        <div class="row  optional-field offerLetter">
                            <div class="col-md-12">
                                <x-forms.label class=" optional-field offerLetter" name="Message" :required="false"/>
                            <textarea  id="editor_offerLetter" rows="8" type="text" class="form-control editor1" name="templates_message" placeholder="{{ __('enter') }} {{ __('notes') }}">
                                
                              </textarea>
                            </div> 
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" onclick="customEmail(event)">Send Email</button>
                        <div id="loader1" class="loader1"></div>
                    </div>
                </div>
            </div>
        </div>
       {{-- notes model end --}}

       {{-- WhatsApp --}}
        <div class="modal fade" id="exampleModal_customWhatsApp" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelW" aria-hidden="true">
            <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabelW">WhatsApp (<span class="Wtemplates_user_name">User</span>)</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    {{-- <div class="modal-body">
                        <input type="hidden" id="wtemplates_id">
                        <div class="row">
                        
                            <div class="col-md-6">
                                <x-forms.label name="Name" :required="false"/>
                                <x-forms.input  class="Wtemplates_user_name" type="text" name="Wtemplates_user_name" id="Wtemplates_user_name"  placeholder="Name" />
                                <input type="hidden" id="wtemplates_id">
                                <div class="row">
                                
                                    <div class="col-md-6">
                                        <x-forms.label name="Name" :required="false"/>
                                        <input readonly class="form-control Wtemplates_user_name" type="text" name="Wtemplates_user_name" id="Wtemplates_user_name"  placeholder="Name" />
                                    </div>
                                    <div class="col-md-6">
                                        <x-forms.label name="Phone" :required="false"/>
                                        <x-forms.input class="Wtemplates_user_phone" type="text" name="Wtemplates_user_phone" id="Wtemplates_user_phone"  placeholder="Phone" />
                                    </div>
                                </div>
                                <div class="row">
                                
                                    <div class="col-md-12">
                                        <x-forms.label name="Message" :required="false"/>
                                        <x-forms.input  type="text" name="whatsApp_massage" id="whatsApp_massage"  placeholder="WhatsApp Message" />
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <x-forms.label name="Phone" :required="false"/>
                                <x-forms.input class="Wtemplates_user_phone" type="text" name="Wtemplates_user_phone" id="Wtemplates_user_phone"  placeholder="Phone" />
                            </div>
                        </div>
                        {{-- <div class="row">
                        
                            <div class="col-md-12">
                                <x-forms.label name="Massage" :required="false"/>
                                <x-forms.input  type="text" name="whatsApp_massage" id="whatsApp_massage"  placeholder="WhatsApp Massage" />
                            </div>
                        </div> --}}
                      
                     
                    {{-- </div> --}} 
                      <div class="modal-body">
                        <div class="row">
                            <div class="col-md-6">
                                <input type="hidden" id="wtemplates_id" value="{{ $candidate->user_id }}">
                               
                                <div class="row">
                                
                                    <div class="col-md-6">
                                        <x-forms.label name="Name" :required="false"/>
                                        <input readonly class="form-control Wtemplates_user_name" type="text" name="Wtemplates_user_name" id="Wtemplates_user_name"  value="{{@$candidate->user->name}}" placeholder="Name" />
                                    </div>
                                    @php 
                                    $candidatePhone = @$candidate->user->phone;
                                    $candidateCode =  @$candidate->user->country_code;
                                    $candidateCountry =  @$candidate->user->country;

                                    $newPhone = $candidateCode . $candidatePhone;

                                    if ($candidateCountry === "India") {
                                        $newPhone = $candidateCode . substr($candidatePhone, -10);
                                    }

                                    $newPhone = preg_replace('/\s/', '', $newPhone);
                                    @endphp
                                    <div class="col-md-6">
                                        <x-forms.label name="Phone" :required="false"/>
                                        <x-forms.input class="Wtemplates_user_phone" type="text" name="Wtemplates_user_phone" id="Wtemplates_user_phone" value="{{@$newPhone}}" placeholder="Phone" />
                                    </div>
                                </div>
                                <div class="row">
                                
                                    <div class="col-md-12">
                                        <x-forms.label name="Message" :required="false"/>
                                        <x-forms.input  type="text" name="whatsApp_massage" id="whatsApp_massage"  placeholder="WhatsApp Message" />
                                    </div>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="card">
                                    <div class="card-body">
                                    <h5 class="card-title">Preview</h5>
                                        <pre class="card-text">
Hello <span class="Wtemplates_user_name">{{ ucwords($candidate->user->name) }}</span>,

<span class="Wtemplates_message"></span>

Thanks and Regards
Team Gradding
                                        </pre>
                                    </div>
                                </div>
                            </div>
                        </div>
                     
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary" onclick="customWhatsApp(event)">Send WhatsApp</button>
                        <div id="loader1" class="loader1"></div>
                    </div>
                </div>
            </div>
        </div>
       {{-- end WhatsApp --}}
    </div>
    </div>
@endsection

@section('style')
    <link rel="stylesheet" href="{{ asset('backend') }}/plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
    <style>
        .switch {
            position: relative;
            display: inline-block;
            width: 35px;
            height: 19px;
        }

        /* Hide default HTML checkbox */
        .switch input {
            display: none;
        }

        /* The slider */
        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            -webkit-transition: .4s;
            transition: .4s;
        }

        .slider:before {
            position: absolute;
            content: "";
            height: 15px;
            width: 15px;
            left: 3px;
            bottom: 2px;
            background-color: white;
            -webkit-transition: .4s;
            transition: .4s;
        }

        input.success:checked+.slider {
            background-color: #28a745;
        }

        input:checked+.slider:before {
            -webkit-transform: translateX(15px);
            -ms-transform: translateX(15px);
            transform: translateX(15px);
        }

        /* Rounded sliders */
        .slider.round {
            border-radius: 34px;
        }

        .slider.round:before {
            border-radius: 50%;
        }

        .badge-container {
            display: flex;
            flex-direction: row-reverse;
        }
        .badge {
            margin-left: 5px;
        }
        .loader1 {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #3498db;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            animation: spin 2s linear infinite;
            display: none;
            margin-left: 10px; /* Adjust the margin as per your layout */
            }

            @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
@endsection
@section('script')
    <script src="{{ asset('backend') }}/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>

    <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
    <script src="{{ asset('tinymce/tinymce.min.js') }}" referrerpolicy="origin"></script>
    <script>
        $('.status-switch').on('change', function() {
            var status = $(this).prop('checked') == true ? 1 : 0;
            var id = $(this).data('id');
            $.ajax({
                type: "GET",
                dataType: "json",
                url: '{{ route('candidate.status.change') }}',
                data: {
                    'status': status,
                    'id': id
                },
                success: function(response) {
                    toastr.success(response.message, 'Success');
                }
            });

            if (status == 1) {
                $(`#status_${id}`).text("{{ __('activated') }}")
            }else{
                $(`#status_${id}`).text("{{ __('deactivated') }}")
            }
        });

        $('.email-verification-switch').on('change', function() {
            var status = $(this).prop('checked') == true ? 1 : 0;
            var id = $(this).data('userid');

            $.ajax({
                type: "GET",
                dataType: "json",
                url: '{{ route('company.verify.change') }}',
                data: {
                    'status': status,
                    'id': id
                },
                success: function(response) {
                    toastr.success(response.message, 'Success');
                }
            });

            if (status == 1) {
                $(`#verification_status_${id}`).text("{{ __('verified') }}")
            }else{
                $(`#verification_status_${id}`).text("{{ __('unverified') }}")
            }
        });
    </script>
    <script>
        $(document).ready(function() {
            // validate();
            $('#exampleModal_customEmail').on('show.bs.modal', function(event) {
                
               
            var button = $(event.relatedTarget); 
            var candidateId = button.data('candidate-id'); 
            var candidateName = button.data('candidate-name');
            var candidateEmail = button.data('candidate-email');
            var modal = $(this);
            modal.find('#templates_type').val('');
            modal.find('#customFile').val('');
            
            modal.find('#templates_id').val('');
            modal.find('.templates_user_name').text('');
            modal.find('.templates_user_email').text('');
            $(".optional-field").hide();
            // Set the candidate ID in the hidden input field of the modal
            modal.find('#templates_id').val(candidateId);
            modal.find('.templates_user_name').text(candidateName);
            modal.find('.templates_user_email').text(candidateEmail);
            });

            $('#exampleModal_customWhatsApp').on('show.bs.modal', function(event) {
                
               
                var button = $(event.relatedTarget); 
                var candidateId = button.data('candidate-id'); 
                var candidateName = button.data('candidate-name');
                var candidatePhone = button.data('candidate-phone');
                var modal = $(this);
               
                modal.find('#wtemplates_id').val('');
                modal.find('#Wtemplates_user_name').val('');
                modal.find('#Wtemplates_user_phone').val('');
                modal.find('.Wtemplates_user_name').text('');
                modal.find('.Wtemplates_user_phone').text('');
             
                // Set the candidate ID in the hidden input field of the modal
                modal.find('#wtemplates_id').val(candidateId);
                modal.find('#Wtemplates_user_name').val(candidateName);
                modal.find('#Wtemplates_user_phone').val(candidatePhone);
                modal.find('.Wtemplates_user_name').text(candidateName);
                modal.find('.Wtemplates_user_phone').text(candidatePhone);
                });

            


            var stages_name = "{{ request('stages') }}";
            $.ajax({
                url: "{{ url('stageArray.php') }}?t=" + stages_name,
                success: function(res) {
                    $("#stageSelect").html(res);
                }
            });

            $('#title').keyup(validate);

            $('input[name="daterange"]').daterangepicker({
                autoUpdateInput: false,
                maxDate: new Date(),
                locale: {
                    cancelLabel: 'Clear'
                }
            });
            $('input[name="daterange"]').on('apply.daterangepicker', function(ev, picker) {
                $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format(
                    'MM/DD/YYYY'));
            });

            $('input[name="daterange"]').on('cancel.daterangepicker', function(ev, picker) {
                $(this).val('');
            });
            // date picker end
            $("#my_txtbox").keypress(function(event) {event.preventDefault();});


            $('input[name="daterange_activity"]').daterangepicker({
                autoUpdateInput: false,
                maxDate: new Date(),
                locale: {
                    cancelLabel: 'Clear'
                }
            });
            $('input[name="daterange_activity"]').on('apply.daterangepicker', function(ev, picker) {
                $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format(
                    'MM/DD/YYYY'));
            });

            $('input[name="daterange_activity"]').on('cancel.daterangepicker', function(ev, picker) {
                $(this).val('');
            });
            // date picker end
            $("#my_txtbox_activity").keypress(function(event) {event.preventDefault();});
        });

        function validate() {
            if (
                $('#title').val().length > 0) {
                $('#crossB').removeClass('d-none');
            } else {
                $('#crossB').addClass('d-none');
            }
        }

        $('#formSubmit').on('change', function() {
            $(this).submit();
        });
        

        function RemoveFilter(id) {
            $('#' + id).val('');
            $('#formSubmit').submit();
        }

        // $(".popover").popover({ trigger: "hover" });
        $(document).ready(function() {
            var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
            var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
            return new bootstrap.Popover(popoverTriggerEl)
            });
        });

        $('table').on('click', '.assigneeNamehide', function() {
            let data_id = $(this).data('id');
         
            $('.assign_to_show'+data_id).removeClass('d-none');
            $('.assign_to_hide'+data_id).addClass('d-none');
          
        });


        function assignToChange(id, obj){

            assign_to = $(obj).val();
            // if (confirm("Are you sure you want to assign this User?")) {
                $.ajax({
                    url: "{{ route('candidate.assignToChange') }}",
                    type: "POST",
                    data: {
                        id: id,
                        assign_to: assign_to,
                        _token: '{{ csrf_token() }}'
                    },
                    dataType: 'json',
                    success: function(result) {
                    if(result.status == "1"){
                            toastr.success("Assign User Successfully");
                            $('.assigneeNamehide').removeClass('d-none');
                            $('.assigneeNameShow').addClass('d-none');
                            $('.assigneeNameText'+result.data.id).text(result.data.name);
                            
                        }else{
                            toastr.error("something went wrong");
                        }
                    
                    }
                });
            // }
        }

    </script>
        <script>
            $("#checkboxAll").on('click', function() {
                $('input:checkbox').not(this).prop('checked', this.checked);
                SelectIds();
            });
            $(".sub_chk").on('click', function() {
                SelectIds();
            });
    
            function SelectIds() {
    
                var Ids = [];
                $(".sub_chk:checked").each(function() {
                    Ids.push($(this).attr('data-id'));
                });
                $('#selectedCount').html(parseInt(Ids.length));
                if (Ids != 0) {
                    // Show Delete Button
                    $('.DeleteButton').removeClass('d-none');
                } else {
                    // Hide Delete Button
                    $('.DeleteButton').addClass('d-none');
                }
            }
    
            function MultiDelete() {
    
                var Ids = [];
                $(".sub_chk:checked").each(function() {
                    Ids.push($(this).attr('data-id'));
                });
    
                if (Ids != 0) {
    
                    if (confirm("{{ __('are_you_sure_you_want_to_delete_this_item') }}") == true) {
                        AjaxCall(Ids);
                    } else {
                        return false;
                    }
    
                } else {
                    alert('Please Select First');
                }
            }
    
            function AjaxCall(value) {
                $.ajax({
                    url: "{{ route('candidate.multiple.delete') }}",
                    type: "Delete",
                    data: {
                        ids: value,
                        _token: '{{ csrf_token() }}'
                    },
                    dataType: 'json',
                    success: function(result) {
                        location.reload();
                    }
                });
            };


        </script>
        <script>

            function MultiRestore() {
                
                var Ids = [];
                $(".sub_chk:checked").each(function() {
                    Ids.push($(this).attr('data-id'));
                });

                if (Ids != 0) {

                    if (confirm("{{ __('are_you_sure_you_want_to_restore_this_item') }}") == true) {
                        AjaxCallRestore(Ids);
                    } else {
                        return false;
                    }

                } else {
                    alert('Please Select First');
                }
            }

            function confirmAndRestore(userId) {
                if (confirm('Are you sure you want to restore this?')) {
                    AjaxCallRestore(userId);
                }
            }

            function AjaxCallRestore(value) {
                console.log("Restoring data for user ID:", value);
                $.ajax({
                    url: "{{ route('candidate.multiple.restore') }}",
                    type: "POST",
                    data: {
                        ids: value,
                        _token: '{{ csrf_token() }}'
                    },
                    dataType: 'json',
                    success: function(response) {
                        if (response.success) {
                          toastr.success("Customer Restore Successfully");
                          setTimeout(function() {
                                location.reload();
                            }, 2000);
                        } else {
                            toastr.error("Restoration failed:"+ response.message); 
                            setTimeout(function() {
                                location.reload();
                            }, 2000);
                        }
                    },
                    error: function(xhr, status, error) {
                        alert('An error occurred: ' + error);
                        // Handle the error if the AJAX request fails
                    }
                });
            };
        </script>
        <script>
             tinymce.init({
            selector: `#editor_enquiryEmail`,
            plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount code imagetools fontawesome',
            toolbar: 'fontawesome | searchreplace |undo redo | blocks |bold italic underline strikethrough | align | link image media table | numlist bullist indent outdent',
            // toolbar: 'undo redo | blocks fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat code | fontawesome | searchreplace',
            image_advtab: true,
            // extended_valid_elements: 'svg[*],path[*],use[*]',
            valid_elements: '*[*]',
            valid_children: '*[*]',
            extended_valid_elements: '*[*]',
            file_picker_types: 'image',
            file_picker_callback: function(callback, value, meta) {
            if (meta.filetype === 'image') {
                // Implement your custom file picker logic here
                // For example, you can use an input type=file or open a file picker dialog
                // Once the user selects an image, pass the selected file to the callback
                // using the callback function provided by TinyMCE
            }
            }
         });

         tinymce.init({
            selector: `#editor_customEmail`,
            plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount code imagetools fontawesome',
            toolbar: 'fontawesome | searchreplace |undo redo | blocks |bold italic underline strikethrough | align | link image media table | numlist bullist indent outdent',
            // toolbar: 'undo redo | blocks fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat code | fontawesome | searchreplace',
            image_advtab: true,
            // extended_valid_elements: 'svg[*],path[*],use[*]',
            valid_elements: '*[*]',
            valid_children: '*[*]',
            extended_valid_elements: '*[*]',
            file_picker_types: 'image',
            file_picker_callback: function(callback, value, meta) {
            if (meta.filetype === 'image') {
                // Implement your custom file picker logic here
                // For example, you can use an input type=file or open a file picker dialog
                // Once the user selects an image, pass the selected file to the callback
                // using the callback function provided by TinyMCE
            }
            }
         });


         tinymce.init({
            selector: `#editor_offerLetter`,
            plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount code imagetools fontawesome',
            toolbar: 'fontawesome | searchreplace |undo redo | blocks |bold italic underline strikethrough | align | link image media table | numlist bullist indent outdent',
            // toolbar: 'undo redo | blocks fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat code | fontawesome | searchreplace',
            image_advtab: true,
            // extended_valid_elements: 'svg[*],path[*],use[*]',
            valid_elements: '*[*]',
            valid_children: '*[*]',
            extended_valid_elements: '*[*]',
            file_picker_types: 'image',
            file_picker_callback: function(callback, value, meta) {
            if (meta.filetype === 'image') {
                // Implement your custom file picker logic here
                // For example, you can use an input type=file or open a file picker dialog
                // Once the user selects an image, pass the selected file to the callback
                // using the callback function provided by TinyMCE
            }
            }
         });



         function updateEditorContent(templateType, candidateName) {
            if (templateType === 'enquiryEmail') {
                // Get the content for the enquiryEmail template and set it to the editor
                var enquiryEmailContent = `<p><strong >Dear <span>${candidateName}</span>,</strong></p>
                    <div dir="ltr">
                    <div>
                        <p><span style="font-family: Times New Roman, serif; font-size: medium;">Thank you for expressing your interest in studying abroad. We appreciate your enthusiasm and trust in our services &amp; are confident that we can assist you in securing admission to your desired program at the preferred university.</span></p>
                        <p></p>
                        <p><span style="font-family: Times New Roman, serif; font-size: medium;"><b>Destination Country -&nbsp;</b></span></p>
                        <p><span style="font-family: Times New Roman, serif; font-size: medium;"><b>Program Name -</b></span></p>
                        <p><span style="font-family: Times New Roman, serif; font-size: medium;"><b>Preferred University (if any) -</b></span></p>
                        <p></p>
                        <p><span style="font-family: Times New Roman, serif; font-size: medium;">Please also share the following required&nbsp;documents for thorough profile evaluation.</span></p>
                        <ol>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">10th Marksheet</span></p>
                        </li>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">12th Marksheet</span></p>
                        </li>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">Bachelor&rsquo;s Marksheet</span></p>
                        </li>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">Transcripts</span></p>
                        </li>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">Resume/CV</span></p>
                        </li>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">Passport</span></p>
                        </li>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">English&nbsp;Efficiency Proof (IELTS/PTE)</span></p>
                        </li>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">2 LORs (Letter of Recommendation) </span></p>
                        </li>
                        <li>
                            <p><span style="font-family: Times New Roman, serif; font-size: medium;">Personal Statement (SOP)</span></p>
                        </li>
                        </ol>
                        <p><span style="font-family: Times New Roman, serif; font-size: medium;">Your prompt response and submission of the above documents will enable us to assess your profile accurately and provide you with further assistance tailored to your specific needs.</span></p>
                        <p></p>
                        <p><span style="font-family: Times New Roman, serif; font-size: medium;">Alternatively, if you have any questions or need immediate assistance, please do not hesitate&nbsp;to contact us via&nbsp;</span></p>
                        <span style="font-family: Times New Roman, serif; font-size: medium;"><b>Call </b></span><span style="font-family: Times New Roman, serif; font-size: medium;">or</span><b> WhatsApp at&nbsp; &nbsp;{{$website_setting->whatsapp_number}}</b><span style="font-family: Times New Roman, serif; font-size: medium;">. Our dedicated team is available to address any concerns or queries you may have,&nbsp;</span>
                        <p></p>
                        <p><span style="font-family: Times New Roman, serif; font-size: medium;">Thank&nbsp;you once again for choosing our services. We look forward to receiving your documents and working together to make your study abroad aspirations a reality.</span></p>
                    </div>
                    <div>
                        <div style="color: rgb(34,34,34);">
                        <div>-</div>
                        <div>Thanks &amp; Regards,</div>
                        <table cellpadding="0" cellspacing="0" style="color: rgb(0,0,0); font-family: Arial; font-size: 16px; border-collapse: collapse;">
                            <tbody>
                            <tr>
                                <td style="line-height: 1.2; padding: 0.01px;"><span style="text-transform: initial; font-weight: bold; color: rgb(100,100,100); letter-spacing: 0px; line-height: 1.2;"> <br>&nbsp; &nbsp; Team Gradding </span></td>
                            </tr>
                            <tr>
                                <td>
                                <table cellpadding="0" cellspacing="0" style="border-collapse: collapse;">
                                    <tbody>
                                    <tr>
                                        <td nowrap="nowrap" width="421" style="padding-top: 14px; width: 421px;">
                                        <p style="margin: 0.1px; line-height: 1;"><span style="font-size: 11px; color: rgb(33,33,33);"> <a href="tel:{{@$website_setting->phone}}" rel="nofollow noopener noreferrer" style="color: rgb(17,85,204); text-decoration: unset;" target="_blank"> <span style="line-height: 1.2; color: rgb(33,33,33);">{{@$website_setting->phone}}</span> </a> &nbsp;|&nbsp;&nbsp; <a href="https://www.gradding.com/" rel="nofollow noopener noreferrer" style="color: rgb(17,85,204); text-decoration: unset;" target="_blank" data-saferedirecturl="https://www.google.com/url?q=https://www.gradding.com/&amp;source=gmail&amp;ust=1691320115837000&amp;usg=AOvVaw38FZCAQNqgTXnlONjQEoxU"> <span style="line-height: 1.2; color: rgb(33,33,33);">www.gradding.com</span> </a> &nbsp;|&nbsp;&nbsp; <a href="mailto:{{$setting->email}}" rel="nofollow noopener noreferrer" style="color: rgb(17,85,204); text-decoration: unset;" target="_blank"> <span style="line-height: 1.2; color: rgb(33,33,33);">{{$setting->email}}</span> </a> </span></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td nowrap="nowrap" width="801" style="padding-top: 7px; width: 801px;">
                                        <p style="margin: 0.1px; line-height: 1;"><span style="font-size: 11px; color: rgb(33,33,33);"> <a href="https://maps.google.com/?q=P.%20No.4,%203rd%20Floor,%20Lal%20Niwas,%20Heera%20Bagh,%20Near%20Narayan%20Singh%20Circle,%20Tonk%20Road,%20Jaipur,%20Rajasthan" rel="nofollow noopener noreferrer" style="color: rgb(17,85,204); text-decoration: unset;" target="_blank" data-saferedirecturl="https://www.google.com/url?q=https://maps.google.com/?q%3DP.%2520No.4,%25203rd%2520Floor,%2520Lal%2520Niwas,%2520Heera%2520Bagh,%2520Near%2520Narayan%2520Singh%2520Circle,%2520Tonk%2520Road,%2520Jaipur,%2520Rajasthan&amp;source=gmail&amp;ust=1691320115837000&amp;usg=AOvVaw2Wh5O1jfYxDeB-ONspFB5l"> <span style="line-height: 1.2; color: rgb(33,33,33);">P. No.4, 3rd Floor, Lal Niwas, Heera Bagh, Near Narayan Singh Circle, Tonk Road, Jaipur, Rajasthan</span> </a> </span></p>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                </td>
                            </tr>
                            <tr>
                                <td style="padding: 14px 0.01px 0.01px;">
                                <table border="0" cellpadding="0" cellspacing="0">
                                    <tbody>
                                        <tr>
                                            <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                <a href="{{@$website_setting->facebook}}" target="_Blank"
                                                    style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                    <img style="width:11px;height:21px;" src="https://i.imgur.com/WG1xTUx.png" alt="icons">
                                                </a>
                                            </td>
                                            <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                <a href="{{@$website_setting->twitter}}" target="_Blank"
                                                    style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                    <img style="width:20px;height:16px;" src="https://i.imgur.com/nYdYc4n.png" alt="icons">
                                                </a>
                                            </td>
                                            <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                <a href="{{@$website_setting->instagram}}" target="_Blank"
                                                    style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                    <img style="width:18px;height:19px;" src="https://i.imgur.com/EhfqaPM.png" alt="icons">
                                                </a>
                                            </td>

                                            <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                <a href="{{@$website_setting->pinterest}}" target="_Blank"
                                                    style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                    <img style="width:16px;height:20px;" src="https://i.imgur.com/p8u8BFA.png" alt="icons">
                                                </a>
                                            </td>

                                            <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                <a href="{{@$website_setting->linkedin}}" target="_Blank"
                                                    style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                    <img style="width:17px;height:18px;" src="https://i.imgur.com/wdzPBPP.png" alt="icons">
                                                </a>
                                            </td>
                                            <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                <a href="{{@$website_setting->youtube}}" target="_Blank"
                                                    style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                    <img style="width:23px;height:16px;" src="https://i.imgur.com/7Zf8wM8.png" alt="icons">
                                                </a>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        </div>
                    </div>
                    </div>`;
                tinymce.get("editor_enquiryEmail").setContent(enquiryEmailContent);
            } else if (templateType === 'customEmail') {
              
                var customEmailContent = `<p><strong>Dear <span>${candidateName}</span>,</strong></p>
                            <div dir="ltr">
                            <div>
                                <p><span style="font-family: Times New Roman, serif;"><span style="font-size: medium;">Thank&nbsp;you once again for choosing our services. We look forward to receiving your documents and working together to make your study abroad aspirations a reality.</span></span></p>
                            </div>
                            <div>
                                <div style="color: rgb(34,34,34);">
                                <div>-</div>
                                <div>Thanks &amp; Regards,</div>
                                <table cellpadding="0" cellspacing="0" style="color: rgb(0,0,0); font-family: Arial; font-size: 16px; border-collapse: collapse;">
                                    <tbody>
                                    <tr>
                                        <td style="line-height: 1.2; padding: 0.01px;"><span style="text-transform: initial; font-weight: bold; color: rgb(100,100,100); letter-spacing: 0px; line-height: 1.2;"> <br>&nbsp; &nbsp; Team Gradding </span></td>
                                    </tr>
                                    <tr>
                                        <td>
                                        <table cellpadding="0" cellspacing="0" style="border-collapse: collapse;">
                                            <tbody>
                                            <tr>
                                                <td nowrap="nowrap" width="421" style="padding-top: 14px; width: 421px;">
                                                <p style="margin: 0.1px; line-height: 1;"><span style="font-size: 11px; color: rgb(33,33,33);"> <a href="tel:{{$website_setting->phone}}" rel="nofollow noopener noreferrer" style="color: rgb(17,85,204); text-decoration: unset;" target="_blank"> <span style="line-height: 1.2; color: rgb(33,33,33);">{{$website_setting->phone}}</span> </a> &nbsp;|&nbsp;&nbsp; <a href="https://www.gradding.com/" rel="nofollow noopener noreferrer" style="color: rgb(17,85,204); text-decoration: unset;" target="_blank" data-saferedirecturl="https://www.google.com/url?q=https://www.gradding.com/&amp;source=gmail&amp;ust=1691320115837000&amp;usg=AOvVaw38FZCAQNqgTXnlONjQEoxU"> <span style="line-height: 1.2; color: rgb(33,33,33);">www.gradding.com</span> </a> &nbsp;|&nbsp;&nbsp; <a href="mailto:{{$setting->email}}" rel="nofollow noopener noreferrer" style="color: rgb(17,85,204); text-decoration: unset;" target="_blank"> <span style="line-height: 1.2; color: rgb(33,33,33);">{{$setting->email}}</span> </a> </span></p>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td nowrap="nowrap" width="801" style="padding-top: 7px; width: 801px;">
                                                <p style="margin: 0.1px; line-height: 1;"><span style="font-size: 11px; color: rgb(33,33,33);"> <a href="https://maps.google.com/?q=P.%20No.4,%203rd%20Floor,%20Lal%20Niwas,%20Heera%20Bagh,%20Near%20Narayan%20Singh%20Circle,%20Tonk%20Road,%20Jaipur,%20Rajasthan" rel="nofollow noopener noreferrer" style="color: rgb(17,85,204); text-decoration: unset;" target="_blank" data-saferedirecturl="https://www.google.com/url?q=https://maps.google.com/?q%3DP.%2520No.4,%25203rd%2520Floor,%2520Lal%2520Niwas,%2520Heera%2520Bagh,%2520Near%2520Narayan%2520Singh%2520Circle,%2520Tonk%2520Road,%2520Jaipur,%2520Rajasthan&amp;source=gmail&amp;ust=1691320115837000&amp;usg=AOvVaw2Wh5O1jfYxDeB-ONspFB5l"> <span style="line-height: 1.2; color: rgb(33,33,33);">P. No.4, 3rd Floor, Lal Niwas, Heera Bagh, Near Narayan Singh Circle, Tonk Road, Jaipur, Rajasthan</span> </a> </span></p>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 14px 0.01px 0.01px;">
                                        <table border="0" cellpadding="0" cellspacing="0">
                                            <tbody>
                                                <tr>
                                                    <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                        <a href="{{@$website_setting->facebook}}" target="_Blank"
                                                            style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                            <img style="width:11px;height:21px;" src="https://i.imgur.com/WG1xTUx.png" alt="icons">
                                                        </a>
                                                    </td>
                                                    <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                        <a href="{{@$website_setting->twitter}}" target="_Blank"
                                                            style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                            <img style="width:20px;height:16px;" src="https://i.imgur.com/nYdYc4n.png" alt="icons">
                                                        </a>
                                                    </td>
                                                    <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                        <a href="{{@$website_setting->instagram}}" target="_Blank"
                                                            style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                            <img style="width:18px;height:19px;" src="https://i.imgur.com/EhfqaPM.png" alt="icons">
                                                        </a>
                                                    </td>

                                                    <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                        <a href="{{@$website_setting->pinterest}}" target="_Blank"
                                                            style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                            <img style="width:16px;height:20px;" src="https://i.imgur.com/p8u8BFA.png" alt="icons">
                                                        </a>
                                                    </td>

                                                    <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                        <a href="{{@$website_setting->linkedin}}" target="_Blank"
                                                            style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                            <img style="width:17px;height:18px;" src="https://i.imgur.com/wdzPBPP.png" alt="icons">
                                                        </a>
                                                    </td>
                                                    <td align="left" style="padding-right: 6px; text-align: center; padding-top: 0px;">
                                                        <a href="{{@$website_setting->youtube}}" target="_Blank"
                                                            style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                            <img style="width:23px;height:16px;" src="https://i.imgur.com/7Zf8wM8.png" alt="icons">
                                                        </a>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                </div>
                            </div>
                            </div>`;

                tinymce.get("editor_customEmail").setContent(customEmailContent);
            } else if (templateType === 'offerLetter') {
              
                var offerLetterContent = `
                <table cellspacing="0" cellpadding="0" style="max-width: 100%; width: 100%; background:#EFEFEF;">
                    <tr>
                        <td>
                            <table cellspacing="0" cellpadding="0" style="max-width: 600px; width: 100%; background: #ffffff; margin: 20px auto 0; font-family: Arial, Helvetica, sans-serif; color: #3E3E3E; font-weight: 400;">
                                <tbody>
                                    <tr>
                                        <td style="text-align: center; border-left: 1px solid #d1d1d1; border-right: 1px solid #d1d1d1; border-top: 1px solid #d1d1d1;">
                                            <a href="https://gradding.com/" target="_blank">
                                                <img src="https://i.imgur.com/JUtvZS6.jpg" alt="Welcome to Gradding" class="logo" style="max-width: 100%;">
                                            </a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 15px 20px 0; border-left: 1px solid #d1d1d1; border-right: 1px solid #d1d1d1;">
                                            <strong>Dear <span>${candidateName}</span>,</strong>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 15px 20px 20px; border-left: 1px solid #d1d1d1; border-right: 1px solid #d1d1d1;">
                                            <p style="font-size: 14px; line-height: 18px; color: #101010; margin: 0 0 10px 0;">Warm Greetings!</p>
                                            <p style="font-size: 14px; line-height: 18px; color: #101010; margin: 0 0 15px 0;">We are delighted to inform you that you have received an offer letter from one of the universities you have applied through us.</p>
                                            <p style="font-size: 14px; line-height: 18px; color: #101010; margin: 0;">Please get in touch with your assigned counsellor soon after you receive this email to know the details of your offer and proceed with your admission.</p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="padding: 0 20px 0; border-left: 1px solid #d1d1d1; border-right: 1px solid #d1d1d1;">
                                            <p style="font-size: 15px; line-height: 20px; color: #055aaa; margin: 0;"><strong>We thank you for giving us the chance to serve you.</strong></p>
                                            <p style="font-size: 15px; line-height: 20px; color: #101010; margin: 0; border-bottom: 1px solid #101010; padding: 0 0 15px 0;"><strong>Team <span style="color: #055aaa;">Gradding</span></strong></p>
                                        </td>
                                    </tr>
                                </tbody>
                                <tfoot>			
                                    <tr style="background:#ffffff;">
                                        <td style="padding:5px 0 17px;text-align:center;border-left: 1px solid #d1d1d1;border-right: 1px solid #d1d1d1;border-bottom: 1px solid #d1d1d1;">
                                            <p style="margin: 0; color: #616161; font-size: 13px;  line-height: 18px;  padding: 10px 14px 15px;">
                                                If you have any questions or concerns, please do not hesitate to get in <br class="dnone" >touch with us at <a href="mailto:{{$setting->email}}" style="color: #055aaa; text-decoration:none">{{@$setting->email}}</a> or <a href="tel:{{$website_setting->phone}}"style="color: #055aaa; text-decoration:none" >{{@$website_setting->phone}}</a>
                                            </p>									
                                            <a href="{{@$website_setting->facebook}}" target="_Blank" style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                <img style="width:11px;height:21px;" src="https://i.imgur.com/WG1xTUx.png" alt="icons">
                                            </a>									
                                            <a href="{{@$website_setting->twitter}}" target="_Blank" style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                <img style="width:20px;height:16px;" src="https://i.imgur.com/nYdYc4n.png" alt="icons">
                                            </a>
                                            <a href="{{@$website_setting->instagram}}" target="_Blank" style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                <img style="width:18px;height:19px;" src="https://i.imgur.com/EhfqaPM.png" alt="icons">
                                            </a>
                                            <a href="{{@$website_setting->pinterest}}" target="_Blank" style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                <img style="width:16px;height:20px;" src="https://i.imgur.com/p8u8BFA.png" alt="icons">
                                            </a>
                                            <a href="{{@$website_setting->linkedin}}" target="_Blank" style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                <img style="width:17px;height:18px;" src="https://i.imgur.com/wdzPBPP.png" alt="icons">
                                            </a>									
                                            <a href="{{@$website_setting->youtube}}" target="_Blank" style="text-decoration:none;padding: 0 17px 0 0;display: inline-block;">
                                                <img style="width:23px;height:16px;" src="https://i.imgur.com/7Zf8wM8.png" alt="icons">
                                            </a>											
                                        </td>				
                                    </tr>	
                                </tfoot>
                            </table>
                        </td>
                    </tr>
                </table>`;

              tinymce.get("editor_offerLetter").setContent(offerLetterContent);
          }
        }

        $(".optional-field").hide();
        $("#templates_type").change(function () {
            $(".optional-field").hide();
            var className = $('option:selected', this).data('class').trim();
            templatesHideShowFunction(className);
            var candidateName = $(".templates_user_name").text().trim();
            updateEditorContent(className, candidateName);
        });

        function templatesHideShowFunction(className) {
            
            if (className === 'enquiryEmail') {
                $('#templates_subject').val('Study Abroad Enquiry');
            } else if (className === 'customEmail') {
                $('#templates_subject').val('Custom Email');
            } else if (className === 'offerLetter') {
                $('#templates_subject').val('Congratulations on Acceptance of Your University Application! 🎉');
            }
            
            $("." + className).show();
        }

        // Initial setup on page load
        var initialTemplateType = $("#templates_type").val().trim();
        var initialCandidateName = $(".templates_user_name").text().trim();
        updateEditorContent(initialTemplateType, initialCandidateName);
        templatesHideShowFunction(initialTemplateType);

        
            function customWhatsApp(event) {
                event.preventDefault();
                var id = $('#wtemplates_id').val();
                var name = $('#Wtemplates_user_name').val();
                var phone = $('#Wtemplates_user_phone').val();
                var message = $('#whatsApp_massage').val();
             
    
          
                
                    if (!id) {
                        toastr.error("ID is required.");
                        return;
                    }

                    if (!name) {
                        toastr.error("Name is required.");
                        return;
                    }
                    if (!phone) {
                        toastr.error("Phone is required.");
                        return;
                    }
                    if (!message) {
                        toastr.error("Message is required.");
                        return;
                    }
    
                    const button = event.target;
                    button.style.display = 'none';
                    const loader = document.getElementById('loader1');
                     loader.style.display = 'inline-block';
                    $.ajax({
                        url: "{{ route('candidate.customWhatsApp', ['id' => ':id']) }}".replace(':id', id),
                        type: "post",
                        data: {
                            id: id,
                            name: name,
                            phone: phone,
                            message: message,
                            _token: '{{ csrf_token() }}'
                        },
                        dataType: 'json',
                        success: function (result) {
                            loader.style.display = 'none';
                            button.style.display = 'inline-block';
                                                   
                            toastr.success("WhatsApp Message send successfully!");
                            $('#exampleModal_customWhatsApp').find('[data-dismiss="modal"]').trigger('click');
                        },
                        error: function (xhr, status, error) {
                            loader.style.display = 'none';
                            button.style.display = 'inline-block';
                            // Handle the error response, e.g., show an error message
                            console.error(xhr.responseText);
                            toastr.error("Error WhatsApp Message. Please try again later.");
                        }
                    });
                
            };


            function customEmail(event) {
                event.preventDefault();
                var id = $('#templates_id').val();
                var type = $('#templates_type').val();
                var subject = $('#templates_subject').val();
                var customFile = $('#customFile').val();
                
                var message = null;

                var formData = new FormData();
    
                // Append the selected file to the FormData object
                var customFileInput = document.getElementById('customFile');
                if (customFileInput.files.length > 0) {
                    formData.append('customFile', customFileInput.files[0]);
                }

    
                if (type === 'enquiryEmail') {
                     message = tinymce.get("editor_enquiryEmail").getContent();
                } else if (type === 'customEmail') {
                     message = tinymce.get("editor_customEmail").getContent();
                     var isFileValid = checkFile(customFileInput);
                    if (!isFileValid && customFile) {
                        toastr.error("Invalid file. Please check the file size and type.");
                        return;
                    }
                } else if (type === 'offerLetter') {
                     message = tinymce.get("editor_offerLetter").getContent();
                }
                
                    if (!id) {
                        toastr.error("ID is required.");
                        return;
                    }
        
                    if (!type) {
                        toastr.error("Templates Type is required.");
                        return;
                    }
                         console.log(message);
                    if (!subject || !message) {
                        toastr.error("Templates Subject and Message are required.");
                        return;
                    }
                    const button = event.target;
                    button.style.display = 'none';
                    const loader = document.getElementById('loader1');
                     loader.style.display = 'inline-block';

                    formData.append('id', id);
                    formData.append('type', type);
                    formData.append('subject', subject);
                    formData.append('message', message);
                    formData.append('_token', '{{ csrf_token() }}');
        
                    $.ajax({
                        url: "{{ route('candidate.customEmail', ['id' => ':id']) }}".replace(':id', id),
                        type: "post",
                        data: formData, // Use the FormData object for data
                        contentType: false, // Set to false for FormData
                        processData: false, // Set to false for FormData
                        dataType: 'json',
                        success: function (result) {
                            loader.style.display = 'none';
                            button.style.display = 'inline-block';
                                                   
                            toastr.success("Email send successfully!");
                            $('#exampleModal_customEmail').find('[data-dismiss="modal"]').trigger('click');
                        },
                        error: function (xhr, status, error) {
                            loader.style.display = 'none';
                            button.style.display = 'inline-block';
                            // Handle the error response, e.g., show an error message
                            console.error(xhr.responseText);
                            toastr.error("Error sending email. Please try again later.");
                        }
                    });
                
            };

            function checkFile(input) {
                const maxFileSizeMB = 20;
                const allowedExtensions = ['pdf', 'doc', 'docx'];

                const file = input.files[0];
                if (file) {
                    const fileSizeMB = file.size / (1024 * 1024); // Convert bytes to megabytes
                    const fileExtension = file.name.split('.').pop().toLowerCase();

                    if (fileSizeMB > maxFileSizeMB) {
                        alert('File size exceeds the maximum limit of ' + maxFileSizeMB + 'MB.');
                        input.value = ''; // Clear the file input
                    } else if (!allowedExtensions.includes(fileExtension)) {
                        alert('Invalid file extension. Please select a valid file with extensions: ' + allowedExtensions.join(', '));
                        input.value = ''; // Clear the file input
                    }
                }
            }
        </script>
        
    
@endsection
