
@extends('admin.layouts.leadManagement')
@section('title')
    Lead Management
@endsection
@section('content')

@php
use Carbon\Carbon;

$selectedMonths = is_array(request('intake_month')) ? request('intake_month') : explode(',', request('intake_month'));
$selectedYears = is_array(request('intake_years')) ? request('intake_years') : explode(',', request('intake_years'));
$selectedSources = is_array(request('source_value')) ? request('source_value') : explode(',', request('source_value'));
$requestValues = request('values');

// Define an empty array to store the sub-stages
$subStagesArray = [];

if ($requestValues == 'inquiry') {
    $subStagesArray = ['Inquiry', 'Counselling', 'University to be suggested', 'Universities suggested'];
} elseif ($requestValues == 'application') {
    $subStagesArray = ['Application ready to submit', 'Application submitted', 'Application Rejected', 'Application resubmitted', 'Admission Letter Pending'];
} elseif ($requestValues == 'offer') {
    $subStagesArray = ['Offer Issued','Offer Accepted','Offer Rejected'];
} elseif ($requestValues == 'dropped') {
    $subStagesArray = ['Student backed out / Dropped'];
} elseif ($requestValues == 'feePayment') {
    $subStagesArray = ['Initial Fee / Tuition Fee Deposit'];
} elseif ($requestValues == 'visa') {
    $subStagesArray = ['Visa Rejected', 'Visa Accepted', 'Visa In Process'];
} elseif ($requestValues == 'defered') {
    $subStagesArray = ['Student Defered'];
} elseif ($requestValues == 'workVisa') {
    $subStagesArray = ['Work Visa'];
} elseif ($requestValues == 'testPreparation') {
    $subStagesArray = ['Test Preparation'];
}


// Define an array to store the sub-stages names
$getSubStagesArray = [];

if (!empty($subStagesArray)) {
    $stagesArray = get_stages_array();
    foreach ($subStagesArray as $subStage) {
        foreach ($stagesArray as $stage) {
            if ($stage['name'] == $subStage) {
                $getSubStagesArray[]['name'] = $stage['name'];
            }
        }
    }
} else {
    $getSubStagesArray = get_stages_array();
}
@endphp

<div class="main">
    <div class="top">
        <div class="head-detail">
            <p class="head">Lead Management({{ @$totalCandidatesCount }})</p>
            <p class="values">
                <div class="button-box">
                <a href="{{ route('admin.leadManagement', ['values' => 'notDropped' ,'assign_to' => request('assign_to')]) }}"><span class="label active">Active: <span id="activeTotal">--</span></span></a>
                <div class="tooltip-box active-lead"><svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.5 15C11.6325 15 15 11.6325 15 7.5C15 3.3675 11.6325 0 7.5 0C3.3675 0 0 3.3675 0 7.5C0 11.6325 3.3675 15 7.5 15ZM8.0625 10.5C8.0625 10.8075 7.8075 11.0625 7.5 11.0625C7.1925 11.0625 6.9375 10.8075 6.9375 10.5V6.75C6.9375 6.4425 7.1925 6.1875 7.5 6.1875C7.8075 6.1875 8.0625 6.4425 8.0625 6.75V10.5ZM6.81 4.215C6.8475 4.1175 6.9 4.0425 6.9675 3.9675C7.0425 3.9 7.125 3.8475 7.215 3.81C7.305 3.7725 7.4025 3.75 7.5 3.75C7.5975 3.75 7.695 3.7725 7.785 3.81C7.875 3.8475 7.9575 3.9 8.0325 3.9675C8.1 4.0425 8.1525 4.1175 8.19 4.215C8.2275 4.305 8.25 4.4025 8.25 4.5C8.25 4.5975 8.2275 4.695 8.19 4.785C8.1525 4.875 8.1 4.9575 8.0325 5.0325C7.9575 5.1 7.875 5.1525 7.785 5.19C7.605 5.265 7.395 5.265 7.215 5.19C7.125 5.1525 7.0425 5.1 6.9675 5.0325C6.9 4.9575 6.8475 4.875 6.81 4.785C6.7725 4.695 6.75 4.5975 6.75 4.5C6.75 4.4025 6.7725 4.305 6.81 4.215Z" fill="#B9BCC8"/>
                    </svg>
                <span class="tooltip-text">Active Leads.</span></div>
                </div>

                <div class="button-box">
                <a href="{{ route('admin.leadManagement') }}"><span class=" label total">Total: <span>{{ @$totalCount }}</span></span></a>
                <div class="tooltip-box total-count"><svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.5 15C11.6325 15 15 11.6325 15 7.5C15 3.3675 11.6325 0 7.5 0C3.3675 0 0 3.3675 0 7.5C0 11.6325 3.3675 15 7.5 15ZM8.0625 10.5C8.0625 10.8075 7.8075 11.0625 7.5 11.0625C7.1925 11.0625 6.9375 10.8075 6.9375 10.5V6.75C6.9375 6.4425 7.1925 6.1875 7.5 6.1875C7.8075 6.1875 8.0625 6.4425 8.0625 6.75V10.5ZM6.81 4.215C6.8475 4.1175 6.9 4.0425 6.9675 3.9675C7.0425 3.9 7.125 3.8475 7.215 3.81C7.305 3.7725 7.4025 3.75 7.5 3.75C7.5975 3.75 7.695 3.7725 7.785 3.81C7.875 3.8475 7.9575 3.9 8.0325 3.9675C8.1 4.0425 8.1525 4.1175 8.19 4.215C8.2275 4.305 8.25 4.4025 8.25 4.5C8.25 4.5975 8.2275 4.695 8.19 4.785C8.1525 4.875 8.1 4.9575 8.0325 5.0325C7.9575 5.1 7.875 5.1525 7.785 5.19C7.605 5.265 7.395 5.265 7.215 5.19C7.125 5.1525 7.0425 5.1 6.9675 5.0325C6.9 4.9575 6.8475 4.875 6.81 4.785C6.7725 4.695 6.75 4.5975 6.75 4.5C6.75 4.4025 6.7725 4.305 6.81 4.215Z" fill="#B9BCC8"/>
                    </svg><span class="tooltip-text">Total Leads.</span></div>
                </div>

                <div class="button-box">
                <a href="{{ route('admin.leadManagement', ['followUp' => 'inactive' ,'assign_to' => request('assign_to')]+ request()->all()) }}"><span class="label inactive-follow"> Ignore Leads:  <span id="inactiveFollowCount">--</span></span></a>
                <div class="tooltip-box ignore-leads"><svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <path d="M7.5 15C11.6325 15 15 11.6325 15 7.5C15 3.3675 11.6325 0 7.5 0C3.3675 0 0 3.3675 0 7.5C0 11.6325 3.3675 15 7.5 15ZM8.0625 10.5C8.0625 10.8075 7.8075 11.0625 7.5 11.0625C7.1925 11.0625 6.9375 10.8075 6.9375 10.5V6.75C6.9375 6.4425 7.1925 6.1875 7.5 6.1875C7.8075 6.1875 8.0625 6.4425 8.0625 6.75V10.5ZM6.81 4.215C6.8475 4.1175 6.9 4.0425 6.9675 3.9675C7.0425 3.9 7.125 3.8475 7.215 3.81C7.305 3.7725 7.4025 3.75 7.5 3.75C7.5975 3.75 7.695 3.7725 7.785 3.81C7.875 3.8475 7.9575 3.9 8.0325 3.9675C8.1 4.0425 8.1525 4.1175 8.19 4.215C8.2275 4.305 8.25 4.4025 8.25 4.5C8.25 4.5975 8.2275 4.695 8.19 4.785C8.1525 4.875 8.1 4.9575 8.0325 5.0325C7.9575 5.1 7.875 5.1525 7.785 5.19C7.605 5.265 7.395 5.265 7.215 5.19C7.125 5.1525 7.0425 5.1 6.9675 5.0325C6.9 4.9575 6.8475 4.875 6.81 4.785C6.7725 4.695 6.75 4.5975 6.75 4.5C6.75 4.4025 6.7725 4.305 6.81 4.215Z" fill="#B9BCC8"/>
                    </svg><span class="tooltip-text">Leads that are not connected from past 7 days.</span></div>
                </div>

                <div class="button-box">
                <a href="{{ route('admin.leadManagement', ['followUp' => 'no_followUp' ,'assign_to' => request('assign_to')]+ request()->all()) }}"><span class=" label not-follow">Not Followed: <span id="myNonfollowedcount">--</span></span></a>
                <div class="tooltip-box not-followed"><svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M7.5 15C11.6325 15 15 11.6325 15 7.5C15 3.3675 11.6325 0 7.5 0C3.3675 0 0 3.3675 0 7.5C0 11.6325 3.3675 15 7.5 15ZM8.0625 10.5C8.0625 10.8075 7.8075 11.0625 7.5 11.0625C7.1925 11.0625 6.9375 10.8075 6.9375 10.5V6.75C6.9375 6.4425 7.1925 6.1875 7.5 6.1875C7.8075 6.1875 8.0625 6.4425 8.0625 6.75V10.5ZM6.81 4.215C6.8475 4.1175 6.9 4.0425 6.9675 3.9675C7.0425 3.9 7.125 3.8475 7.215 3.81C7.305 3.7725 7.4025 3.75 7.5 3.75C7.5975 3.75 7.695 3.7725 7.785 3.81C7.875 3.8475 7.9575 3.9 8.0325 3.9675C8.1 4.0425 8.1525 4.1175 8.19 4.215C8.2275 4.305 8.25 4.4025 8.25 4.5C8.25 4.5975 8.2275 4.695 8.19 4.785C8.1525 4.875 8.1 4.9575 8.0325 5.0325C7.9575 5.1 7.875 5.1525 7.785 5.19C7.605 5.265 7.395 5.265 7.215 5.19C7.125 5.1525 7.0425 5.1 6.9675 5.0325C6.9 4.9575 6.8475 4.875 6.81 4.785C6.7725 4.695 6.75 4.5975 6.75 4.5C6.75 4.4025 6.7725 4.305 6.81 4.215Z" fill="#B9BCC8"/>
                </svg><span class="tooltip-text">New assigned leads on which you have not marked any follow-up yet.</span></div>
                </div>
                <img src="{{ asset('backend') }}/loader/three-dot-loader.gif" style="height: 25px;display:none" class="countloader">
            </p>
        </div>

        <form  action="{{ route('admin.leadManagement') }}" class="search-box" method="GET">
            <div class="single-input search">                                                 
                <input type="search" name="keyword" class="input-field" value="{{ request('keyword') }}" id="" placeholder="Search by keyword"
                    aria-label="date">
                <button class="search-btn"  type="submit" aria-label="Search">
                    <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path
                            d="M17.7043 16.2848L14.3054 12.8958C15.402 11.4988 15.9971 9.77351 15.9948 7.99743C15.9948 6.41569 15.5258 4.86947 14.647 3.5543C13.7683 2.23913 12.5192 1.21408 11.0579 0.608771C9.59657 0.00346512 7.98855 -0.15491 6.43721 0.153672C4.88586 0.462254 3.46085 1.22393 2.34239 2.34239C1.22393 3.46085 0.462254 4.88586 0.153672 6.43721C-0.15491 7.98855 0.00346512 9.59657 0.608771 11.0579C1.21408 12.5192 2.23913 13.7683 3.5543 14.647C4.86947 15.5258 6.41569 15.9948 7.99743 15.9948C9.77351 15.9971 11.4988 15.402 12.8958 14.3054L16.2848 17.7043C16.3777 17.798 16.4883 17.8724 16.6101 17.9231C16.7319 17.9739 16.8626 18 16.9945 18C17.1265 18 17.2572 17.9739 17.379 17.9231C17.5008 17.8724 17.6114 17.798 17.7043 17.7043C17.798 17.6114 17.8724 17.5008 17.9231 17.379C17.9739 17.2572 18 17.1265 18 16.9945C18 16.8626 17.9739 16.7319 17.9231 16.6101C17.8724 16.4883 17.798 16.3777 17.7043 16.2848ZM1.99936 7.99743C1.99936 6.81112 2.35114 5.65146 3.01022 4.66508C3.66929 3.6787 4.60606 2.90991 5.70206 2.45593C6.79807 2.00196 8.00408 1.88317 9.16759 2.11461C10.3311 2.34605 11.3999 2.91731 12.2387 3.75615C13.0775 4.595 13.6488 5.66375 13.8802 6.82726C14.1117 7.99077 13.9929 9.19678 13.5389 10.2928C13.0849 11.3888 12.3162 12.3256 11.3298 12.9846C10.3434 13.6437 9.18373 13.9955 7.99743 13.9955C6.40664 13.9955 4.88101 13.3636 3.75615 12.2387C2.6313 11.1138 1.99936 9.58821 1.99936 7.99743Z"
                            fill="white" />
                    </svg>
    
                </button>
            </div>
        </form>
        
        @if(userCan('followup.view'))
        <p class="t-right">
            {{-- <span class="timeline"><img src="{{ asset('backend') }}/lead-management/images/watch.svg" width="100%" height="100%" alt="timeline"></span> --}}
            <a href="{{ route('admin.myfollowup')}}" class="follow-up">Follow Ups</a>
            @if (userCan('candidate.create'))
            {{-- <a href="{{ route('candidate.create') }}" class="create-lead">Create lead</a> --}}
            <a href="javascript::void()" class="create-lead create-lead_open">Create lead</a>
            @endif
        </p>
        @endif
    </div>



    {{-- <div class="tab-list">
        <a href="javascript:;" class="links">Stages</a> &nbsp; &nbsp; &nbsp;
        <p class="tab">
            <a class="tab-link"
                href="{{ route('admin.leadManagement', ['values' => 'inquiry',    
                'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                ,'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "inquiry" ) active @endif ">Inquiry  
                        <span id="inquiryButtonCount"></span>
                </span>
            </a>
            <a href="{{ route('admin.myfollowup', ['values' => 'inquiry',
              'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                ,'assign_to' => request('assign_to')]) }}">
                <span class="count" data-toggle="tooltip" data-placement="top"
                title="Follow Up" id="inquiryPendingCount">0</span>
            </a>
        </p>
        <p class="tab">
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'application',
              'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "application" ) active @endif ">Application  
                    <span id="applicationButtonCount"></span>
                </span>
            </a>
            <a href="{{ route('admin.myfollowup', ['values' => 'application',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span data-toggle="tooltip" data-placement="top"
                title="Follow Up" class="count" id="applicationPendingCount">0</span>
            </a>
        </p>
    
        <p class="tab">
    
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'offer' ,
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "offer" ) active @endif ">Offer  
                    <span id="offerButtonCount"></span>
                </span>
            </a>
            <a href="{{ route('admin.myfollowup', ['values' => 'offer',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span data-toggle="tooltip" data-placement="top"
                title="Follow Up" class="count" id="offerPendingCount">0</span>
            </a>
        </p>
    
        <p class="tab">
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'visa' ,
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "visa" ) active @endif ">Visa  
                    <span id="visaButtonCount"></span> 
                </span>
            </a>
            <a href="{{ route('admin.myfollowup', ['values' => 'visa',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span data-toggle="tooltip" data-placement="top"
                title="Follow Up" class="count" id="visaPendingCount">0</span>
            </a>
        </p>
        <p class="tab">
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'feePayment' ,
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "feePayment" ) active @endif ">Fee Payment 
                    <span id="feePaymentButtonCount"></span>
                </span>
            </a>
            <a href="{{ route('admin.myfollowup', ['values' => 'feePayment',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
             <span data-toggle="tooltip" data-placement="top"
             title="Follow Up" class="count" id="feePaymentPendingCount">0</span>
            </a>
        </p>
        <p class="tab">
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'defered' ,
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "defered" ) active @endif ">Deferred 
                    <span id="deferedButtonCount"></span>
                </span>
            </a>
            <a href="{{ route('admin.myfollowup', ['values' => 'defered',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
             <span data-toggle="tooltip" data-placement="top"
             title="Follow Up" class="count" id="deferedPendingCount">0</span>
            </a>
        </p>

        <p class="tab">
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'dropped' ,
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "dropped" ) active @endif ">Dropped 
                    <span id="droppedButtonCount"></span>
                </span>
            </a>

            <a href="{{ route('admin.myfollowup', ['values' => 'dropped',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span data-toggle="tooltip" data-placement="top"
                title="Follow Up" class="count" id="droppedPendingCount">0</span>
            </a>
        </p>
        <p class="tab">
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'workVisa' ,
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "visa" ) active @endif ">Work Visa  
                    <span id="workVisaButtonCount"></span> 
                </span>
            </a>
            <a href="{{ route('admin.myfollowup', ['values' => 'visa',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span data-toggle="tooltip" data-placement="top"
                title="Follow Up" class="count" id="workVisaPendingCount">0</span>
            </a>
        </p>
    </div> --}}

    <div class="tab-list">
        @php
            $tabs = [
                'Inquiry' => 'inquiry',
                'Application' => 'application',
                'Offer' => 'offer',
                'Visa' => 'visa',
                'Fee Payment' => 'feePayment',
                'Deferred' => 'defered',
                'Dropped' => 'dropped',
                // 'Work Visa' => 'workVisa',
            ];
        @endphp
    
        @foreach ($tabs as $label => $value)
            <a href="{{ route('admin.leadManagement', ['values' => $value] + request()->except('values')) }}">
                <p class="tab">
                    <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => $value] + request()->except('stages')) }}">
                        <span class="tab-item  @if(request('values') == $value) active @endif ">{{ $label }}
                            <span id="{{ $value }}ButtonCount"></span>
                        </span>
                    </a>
                    <a href="{{ route('admin.myfollowup', ['values' => $value] + request()->except('stages')) }}">
                        <span data-toggle="tooltip" data-placement="top" title="Follow Up"
                            class="count" id="{{ $value }}PendingCount">0</span>
                    </a>
                </p>
            </a>
        @endforeach
        <p class="tab">
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'workVisa' ,
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword'),
                'payment_status' => request('payment_status'),
                'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "workVisa" ) active @endif ">Work Visa  
                    <span id="workVisaButtonCount"></span> 
                </span>
            </a>
            {{-- <a href="{{ route('admin.myfollowup', ['values' => 'visa',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span data-toggle="tooltip" data-placement="top"
                title="Follow Up" class="count" id="workVisaPendingCount">0</span>
            </a> --}}
        </p>
        <p class="tab">
            <a class="tab-link" href="{{ route('admin.leadManagement', ['values' => 'testPreparation' ,
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword'),
                'payment_status' => request('payment_status'),
                 'assign_to' => request('assign_to')]) }}">
                <span class="tab-item  @if(request('values') == "testPreparation" ) active @endif ">Test Preparation
                    <span id="testPreparationButtonCount"></span> 
                </span>
            </a>
            {{-- <a href="{{ route('admin.myfollowup', ['values' => 'visa',
            'daterange' => request('daterange'),
                'preferred_country' => request('preferred_country'),
                'lead_type' => request('lead_type'),
                'student_category' => request('student_category'),
                'intake_month' => request('intake_month'),
                'intake_years' =>request('intake_years'),
                'assign_from' => request('assign_from'),
                'keyword' => request('keyword') 
                 ,'assign_to' => request('assign_to')]) }}">
                <span data-toggle="tooltip" data-placement="top"
                title="Follow Up" class="count" id="workVisaPendingCount">0</span>
            </a> --}}
        </p>
    </div>

    <form id="formSubmit" action="{{ route('admin.leadManagement') }}" method="GET" >
        <input type="hidden" name="values" value="{{ request('values') }}"> 
        <input type="hidden" name="followUp" value="{{ request('followUp') }}"> 
        <div class="dropdown-list">
            <div class="single-input date-picker-input">
                <input type="text" class="input-field"  id="daterange" name="daterange" value="{{ request('daterange') }}" placeholder="Date Assign" aria-label="date" readonly>
            </div>
            <div class="single-input date-picker-input">
                <input type="text" class="input-field"  id="daterangeCreated" name="daterangeCreated" value="{{ request('daterangeCreated') }}" placeholder="Date created" aria-label="date" readonly>
            </div>
            <div class="single-input w-drp">
                <select name="preferred_country[]"
                    class="select-list select2-with-search" id="preferred_country">
                    <option value="" disabled selected>
                        Preferred Country
                    </option>
                    @isset($countries)
                    @foreach ($countries as $country)
                        <option
                        @if (!empty(request('preferred_country'))) 
                        @foreach (request('preferred_country') as $key => $preferred_country_id)
                        {{ $country->id == $preferred_country_id ? 'selected' : '' }}   
                        @endforeach 
                        @endif
                            value="{{ $country->id }}">
                            {{ $country->name }}
                        </option>
                    @endforeach
                    @endisset
                </select>
            </div>
            <div class="single-input lead-type-box">
                <select name="lead_type" id="lead_type" class="select-list select2-with-search">
                    <option value="" disabled selected>Lead Type</option>
                    <option
                        {{ 'Cold' == request('lead_type') ? 'selected' : '' }}
                        value="Cold">Cold</option>
                    <option
                        {{ 'Hot' == request('lead_type') ? 'selected' : '' }}
                        value="Hot">Hot</option>
                    <option
                        {{ 'Warm' == request('lead_type') ? 'selected' : '' }}
                        value="Warm">Warm</option>
                </select>
            </div>
            <div class="single-input student-category-box">
                <select name="student_category" id="student_category" class="select-list select2-with-search">
                    <option value="" disabled selected>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>
            </div>
            <div class="single-input intake-month-box">
                <select name="intake_month[]" id="intake_month" class="select-list select2-limit-3 " multiple>
                <option value="" disabled>Intake</option>
                

                <option {{ in_array("Jan", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Jan"; ?>"><?php echo "Jan"; ?></option>
                <option {{ in_array("Feb", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Feb"; ?>"><?php echo "Feb"; ?></option>
                <option {{ in_array("Mar", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Mar"; ?>"><?php echo "Mar"; ?></option>
                <option {{ in_array("Apr", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Apr"; ?>"><?php echo "Apr"; ?></option>
                <option {{ in_array("May", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "May"; ?>"><?php echo "May"; ?></option>
                <option {{ in_array("Jun", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Jun"; ?>"><?php echo "Jun"; ?></option>
                <option {{ in_array("July", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "July"; ?>"><?php echo "July"; ?></option>
                <option {{ in_array("Aug", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Aug"; ?>"><?php echo "Aug"; ?></option>
                <option {{ in_array("Sep", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Sep"; ?>"><?php echo "Sep"; ?></option>
                <option {{ in_array("Oct", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Oct"; ?>"><?php echo "Oct"; ?></option>
                <option {{ in_array("Nov", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Nov"; ?>"><?php echo "Nov"; ?></option>
                <option {{ in_array("Dec", $selectedMonths) ? 'selected' : '' }}
                value="<?php echo "Dec"; ?>"><?php echo "Dec"; ?></option>
                
                </select>
            </div>
            <div class="single-input intake-year-box">
                <select name="intake_years[]" id="intake_years" class="select-list select2-limit-2" multiple>
                    <option value="" disabled>Intake Year</option>
                    @for ($i = 2022; $i <=  date('Y')+3; $i++)
                        <option {{ in_array($i, $selectedYears) ? 'selected' : '' }} value="{{ $i }}">{{ $i }}</option>
                    @endfor
                    
                </select>
            </div>
            <div class="single-input status-box">
                <select name="payment_status" id="payment_status"  class="select-list select2-hide-search">
                    <option value="" selected>Payment</option>
                    <option value="paid"  {{ "paid" == request('payment_status') ? 'selected' : '' }}>Paid</option>
                    <option value="unpaid"  {{ "unpaid" == request('payment_status') ? 'selected' : '' }}>Unpaid</option>
                </select>
            </div>
            <div class="single-input w-drp stage-box">
                <select name="stages" id="stageSelect" class="select-list select2-with-search">
                    <option value="" disabled selected>Sub Stages</option>
                    @foreach ($getSubStagesArray as $item)
                    <option value="{{ $item['name'] }}" 
                    {{ $item['name'] == request('stages') ? 'selected' : '' }} >{{ $item['name'] }}</option>
                    @endforeach
                </select>
            </div>
            <div class="single-input">
                <select name="assign_from" id="assign_from"  class="select-list select2-with-search">
                    <option value=""selected>Assigned From</option>
                    <option value="All" {{ request('assign_from') == 'All' ? 'selected' : '' }}>All</option>
                    {{-- @foreach ($admin_list as $option) --}}
                    @foreach (array_filter($admin_list, function($item) {
                        return $item['status'] == 0; // Assuming 'status' is the field indicating active/inactive
                    }) as $option)
                        @if (!@empty($option))
                            <option value="{{ $option['id'] }}"
                            {{ request('assign_from') == $option['id'] ? 'selected' : '' }}>
                                {{ $option['name'] }}
                            </option>
                        @endif
                    @endforeach
                </select>
            </div>

            @if(userCan('admin.assign_list') || userCan('admin.assign'))
            <div class="single-input">
                <select name="assign_to"  id="assign_to" class="select-list select2-with-search">
                    <option value="">Counsellor</option>
                    <option value="all" {{ request('assign_to') == 'all' ? 'selected' : '' }}>All</option>
                    <option value="na" {{ request('assign_to') == 'na' ? 'selected' : '' }}>Na</option>
                    @foreach (array_filter($admin_list, function($item) {
                        return $item['status'] == 1;
                    }) as $option)
                        @if (!@empty($option))
                            <option value="{{ $option['id'] }}"
                                {{ request('assign_to', Auth::user()->id) == $option['id'] ? 'selected' : '' }}>
                                {{ $option['name'] }}
                            </option>
                        @endif
                    @endforeach
                </select>
            </div>
            @endif

            @if (userCan('candidate.assignedRm'))
            <div class="single-input">
                <select name="assigned_rm"  id="assigned_rm" class="select-list select2-with-search">
                    <option value="">RM</option>
                    <option value="na"  {{ request('assigned_rm') == 'na' ? 'selected' : '' }}>NA</option>
                    {{-- @foreach ($admin_list as $option) --}}
                    @foreach (array_filter($admin_list_Operation, function($item) {
                        return $item['status'] == 1; // Assuming 'status' is the field indicating active/inactive
                    }) as $option)
                        {{-- @if (!@empty($option))
                        <option value="{{ $option['id'] }}"
                        {{ request('assigned_rm') == $option['id'] ? 'selected' : '' }}>
                        {{ $option['name'] }}
                    </option>
                          
                        @endif --}}

                        @if (!empty($option))
                        @php
                            $selected = (!empty(request('assigned_rm')) && request('assigned_rm') == $option['id']) ||
                                        (checkRmEnvRole() && request('assigned_rm', Auth::user()->id) == $option['id'])
                                        ? 'selected'
                                        : '';
                        @endphp
            
                        <option value="{{ $option['id'] }}" {{ $selected }}>
                            {{ $option['name'] }}
                        </option>
                    @endif
                    @endforeach
                </select>
            </div>
            @endif

            <div class="single-input">
                <select name="source_value[]" id="source_value" class="select-list select2-source" multiple>
                    <option value="">Source</option>
                    @foreach ($sourcesData as $sd)
                    <optgroup label="{{ $sd->name }}"> 
                        @foreach ($sd->source as $ssd)
                        <option
                        {{ in_array($ssd->name, $selectedSources) ? 'selected' : '' }}
                        value="{{ $ssd->name }}"> {{ $ssd->name }}</option>
                        @endforeach
                    </optgroup>
                    @endforeach
                </select>
            </div>
          
           

           <button class="filter-btn">
               <svg width="15" height="14" viewBox="0 0 7 6" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0.84375 2.99922L2.6125 4.76797L6.15625 1.23047" stroke="white" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
            </button>
        </div>
        
    </form>
    <div class="btns">
        @if(count(request()->all()) > 0)
        <a href="{{ route('admin.leadManagement') }}" class="links">Clear All</a> 
        @endif
        
        {{-- <button type="submit" class="clear-btn">Clear</button> --}}
    </div>
    
    <div class="detail-list">
        <!--Desktop-->
        <table class="d-table hoverTable" id="leadManagementTable">
            <thead>
                <th class="table-head">ID</th>
                <th class="table-head">Name</th>
                @if(!empty(request('daterange')) && !empty(request('daterangeCreated')))
                  <th class="table-head">Assign Date</th>
                  <th class="table-head">Cr. Date</th>
                @elseif (!empty(request('daterange')))
                  <th class="table-head">Assign Date</th>
                @elseif (!empty(request('daterangeCreated')))
                  <th class="table-head">Cr. Date</th>
                @elseif (checkleadManagerEnvRole())
                  <th class="table-head">Assign Date</th>
                @else
                  <th class="table-head">Cr. Date</th>
                @endif
                <th class="table-head">Mobile Number</th>
                <th class="table-head">Cat.</th>
                <th class="table-head lead-edit">Type <img src="{{ asset('backend') }}/lead-management/images/edit.svg" alt="edit" width="100%" height="100%"></th>
                <th class="table-head">Preferred Country</th>
                {{-- <th class="table-head">Intake</th> --}}
                <th class="table-head">Intake Month</th>
                <th class="table-head">Intake Year</th>
                <th class="table-head">TAT</th>
                <th class="table-head">Sub Stages</th>
                <th class="table-head">Assign To @if(userCan('admin.assign'))<img src="{{ asset('backend') }}/lead-management/images/edit.svg" alt="edit" width="100%" height="100%">@endif</th>
                <th class="table-head">Assign Rm @if(userCan('candidate.assignedRm'))<img src="{{ asset('backend') }}/lead-management/images/edit.svg" alt="edit" width="100%" height="100%">@endif</th>
                <th class="table-head">Last Comment/Next Followup</th>
                <th class="table-head"></th>
                <th class="table-head"></th>
            </thead>

            <tbody>
                    
                @if ($candidates->count() > 0)
                @foreach ($candidates as $candidate)

                <tr @if(!empty(@$candidate->orders_status_paid) && @$candidate->orders_status_paid->count() > 0) class="paid-row" @endif>
                    <td class="table-col">
                        <p class="st-id">
                            <a target="_blank" href="{{ route('lead-management.edit', $candidate->id) }}"  class="link">
                                {{ $candidate->user_id }}
                            </a>
                        </p>
                        <div class="st-detail">
                            <p>{!! sourceToIcon(@$candidate->user->source) !!}</p>
    
                            @if(!$candidate->interested_webinar->isEmpty() && $candidate->interested_webinar->first()->webinar && 
                                   $candidate->interested_webinar->first()->webinar->dateTime)
                                <div class="event">
                                    <p class="webinar">W</p>
                                        <div class="tooltip">
                                            <p class="t-item">
                                                <span class="t-head">Webinar Date :</span><span class="t-value">{{ dateMonthFormat(@$candidate->interested_webinar[0]->webinar->dateTime) }}</span>
                                            </p>
    
                                            <p class="t-item">
                                                <span class="t-head">Webinar Title :</span><span class="t-value">
                                                    {{ @$candidate->interested_webinar[0]->webinar->webinar_name }}
                                                </span>
                                            </p>
                                        </div>
                                </div>
                                @endif
                        
                                @if(!empty(@$candidate->user->assign_from))
                                <div class="event">
                                    <p class="webinar assign">{{ ucwords(substr(adminIdToNameGet(@$candidate->user->assign_from), 0, 1))  }}</p>
                                    <div class="tooltip">
                                        <p class="t-item">
                                            <span class="t-head">Title :</span><span class="t-value">Assigned from {{ ucwords(adminIdToNameGet(@$candidate->user->assign_from)) }}  @if(!empty(@$candidate->user->assign_date)) on ({{ dateMonthFormat(@$candidate->user->assign_date) }}) @endif</span>
                                        </p>
                                    </div>
                                </div>
                                {{-- <span class="badge rounded-pill bg-info" data-toggle="tooltip" data-placement="top"
                                title="Assigned from {{ ucwords(adminIdToNameGet(@$candidate->user->assign_from)) }}  @if(!empty(@$candidate->user->assign_date)) on ({{ dateMonthFormat(@$candidate->user->assign_date) }}) @endif">{{ ucwords(substr(adminIdToNameGet(@$candidate->user->assign_from), 0, 2))  }}</span>
                                --}}
                            @endif 
                        </div>

                        @if(!empty(@$candidate->profile_complete))<span class="per-value" data-toggle="tooltip" data-placement="top"
                        title="Profile Complete">  {{ @$candidate->profile_complete }}%</span> 
                        @else <span class="per-value" data-toggle="tooltip" data-placement="top"
                        title="Profile Complete"> 0%</span> 
                        @endif
                        
                    </td>

                    <td class="table-col">
                        <div class="st-detail">
                           
                            <div class="event">
                                <p class="st-name">
                                    <a target="_blank" href="{{ route('lead-management.edit', $candidate->id) }}"  class="link">
                                        <span class="name">{{ @$candidate->user->name }} {{ @$candidate->user->middle_name }} {{ @$candidate->user->last_name }}</span>
                                
                                    </a>
                                </p>
                                 
                                @php

                                    $jsonServiceString = str_replace(['"', '[', ']'], '',  @$candidate->user->service_id);
                                    $service_ids = explode(",", $jsonServiceString);
                                    $counter = 0;
                                @endphp
                                @if(!empty(@$service_ids) && !empty(@$service_ids[0]))
                                <div class="tooltip">
                                        <span class="small-text visa">Services: 
                                        @forelse ($services as $service)
                                        @if (in_array($service['id'], $service_ids) &&  $service['name'] != "Overseas Education")
                                        @php
                                            $counter++;
                                        @endphp
                                        {{ $counter }}  {{ $service['name'] }}@if (!$loop->last),@endif
                                        @endif
                                        @empty
                                        @endforelse
                                        </span> 
                                </div>
                                @endif
                            </div>
                           
                          
                            @if(!empty(@$candidate->orders_status_paid) && @$candidate->orders_status_paid->count() > 0)
                            <div class="event">
                                <p class="paid">P</p>
                                <div class="tooltip">
                                    {{-- <p class="t-item">
                                        Payment Detail
                                    </p> --}}

                                    @foreach ($candidate->orders_status_paid as $key => $order)
                                        @if($key > 0)
                                        <hr/>
                                        @endif
                                        <p class="t-item">
                                            <span class="t-head">Order Id :</span><span class="t-value">{{ $order->id }}</span>
                                        </p>
                                        @if(!empty(@$order->plan->title))
                                        <p class="t-item">
                                            <span class="t-head">Plan Name :</span><span class="t-value">{{ @$order->plan->title }}</span>
                                        </p>
                                        <p class="t-item">
                                            <span class="t-head">Plan Expiry Date  :</span><span class="t-value">@if(!empty(@$order->plan->duration) && !empty(@$order->plan->created_at)){{ dateMonthFormat(@$order->plan->created_at->addDays(@$order->plan->duration)) }} @else -- @endif</span>
                                        </p>
                                        @endif
                                      
                                    @endforeach
                                </div> 
                            </div> 
                            @endif
                        </div>
                        {{-- @if(@$candidate->user->services->name && @$candidate->user->services->name != "Overseas Education")
                        <span class="small-text visa">{{ @$candidate->user->services->name }}</span>
                        @endif --}}
                        {{-- <span class="small-text">Oversees Edu</span>
                        <span class="small-text visa">Work Visa</span> --}}
                    </td>
                    @if(!empty(request('daterange')) && !empty(request('daterangeCreated')))
                        <td class="table-col">
                            @if (!empty($candidate->user->assign_date))
                            <p class="date-time"><span class="date">{{ date('d M y', strtotime($candidate->user->assign_date)) }}</span> <span class="time">{{ date('h:i A', strtotime($candidate->user->assign_date)) }}</span>
                            </p>
                            @else
                            --
                            @endif
                        </td> 
                        <td class="table-col">
                            @if (!empty($candidate->user->created_at))
                            <p class="date-time"><span class="date">{{ date('d M y', strtotime($candidate->user->created_at)) }}</span> <span class="time">{{ date('h:i A', strtotime($candidate->user->created_at)) }}</span>
                            </p>
                            @else
                            --
                            @endif
                        </td> 
                    @elseif (!empty(request('daterange')))
                        <td class="table-col">
                            @if (!empty($candidate->user->assign_date))
                            <p class="date-time"><span class="date">{{ date('d M y', strtotime($candidate->user->assign_date)) }}</span> <span class="time">{{ date('h:i A', strtotime($candidate->user->assign_date)) }}</span>
                            </p>
                            @else
                            --
                            @endif
                        </td> 
                    @elseif (!empty(request('daterangeCreated')))
                        <td class="table-col">
                            @if (!empty($candidate->user->created_at))
                            <p class="date-time"><span class="date">{{ date('d M y', strtotime($candidate->user->created_at)) }}</span> <span class="time">{{ date('h:i A', strtotime($candidate->user->created_at)) }}</span>
                            </p>
                            @else
                            --
                            @endif
                        </td> 
                    @elseif (checkleadManagerEnvRole())
                        <td class="table-col">
                            @if (!empty($candidate->user->assign_date))
                            <p class="date-time"><span class="date">{{ date('d M y', strtotime($candidate->user->assign_date)) }}</span> <span class="time">{{ date('h:i A', strtotime($candidate->user->assign_date)) }}</span>
                            </p>
                            @else
                            --
                            @endif
                        </td> 
                    @else
                        <td class="table-col">
                            @if (!empty($candidate->user->created_at))
                            <p class="date-time"><span class="date">{{ date('d M y', strtotime($candidate->user->created_at)) }}</span> <span class="time">{{ date('h:i A', strtotime($candidate->user->created_at)) }}</span>
                            </p>
                            @else
                            --
                            @endif
                        </td> 
                    @endif
                  

                

                    <td class="table-col"><span class="mb-no"> @if(!empty($candidate->user->country_code))
                        + {{ @$candidate->user->country_code }}  
                        @endif
                        {{ @$candidate->user->phone }}</span>
                    </td>

                    @if(@$candidate->student_category == 'Gold')
                    <td class="table-col"><img src="{{ asset('backend') }}/lead-management/images/gold.svg" alt="gold" width="100%" height="100%" data-toggle="tooltip" data-placement="top"
                        title="Gold"></td>
                    @elseif(@$candidate->student_category == 'Silver')
                    <td class="table-col"><img src="{{ asset('backend') }}/lead-management/images/silver.svg" alt="silver" width="100%" height="100%" data-toggle="tooltip" data-placement="top"
                        title="Silver"></td>
                    @elseif(@$candidate->student_category == 'Bronze')
                    <td class="table-col"><img src="{{ asset('backend') }}/lead-management/images/bronze.svg" alt="bronze" width="100%" height="100%" data-toggle="tooltip" data-placement="top"
                        title="Bronze"></td>
                    @else
                    <td class="table-col">--</td>
                    @endif  

                    {{-- @if(@$candidate->user->lead_type == 'Hot')
                    <td class="table-col"><span class="type-1">Hot</span></td>
                    @elseif(@$candidate->user->lead_type == 'Cold')
                    <td class="table-col"><span class="type-2">Cold</span></td>
                    @elseif(@$candidate->user->lead_type == 'Warm')
                    <td class="table-col"><span class="type-3">Warm</span></td>
                    @else
                    <td class="table-col">--</td>
                    @endif   --}}


                    <td class="table-col">
                        <div class="lead-section">
                            <div class="leadTypeToggle" id="leadTypeToggle{{ @$candidate->id }}">
                                <a href="javascript:;" class="edit-lead" data-id="{{ @$candidate->user->id }}" data-followupID="{{ @$candidate->id }}" onclick="handleLeadTypeEditClick('leadTypeToggle','leadEditDropdownToggle',{{ @$candidate->id }})">
                                <span class="lead-type">
                                    @if (@$candidate->user->lead_type == 'Hot')
                                        <span class="type-1">Hot</span>
                                    @elseif(@$candidate->user->lead_type == 'Cold')
                                        <span class="type-2">Cold</span>
                                    @elseif(@$candidate->user->lead_type == 'Warm')
                                        <span class="type-3">Warm</span>
                                    @else
                                        <span class="lead-type-placeholder">--</span>
                                    @endif
                                </span>  
                                </a>
                            </div>
                    
                            <!-- Editable dropdown for lead type -->
                            <div class="edit-dropdown leadEditDropdownToggle" id="leadEditDropdownToggle{{ @$candidate->id }}" style="display:none;">
                                <div class="single-input">
                                    <select name="lead_type" class="select-list select2-with-search">
                                        <option value="Cold" {{ @$candidate->user->lead_type == 'Cold' ? 'selected' : '' }}>Cold</option>
                                        <option value="Hot" {{ @$candidate->user->lead_type == 'Hot' ? 'selected' : '' }}>Hot</option>
                                        <option value="Warm" {{ @$candidate->user->lead_type == 'Warm' ? 'selected' : '' }}>Warm</option>
                                    </select>
                                </div>
                                <button class="button button-small leadTypeSave" onclick="handleLeadTypeSaveClick(this, 'leadEdit')" data-id="{{ @$candidate->user->id }}" data-followupID="{{ @$candidate->id }}">Save</button>
                            </div>
                        </div>
                    </td>

                    <td class="table-col"><span class="prf-country">
                        @php
                        $jsonString = str_replace(['"', '[', ']'], '',  @$candidate->destination[0]->preferred_country);
                        $preferred_country_ids = explode(",", $jsonString);
                        $preferredCountryNames = [];
                        foreach ($preferred_country_ids as $preferred_country_id) {
                                $preferredCountryName = countriesIdToNameGet($preferred_country_id); // Replace with your actual function call
                                $preferredCountryNames[] = $preferredCountryName;
                            }
                        @endphp
                        @if($preferredCountryNames)
                        <span data-toggle="tooltip" data-placement="top"
                        title="{!! implode(', ', @$preferredCountryNames) !!}"> {{  @$preferredCountryNames[0] }}
                    </span>
                    
                        @else
                        -NA-
                        @endif
                        </span>
                    </td>
                    

                    @if(!empty(@$candidate->destination[0]->intake_months))
                    @php 
                    $intake_months = explode(",", @$candidate->destination[0]->intake_months);
                    @endphp
                    <td class="table-col">
                        @if($intake_months)
                        <span class="intake" data-toggle="tooltip" data-placement="top"
                            title="{!! implode(', ', @$intake_months) !!}"> {{  @$intake_months[0] == "" ? @$intake_months[1] : @$intake_months[0] }}@if(count($intake_months) > 1)... @endif
                        </span>
                        @else
                        <span class="intake">--</span>
                        @endif
                   
                    </td>
                    @else
                    <td class="table-col">--</td>
                    @endif

                    @if(!empty(@$candidate->destination[0]->intake_years))
                    @php 
                    $intake_years = explode(",", @$candidate->destination[0]->intake_years);
                    @endphp
                    <td class="table-col">
                        @if($intake_years)
                        <span class="intake" data-toggle="tooltip" data-placement="top"
                            title="{!! implode(', ', @$intake_years) !!}"> {{  @$intake_years[0] == "" ? @$intake_years[1] : @$intake_years[0] }}@if(count($intake_years) > 1)... @endif
                        </span>
                        @else
                        <span class="intake">--</span>
                        @endif
                   
                    </td>
                    @else
                    <td class="table-col">--</td>
                    @endif
               

                    <td class="table-col"><span class="tat">--</span></td>
                    
                    <td class="table-col">
                        <span class="sub-stage">{{ @$candidate->user->stages }}</span>
                        @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>
                        @endif

                        
                        
                    </td>

                    @if(userCan('admin.assign'))
                    <td class="table-col">
                        <div class="lead-section">
                        <div class="assignToToggle" id="assignToToggle{{ @$candidate->id }}">
                            <a href="javascript:;" class="edit-lead" data-id="{{ @$candidate->user->id }}" data-followupID="{{ @$candidate->id }}" onclick="handleLeadTypeEditClick('assignToToggle','assignToEditDropdownToggle',{{ @$candidate->id }})">
                                <span class="tat"> {{ ucwords(adminIdToNameGet($candidate->user->assign_to)) }} </span> 
                            </a>
                        </div>
                
                        <!-- Editable dropdown for lead type -->
                        <div class="edit-dropdown assignToEditDropdownToggle" id="assignToEditDropdownToggle{{ @$candidate->id }}" style="display:none;">
                            <div class="single-input">
                                <select name="assign_to_change"  id="" class="select2-with-search">
                                    <option value="">Select Assign To</option>
                                
                                    @foreach (array_filter($admin_list, function($item) {
                                        return $item['status'] == 1;
                                    }) 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>
                            <button class="button button-small leadTypeSave" onclick="handleLeadTypeSaveClick(this,'assignTo')" data-id="{{ @$candidate->user->id }}" data-followupID="{{ @$candidate->id }}">Save</button>
                        </div>
                        </div>
                    </td>
                    {{-- <td class="table-col assigneeNameShow assign_to_show{{$candidate->id}} d-none" data-id="{{$candidate->id}}"  >
                        <select name="assign_to_change"  id="" class="" onchange="assignToChange({{$candidate->user_id}}, this)">
                            <option value="">Select Assign To</option>
                        
                            @foreach (array_filter($admin_list, function($item) {
                                return $item['status'] == 1;
                            }) 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>
                        
                    </td> --}}
                    @else
                    <td class="table-col">
                        @if(!empty($candidate->user->assign_to))
                         <span class="tat"> {{ ucwords(adminIdToNameGet($candidate->user->assign_to)) }} </span>
                        @else 
                         <span class="tat"> NA </span>
                        @endif
                    </td>
                    @endif
                 
                    @if(userCan('candidate.assignedRm'))

                    <td class="table-col">
                        <div class="lead-section">
                        <div class="assignToToggleRm" id="assignToToggleRm{{ @$candidate->id }}">
                            <a href="javascript:;" class="edit-lead" data-id="{{ @$candidate->user->id }}" data-followupID="{{ @$candidate->id }}" onclick="handleLeadTypeEditClick('assignToToggleRm','assignToRmEditDropdownToggle',{{ @$candidate->id }})">
                                <span class="tat"> {{ ucwords(adminIdToNameGet($candidate->user->assigned_rm)) }} </span> 
                            </a>
                        </div>
                
                        <!-- Editable dropdown for lead type -->
                        <div class="edit-dropdown assignToRmEditDropdownToggle" id="assignToRmEditDropdownToggle{{ @$candidate->id }}" style="display:none;">
                            <div class="single-input">
                                <select name="assign_to_rm_change" id="" class="select2-with-search">
                                    <option value="">Select Assign To</option>
                                
                                    @foreach (array_filter($admin_list_Operation, function($item) {
                                        return $item['status'] == 1;
                                    }) as $option)
                                        @if (!@empty($option))
                                            <option value="{{ $option['id'] }}"
                                                {{ old('assigned_rm', @$candidate->user->assigned_rm) === $option['id'] ? 'selected' : '' }}>
                                                {{ $option['name'] }}
                                            </option>
                                        @endif
                                    @endforeach
                                </select>
                            </div>
                            <button class="button button-small leadTypeSave" onclick="handleLeadTypeSaveClick(this,'assignToRm')" data-id="{{ @$candidate->user->id }}" data-followupID="{{ @$candidate->id }}">Save</button>
                        </div>
                        </div>
                    </td>

                    {{-- <td class="table-col assigneeNameShowRM assign_to_rm_show{{$candidate->id}} d-none" data-id="{{$candidate->id}}"  >   
                        <select name="assign_to_rm_change" id="" class="form-control mr-3" onchange="assignToChange({{$candidate->user_id}}, this,'RM')">
                            <option value="">Select Assign To</option>
                        
                            @foreach (array_filter($admin_list_Operation, function($item) {
                                return $item['status'] == 1;
                            }) as $option)
                                @if (!@empty($option))
                                    <option value="{{ $option['id'] }}"
                                        {{ old('assigned_rm', @$candidate->user->assigned_rm) === $option['id'] ? 'selected' : '' }}>
                                        {{ $option['name'] }}
                                    </option>
                                @endif
                            @endforeach
                        </select>
                    </td> --}}
                    @else
                    <td class="table-col">
                        @if(!empty($candidate->user->assigned_rm))
                         <span class="tat"> {{ ucwords(adminIdToNameGet($candidate->user->assigned_rm)) }} </span>
                        @else 
                         <span class="tat"> NA </span>
                        @endif
                    </td>
                    @endif

                    <td class="table-col comment">
                        @if(!$candidate->followup->isEmpty())
                        <div class="cmt-section">
                            <img src="{{ asset('backend') }}/lead-management/images/calender.svg" alt="calender" width="100%" height="100%">
                            <div class="right-side-div">
                                <span class="date">{{ dateMonthFormat(@$candidate->followup[0]->created_at) }}</span>
                                <span class="cmt">{{@$candidate->followup[0]->comment}}</span>

                                <div class="tooltip">
                                 

                                    @foreach (@$candidate->followup as $key => $value) 
                                        @if ($key >= 5)
                                            @break
                                        @endif

                                        <p class="t-item">
                                            <span class="t-head">Date :</span><span class="t-value">{{ dateMonthTimeFormat(@$value->created_at) }}</span>
                                        </p>
                                        @if(!empty(@$value->datetime))
                                        <p class="t-item">
                                            <span class="t-head">Next Date  :</span><span class="t-value">{{ dateMonthTimeFormat(@$value->datetime) }}</span>
                                        </p>
                                        @endif
    
                                        <p class="t-item">
                                            <span class="t-head">Comment :</span><span class="t-value">{{@$value->comment}}</span>
                                        </p>
                                        <hr/>

                                    @endforeach
                                  
                                </div>
                            </div>
                        </div>
                        @else
                        <a href="javascript:;" class="create-link box-link " aria-label="add-icon" onclick="customFollowupModel(event,'{{$candidate->user->id }}','{{$candidate->user->name }}')">
                            <img src="{{ asset('backend') }}/lead-management/images/add.svg"
                             alt="add" width="100%" height="100%">Follow Up
                        </a>
                        @endif
                    </td>

                    <td class="table-col">
                        <div class="btns">
                            <a href="{{  route('lead-management.student_case', $candidate->id) }}" class="common-btn trans-btn">View Case</a>
                            {{-- <a href="javascript:;" class="common-btn create-btn">
                                <img src="{{ asset('backend') }}/lead-management/images/add.svg"
                             alt="add" width="100%" height="100%">
                            </a> --}}
                            <a href="javascript:;" class="common-btn create-btn create-link" aria-label="add-icon" onclick="customFollowupModel(event,'{{$candidate->user->id }}','{{$candidate->user->name }}')">
                                <img src="{{ asset('backend') }}/lead-management/images/add.svg"
                                 alt="add" width="100%" height="100%">
                            </a>
                            
                        </div>
                    </td>
                
                    <td class="table-col"> 
                        <div class="box">
                            <a href="javascript:;" class="dots" aria-label="dots-icon">
                                <img src="{{ asset('backend') }}/lead-management/images/dots.svg" alt="dots-icon" width="100%" height="100%">
                            </a>
                            <p class="drop-box">
                                    <a target="_blank" href="{{ route('lead-management.edit', $candidate->id) }}" class="company box-link">
                                        <img src="{{ asset('backend') }}/lead-management/images/edit.svg" alt="edit" width="100%" height="100%">Edit
                                    </a>
                                    {{-- <a href="javascript:;" class="wp-link box-link" aria-label="whatsapp-icon">
                                        <img src="{{ asset('backend') }}/lead-management/images/whatsapp.svg"
                                            alt="whatsapp" width="100%" height="100%">WhatsApp
                                    </a>    
                                    <a href="javascript:;" class="email-link box-link" aria-label="email-icon">
                                        <img src="{{ asset('backend') }}/lead-management/images/email.svg"
                                                alt="email" width="100%" height="100%">Email
                                    </a>
                                    <a href="javascript:;" class="create-link box-link" aria-label="add-icon">
                                        <img src="{{ asset('backend') }}/lead-management/images/add.svg"
                                            alt="add" width="100%" height="100%">Add
                                    </a> --}}

                                    @if (userCan('candidate.sendWhatsApp'))
                                    <a href="javascript:;" class="wp-link box-link" aria-label="whatsapp-icon" onclick="customWhatsApp(event, '{{$candidate->user->id }}', '{{$candidate->user->name }}', '{{$candidate->user->phone }}', '{{@$candidate->user->country_code }}','{{@$candidate->user->country }}')">
                                        <img src="{{ asset('backend') }}/lead-management/images/whatsapp.svg"
                                         alt="whatsapp" width="100%" height="100%">WhatsApp
                                    </a>
                                    {{-- <a href="javascript:;" class="wp-link box-link" aria-label="whatsapp-icon"
                                                    onclick="customWhatsApp(event,'{{ $candidate->user->id }}', '{{ $candidate->user->name }}', '{{ $candidate->user->phone }}')"><img
                                                        src="{{ asset('backend') }}/lead-management/images/whatsapp.svg"
                                                        alt="whatsapp" width="100%" height="100%"></a>     --}}
                                    @endif
                                    @if (userCan('candidate.sendEmail'))
                                    <a href="javascript:;" class="email-link box-link" aria-label="email-icon" onclick="customSendEmailModel('{{$candidate->user->id }}', '{{$candidate->user->name }}', '{{$candidate->user->email }}')">
                                        <img src="{{ asset('backend') }}/lead-management/images/email.svg"
                                          alt="email" width="100%" height="100%">Email
                                    </a>

                                    <a href="javascript:;" class="box-link" aria-label="email-icon" onclick="callBackEmailButton('{{$candidate->user->id }}')">
                                        <img src="{{ asset('backend') }}/lead-management/images/email.svg"
                                          alt="email" width="100%" height="100%">Call Back Email
                                    </a>

                                    <a href="javascript:;" class="box-link" aria-label="email-icon" onclick="welcomeEmailButton('{{$candidate->user->id }}')">
                                        <img src="{{ asset('backend') }}/lead-management/images/email.svg"
                                          alt="email" width="100%" height="100%">Welcome Email
                                    </a>

                               
                                    @endif

                                    @if (userCan('candidate.passwordUpdate'))

                                    <a href="javascript:;" class="box-link" aria-label="email-icon" onclick="passwordEmailButton('{{$candidate->user->id }}')">
                                        <img src="{{ asset('backend') }}/lead-management/images/email.svg"
                                          alt="email" width="100%" height="100%"> {{__('password')}} {{__('email')}}
                                    </a>
                                    @endif
                                   
                             
                                    {{-- @if (userCan('candidate.sendEmail')) --}}
                                    <a href="javascript:;" class="create-link box-link" aria-label="add-icon" onclick="customFollowupModel(event,'{{$candidate->user->id }}','{{$candidate->user->name }}')">
                                        <img src="{{ asset('backend') }}/lead-management/images/add.svg"
                                         alt="add" width="100%" height="100%">Follow Up
                                    </a>
                                    {{-- @endif --}}
                                   
                                    @if (userCan('candidate.delete'))
                                    <a href="javascript:;" class="company box-link" onclick="leadManagementDelete('{{ @$candidate->id }}')">
                                        <img src="{{ asset('backend') }}/lead-management/images/delete.svg" alt="delete" width="100%" height="100%">Delete
                                    </a>
                                    {{-- <form action="{{ route('candidate.destroy', $candidate->id) }}"
                                        method="POST" class="">
                                        @method('DELETE')
                                        @csrf
                                        
                                        <button
                                            onclick="return confirm('{{ __('are_you_sure_you_want_to_delete_this_item') }}');"
                                            class="create-link box-link">
                                            <img src="{{ asset('backend') }}/lead-management/images/delete.svg" alt="edit" width="100%" height="100%">Delete
                                            
                                        </button>
                                    </form> --}}
                                @endif
                            </p>
                        </div>
                    </td>
                </tr>

                @endforeach
                @else
                    <tr>
                        <td colspan="12" class="table-col">
                            {{ __('no_data_found') }}
                        </td>
                    </tr>
                @endif
            </tbody>
        </table>

        <!--Mobile-->
        {{-- <div class="m-list">
            <ul class="list">
                <li class="list-item"><img src="{{ asset('backend') }}/lead-management/images/edit.svg" alt="edit" width="100%" height="100%"></li>
                <li class="list-item">
                    <span class="li-head">Cat. :</span>
                    <span class="li-value">
                        <img src="{{ asset('backend') }}/lead-management/images/gold.svg" alt="gold" width="100%" height="100%">
                    </span>
                </li>
                <li class="list-item">
                    <span class="li-head">Type :</span>
                    <span class="li-value type-1">Hot</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Student ID :</span>
                    <a href="javascript:;" class="link li-value">20001 <span class="paid">P</span></a>
                </li>
                <li class="list-item">
                    <span class="li-head">Cr. Date :</span>
                    <p class="li-value"><span class="date">23 Sep, 23</span> <span class="time">02:29 PM</span></p>
                </li>
                <li class="list-item">
                    <span class="li-head">Student Name :</span>
                    <span class="li-value">Ashish lamba <span class="webinar">W</span></span>
                </li>
                <li class="list-item">
                    <span class="li-head">Mobile Number :</span>
                    <span class="li-value">+91 1234567895</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Preferred Country :</span>
                    <span class="li-value">USA</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Intake :</span>
                    <span class="li-value">Nov-2023</span>
                </li>
                <li class="list-item">
                    <span class="li-head">TAT :</span>
                    <span class="li-value">20</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Sub Stages :</span>
                    <span class="li-value">Inquiry</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Last Comment/Next Followup :</span>

                    <p class="li-value">
                        <span class="date">
                            <img src="images/calender.svg" alt="calender" width="100%" height="100%">28 Sep, 23
                        </span>
                        <span class="cmt">Call Busy</span>
                    </p>
                </li>
            </ul>

            <ul class="list">
                <li class="list-item"><img src="{{ asset('backend') }}/lead-management/images/edit.svg" alt="edit" width="100%" height="100%"></li>
                <li class="list-item">
                    <span class="li-head">Cat. :</span>
                    <span class="li-value">
                        <img src="{{ asset('backend') }}/lead-management/images/silver.svg" alt="silver" width="100%" height="100%">
                    </span>
                </li>
                <li class="list-item">
                    <span class="li-head">Type :</span>
                    <span class="li-value type-2">Cold</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Student ID :</span>
                    <a href="javascript:;" class="link li-value">20002</a>
                </li>
                <li class="list-item">
                    <span class="li-head">Cr. Date :</span>
                    <p class="li-value"><span class="date">23 Sep, 23</span> <span class="time">02:29 PM</span></p>
                </li>
                <li class="list-item">
                    <span class="li-head">Student Name :</span>
                    <span class="li-value">Ashok Kumar Meghwal</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Mobile Number :</span>
                    <span class="li-value">+91 2154368547</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Preferred Country :</span>
                    <span class="li-value">Australia</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Intake :</span>
                    <span class="li-value">Jan-2024</span>
                </li>
                <li class="list-item">
                    <span class="li-head">TAT :</span>
                    <span class="li-value">20</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Sub Stages :</span>
                    <span class="li-value">University to be Suggested</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Last Comment/Next Followup :</span>

                    <p class="li-value">
                        <span class="date">
                            <img src="images/calender.svg" alt="calender" width="100%" height="100%">28 Sep, 23
                        </span>
                        <span class="cmt">Student is from Haryana</span>
                    </p>
                </li>
            </ul>

            <ul class="list">
                <li class="list-item"><img src="{{ asset('backend') }}/lead-management/images/edit.svg" alt="edit" width="100%" height="100%"></li>
                <li class="list-item">
                    <span class="li-head">Cat. :</span>
                    <span class="li-value">
                        <img src="{{ asset('backend') }}/lead-management/images/bronze.svg" alt="bronze.svg" width="100%" height="100%">
                    </span>
                </li>
                <li class="list-item">
                    <span class="li-head">Type :</span>
                    <span class="li-value type-3">Warm</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Student ID :</span>
                    <a href="javascript:;" class="link li-value">20005</a>
                </li>
                <li class="list-item">
                    <span class="li-head">Cr. Date :</span>
                    <p class="li-value"><span class="date">23 Sep, 23</span> <span class="time">02:29 PM</span></p>
                </li>
                <li class="list-item">
                    <span class="li-head">Student Name :</span>
                    <span class="li-value">Nagaarjun Reddy Annapureddy</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Mobile Number :</span>
                    <span class="li-value">+91 7485961542</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Preferred Country :</span>
                    <span class="li-value">United kingdom</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Intake :</span>
                    <span class="li-value">Nov-2023</span>
                </li>
                <li class="list-item">
                    <span class="li-head">TAT :</span>
                    <span class="li-value">20</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Sub Stages :</span>
                    <span class="li-value">Counselling</span>
                </li>
                <li class="list-item">
                    <span class="li-head">Last Comment/Next Followup :</span>

                    <p class="li-value">
                        <span class="date">
                            <img src="images/calender.svg" alt="calender" width="100%" height="100%">28 Sep, 23
                        </span>
                        <span class="cmt">Wants to go UK or Canada</span>
                    </p>
                </li>
            </ul>
        </div> --}}
            {{-- @if ($candidates->count()) --}}
            <div class="mt-3 d-flex justify-content-center">
                {{ $candidates->onEachSide(1)->links() }}
            </div>
            {{-- @endif --}}

    </div>
</div>

<!--create Lead Popup-->
<div class="create-lead-popup">
    <div class="popup-head">
        <svg class="close-popup" backBtnFollows width="24" height="24" viewBox="0 0 24 24" fill="none"
                xmlns="http://www.w3.org/2000/svg">
                <path
                    d="M13.2329 11.9993L18.7414 6.4989C18.906 6.33424 18.9985 6.11091 18.9985 5.87804C18.9985 5.64517 18.906 5.42184 18.7414 5.25717C18.5767 5.09251 18.3534 5 18.1206 5C17.8877 5 17.6644 5.09251 17.4998 5.25717L12 10.7663L6.50024 5.25717C6.33559 5.09251 6.11228 5 5.87944 5C5.64659 5 5.42328 5.09251 5.25864 5.25717C5.09399 5.42184 5.00149 5.64517 5.00149 5.87804C5.00149 6.11091 5.09399 6.33424 5.25864 6.4989L10.7671 11.9993L5.25864 17.4996C5.17668 17.5809 5.11164 17.6776 5.06725 17.7842C5.02285 17.8907 5 18.005 5 18.1205C5 18.2359 5.02285 18.3502 5.06725 18.4568C5.11164 18.5633 5.17668 18.66 5.25864 18.7413C5.33992 18.8233 5.43663 18.8884 5.54318 18.9327C5.64972 18.9771 5.76401 19 5.87944 19C5.99486 19 6.10915 18.9771 6.2157 18.9327C6.32225 18.8884 6.41895 18.8233 6.50024 18.7413L12 13.2322L17.4998 18.7413C17.581 18.8233 17.6778 18.8884 17.7843 18.9327C17.8909 18.9771 18.0051 19 18.1206 19C18.236 19 18.3503 18.9771 18.4568 18.9327C18.5634 18.8884 18.6601 18.8233 18.7414 18.7413C18.8233 18.66 18.8884 18.5633 18.9328 18.4568C18.9771 18.3502 19 18.2359 19 18.1205C19 18.005 18.9771 17.8907 18.9328 17.7842C18.8884 17.6776 18.8233 17.5809 18.7414 17.4996L13.2329 11.9993Z"
                    fill="#24292D" />
            </svg>
            <p class="name">Create Lead</p>
    </div>

    <div class="popup-body">
        <form class="form" id="create_lead" submit="false" >
            
            <div class="single-input">
                <label for="Name" class="field-label">Name</label>
                <input type="text" class="input-field" id="name" name="name" placeholder="Enter Your Name" value="" maxlength="100">
            </div>

            <div class="single-input">
                <label for="Email"  class="field-label">Email</label>
                <input type="text" maxlength="200" class="input-field" name="email" id="email" placeholder="Email" value="">
            </div>

            <div class="single-input">
                <label for="Email" class="field-label">Source</label>
                <select class="input-field select2-with-search" name="source" id="source" >
                    <option value="">Select Source</option>
                    @foreach ($sourcesData as $sd)
                        <optgroup label="{{ $sd->name }}"> 
                            @foreach ($sd->source as $ssd)
                            <option
                            
                            value="{{ $ssd->name }}"> {{ $ssd->name }}</option>
                            @endforeach
                        </optgroup>
                    @endforeach 
                </select>
            </div>
            <div class="single-row">
                <div class="single-input select-list">
                    <select class="input-field select2-with-search" name="country" id="country" >
                       
                    </select>
                </div>

                <div class="single-input number">
                    <label for="Mobile number" class="field-label">Mobile Number</label>
                    <input type="text" class="input-field" name="phone" id="phone" placeholder="Mobile number" maxlength="15" value="" 
                    oninput="this.value = this.value.replace(/[^0-9]/g, '').replace(/(\..*)\./g, '$1');">
                </div>
            </div>


            
            
        </form>

        <div class="btns">
            {{-- <button class="common-btn" onclick="lead_create()">Submit</button> --}}
            <button class="common-btn" onclick="lead_create_edit()" >Save & Edit</button>
            <button class="common-btn" onclick="lead_create_close()" >Save & Close</button>
        </div>
    </div>
</div>
   
    <!--create-followup-popup-->
    <input type="hidden" value="close" id="manage_followup_popup"> 
    <div class="create-followup-popup">
        <div class="popup-head">
            <svg class="close-popup" backBtnFollows width="24" height="24" viewBox="0 0 24 24" fill="none"
                xmlns="http://www.w3.org/2000/svg">
                <path
                    d="M13.2329 11.9993L18.7414 6.4989C18.906 6.33424 18.9985 6.11091 18.9985 5.87804C18.9985 5.64517 18.906 5.42184 18.7414 5.25717C18.5767 5.09251 18.3534 5 18.1206 5C17.8877 5 17.6644 5.09251 17.4998 5.25717L12 10.7663L6.50024 5.25717C6.33559 5.09251 6.11228 5 5.87944 5C5.64659 5 5.42328 5.09251 5.25864 5.25717C5.09399 5.42184 5.00149 5.64517 5.00149 5.87804C5.00149 6.11091 5.09399 6.33424 5.25864 6.4989L10.7671 11.9993L5.25864 17.4996C5.17668 17.5809 5.11164 17.6776 5.06725 17.7842C5.02285 17.8907 5 18.005 5 18.1205C5 18.2359 5.02285 18.3502 5.06725 18.4568C5.11164 18.5633 5.17668 18.66 5.25864 18.7413C5.33992 18.8233 5.43663 18.8884 5.54318 18.9327C5.64972 18.9771 5.76401 19 5.87944 19C5.99486 19 6.10915 18.9771 6.2157 18.9327C6.32225 18.8884 6.41895 18.8233 6.50024 18.7413L12 13.2322L17.4998 18.7413C17.581 18.8233 17.6778 18.8884 17.7843 18.9327C17.8909 18.9771 18.0051 19 18.1206 19C18.236 19 18.3503 18.9771 18.4568 18.9327C18.5634 18.8884 18.6601 18.8233 18.7414 18.7413C18.8233 18.66 18.8884 18.5633 18.9328 18.4568C18.9771 18.3502 19 18.2359 19 18.1205C19 18.005 18.9771 17.8907 18.9328 17.7842C18.8884 17.6776 18.8233 17.5809 18.7414 17.4996L13.2329 11.9993Z"
                    fill="#24292D" />
            </svg>
            <p class="name">Complete Follow Up (<span class="follow-up-userName">--</span>)</p>
            <svg  class="back-btn"  onclick="backBtnFollows()" width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path
                    d="M10.2915 7C10.2915 7.3 10.1886 7.5 9.98274 7.7L4.83696 12.7C4.4253 13.1 3.80781 13.1 3.39615 12.7C2.98449 12.3 2.98449 11.7 3.39615 11.3L8.54192 6.3C8.95358 5.9 9.57108 5.9 9.98274 6.3C10.1886 6.5 10.2915 6.7 10.2915 7Z"
                    fill="#747579" />
                <path
                    d="M10.2915 17C10.2915 17.3 10.1886 17.5 9.98274 17.7C9.57108 18.1 8.95358 18.1 8.54192 17.7L3.39615 12.7C2.98449 12.3 2.98449 11.7 3.39615 11.3C3.80781 10.9 4.4253 10.9 4.83696 11.3L9.98274 16.3C10.1886 16.5 10.2915 16.7 10.2915 17Z"
                    fill="#747579" />
                <path
                    d="M21.6122 12C21.6122 12.6 21.2005 13 20.583 13H4.11656C3.49906 13 3.0874 12.6 3.0874 12C3.0874 11.4 3.49906 11 4.11656 11H20.583C21.2005 11 21.6122 11.4 21.6122 12Z"
                    fill="#747579" />
            </svg>
                
        </div>

        <div class="popup-body">
            <form class="form" id="FollowUpsForm">

                <input type="hidden" id="follow-up-id">
                <div id="customFollowUpShow">
                    <div class="single-row">
                        <div class="single-input">
                            <label for="follow-up-type" class="field-label">Follow Up Type</label>
                            <select class="select-list select2-with-search follow-up-type" name="follow-up-type"
                                id="follow-up-type">
                                <option value="">Follow Up Type</option>
                                <option value="Inbound Call">Inbound Call
                                </option>
                                <option value="Outbound Call">Outbound
                                    Call</option>
                                <option value="Chat">
                                    Chat</option>
                                <option value="Email">
                                    Email</option>
                            </select>
                            <span class="text-danger follow-up-type-msg"></span>
                        </div>
    
                        <div class="single-input">
                            <label for="follow_up_status" class="field-label">Follow Up Status</label>
                            <select class="select-list select2-with-search follow_up_status" name="follow_up_status"
                                id="follow_up_status">
                                <option value="">Follow Up Status</option>
                                <option value="Connected">{{ __('Connected') }}</option>
                                <option value="Not Connected">{{ __('Not Connected') }}</option>
                            </select>
                            <span class="text-danger follow_up_status_msg"></span>
                        </div>
                    </div>
    
                    <div class="msg-section">
                        <div class="single-input comment_connected">
                            <label for="comment" class="field-label">Comment</label>
                            <select class="select-list select2-with-search comment_connected" name="comment_connected"
                                id="comment_connected">
                                <option value="">Select Connected</option>
                                @foreach (config('constants.follow_up_connected') as $option)
                                    @if (!@empty($option))
                                        <option value="{{ $option }}">
                                            {{ $option }}
                                        </option>
                                    @endif
                                @endforeach
                            </select>
                            <span class="text-danger comment_connected_msg"></span>
                        </div>
                        <div class="single-input comment_not_connected">
                            <label for="comment" class="field-label">Comment</label>
                            <select class="select-list select2-with-search comment_not_connected" name="comment_not_connected"
                                id="comment_not_connected">
                                <option value="">Select Not Connected</option>
                                @foreach (config('constants.follow_up_not_connected') as $option)
                                    @if (!@empty($option))
                                        <option value="{{ $option }}">
                                            {{ $option }}
                                        </option>
                                    @endif
                                @endforeach
                            </select>
                            <span class="text-danger comment_not_connected_msg"></span>
                        </div>
                        <span class="hide_comment">
                            <textarea type="text" id="comment" class="input-field comment" rows="4" name="comment"
                                placeholder="Write Comment Description">{{ old('comment') }}</textarea>
                            <span class="text-danger comment_msg"></span>
                        </span>
    
                    </div>
                    {{-- <div class="single-input">
                        <label for="follow-up" class="field-label">Follow Up Subject</label>
                        <select class="select-list select2-with-search follow-up" name="follow-up" id="follow-up">
                            <option value="">Follow Up Subject</option>
                            <option value="Documents">Documents</option>
                            <option value="no">No</option>
                            <option value="close">Close</option>
                        </select>
                        <span class="text-danger follow-up-msg"></span>
                    </div> --}}
                    <div class="single-row">
                        <div class="single-btn">
                        <div class="btns"><button class="common-btn" onclick="customFollowupSave(event,'close')">Complete/Close
                            {{-- <i
                            class="proceed_spin loader4" id="loader4" style="display: none;"></i> --}}
                        </button></div>
                        </div>
                        <div class="single-btn">
                            <div class="btns"><button class="common-btn save" onclick="customFollowupSave(event,'closenext')">Next Follow Up
                                {{-- <i class="proceed_spin" id="loader4" style="display: none;"></i> --}}
                            </button></div>
                        </div>
    
                    </div>
                </div>
         
       
                <div id="followClose" class="cal-followup" style="display: none">
                    <div class="single-row followDatetimehide">
                        <div class="single-input date-select">
                            <label for="date" class="field-label">Date</label>
                            <input type="date" class="input-field follow-up-date"
                                id="follow-up-date" name="date" placeholder="Date">
                        </div>

                        <div class="single-input time-select">
                            <label for="time" class="field-label">Time</label>
                            <input type="text" onfocus="this.type='time'" class="input-field follow-up-time"
                                id="follow-up-time" name="time" placeholder="Time">
                        </div>
                        <span class="text-danger follow-up-date-time-msg"></span>
                    </div>
                
                
    

                    <div class="single-row">
                        <div class="single-input">
                            <label for="priority" class="field-label">Priority</label>
                            <select class="select-list select2-with-search priority" name="priority" id="priority">
                                <option value="">Priority</option>
                                <option value="High">High
                                </option>
                                <option value="Medium">Medium
                                </option>
                                <option value="Low">Low</option>
                            </select>
                            <span class="text-danger priority_msg"></span>
                        </div>
                        @if (userCan('admin.assign'))
                            <div class="single-input">
                                <label for="assignee_name" class="field-label">Assign To</label>
                                <select class="select-list select2-with-search assignee_name" name="assignee_name"
                                    id="assignee_name">
                                    <option value="">Assign To</option>
                                    @foreach (array_filter($admin_list, function ($item) {
                                            return $item['status'] == 1;
                                        }) as $option)
                                        @if (!@empty($option))
                                            <option value="{{ $option['id'] }}"
                                                {{ old('assign_to', Auth::user()->id) === $option['id'] ? 'selected' : '' }}>
                                                {{ $option['name'] }}
                                            </option>
                                        @endif
                                    @endforeach
                                </select>
                                <span class="text-danger assignee_name_msg"></span>
                            </div>
                        @endif
                    </div>
                    <div class="btns"><button class="common-btn" onclick="customFollowupSave(event ,'next')">Save<i
                        class="proceed_spin loader4" id="loader4" style="display: none;"></i></button></div>
                </div>

                <div id="followCloseShow" class="cal-followup" style="display: none">
                    <div class="single-row">
                        <div class="single-input date-select">
                            <label for="date" class="field-label">Stages</label>
                            <select class="select-list select2-with-search follow_up_stage" name="follow_up_stage" id="follow_up_stage">
                                <option value="">Stages</option>
                                <option value="Student backed out / Dropped">Student backed out / Dropped
                                </option>
                                <option value="Admitted">Admitted
                                </option>
                            </select>
                            <span class="text-danger follow_up_stage_msg"></span>
                        </div>

                        <div class="single-input time-select stageSelect_hide_show">
                            <label for="time" class="field-label">Reason</label>
                            <select class="select-list select2-with-search stageTypeSelect_show" name="follow_up_dropped_reason" id="stageSelect_hide_show">
                                <option value="" selected disabled="">Select Reason</option>
                                <option value="funds issue" >funds issue</option>
                                <option value="got offer from different consultancy / universit">got offer from different consultancy / universit</option>
                                <option value="other">{{ __('other') }}</option>                                           
                            </select>     
                            <span class="text-danger follow_up_dropped_reason_msg"></span>
                        </div>

                    </div>
                    {{-- <div class="single-row"> --}}
                        <div class="stageSelect_hide_show">
                            <div class="single-input  stageType_hide_show">
                                <label for="time" class="field-label">Reason</label>
                                {{-- <textarea type="text" id="follow_up_dropped_reason_comment" class="input-field follow_up_dropped_reason_comment" rows="4" name="follow_up_dropped_reason_comment"
                                placeholder="Write follow_up_dropped_reason_comment Description">{{ old('follow_up_dropped_reason_comment') }}</textarea> --}}
                                <input type="text" class="input-field" name="follow_up_dropped_reason_comment" id="follow_up_dropped_reason_comment"
                                value="{{ old('follow_up_dropped_reason_comment',@$user->dropped_reason)}}"
                                placeholder="Reason Comment" />  
                                <span class="text-danger follow_up_dropped_reason_comment_msg"></span>
                            </div>
                        </div>
                     

                        <span class="text-danger follow-up-date-time-msg"></span>
                    {{-- </div> --}}
                    <div class="btns"><button class="common-btn" onclick="customFollowupSave(event ,'closeSave')">Close/Save<i
                        class="proceed_spin loader4" id="loader5" style="display: none;"></i></button></div>
                        <p><span style="font-size: 0.75rem;line-height: 14px;color: #E33E3E;bottom: -17px;display: block;">*** To close the comment, you need to select one of the available stages or mark it for the next follow-up. ***</span></p>
                        
                </div>
            </form>
        </div>
    </div>
    


    <!--email-popup-->
    <div class="email-popup">
        <div class="popup-head">
            <svg class="close-popup" width="24" height="24" viewBox="0 0 24 24" fill="none"
                xmlns="http://www.w3.org/2000/svg">
                <path
                    d="M13.2329 11.9993L18.7414 6.4989C18.906 6.33424 18.9985 6.11091 18.9985 5.87804C18.9985 5.64517 18.906 5.42184 18.7414 5.25717C18.5767 5.09251 18.3534 5 18.1206 5C17.8877 5 17.6644 5.09251 17.4998 5.25717L12 10.7663L6.50024 5.25717C6.33559 5.09251 6.11228 5 5.87944 5C5.64659 5 5.42328 5.09251 5.25864 5.25717C5.09399 5.42184 5.00149 5.64517 5.00149 5.87804C5.00149 6.11091 5.09399 6.33424 5.25864 6.4989L10.7671 11.9993L5.25864 17.4996C5.17668 17.5809 5.11164 17.6776 5.06725 17.7842C5.02285 17.8907 5 18.005 5 18.1205C5 18.2359 5.02285 18.3502 5.06725 18.4568C5.11164 18.5633 5.17668 18.66 5.25864 18.7413C5.33992 18.8233 5.43663 18.8884 5.54318 18.9327C5.64972 18.9771 5.76401 19 5.87944 19C5.99486 19 6.10915 18.9771 6.2157 18.9327C6.32225 18.8884 6.41895 18.8233 6.50024 18.7413L12 13.2322L17.4998 18.7413C17.581 18.8233 17.6778 18.8884 17.7843 18.9327C17.8909 18.9771 18.0051 19 18.1206 19C18.236 19 18.3503 18.9771 18.4568 18.9327C18.5634 18.8884 18.6601 18.8233 18.7414 18.7413C18.8233 18.66 18.8884 18.5633 18.9328 18.4568C18.9771 18.3502 19 18.2359 19 18.1205C19 18.005 18.9771 17.8907 18.9328 17.7842C18.8884 17.6776 18.8233 17.5809 18.7414 17.4996L13.2329 11.9993Z"
                    fill="#24292D" />
            </svg>
            <p class="name">Email Message (<span class="templates_user_name">User</span>)</p>
            <svg  class="back-btn " id="closee_mail_popup" width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path
                    d="M10.2915 7C10.2915 7.3 10.1886 7.5 9.98274 7.7L4.83696 12.7C4.4253 13.1 3.80781 13.1 3.39615 12.7C2.98449 12.3 2.98449 11.7 3.39615 11.3L8.54192 6.3C8.95358 5.9 9.57108 5.9 9.98274 6.3C10.1886 6.5 10.2915 6.7 10.2915 7Z"
                    fill="#747579" />
                <path
                    d="M10.2915 17C10.2915 17.3 10.1886 17.5 9.98274 17.7C9.57108 18.1 8.95358 18.1 8.54192 17.7L3.39615 12.7C2.98449 12.3 2.98449 11.7 3.39615 11.3C3.80781 10.9 4.4253 10.9 4.83696 11.3L9.98274 16.3C10.1886 16.5 10.2915 16.7 10.2915 17Z"
                    fill="#747579" />
                <path
                    d="M21.6122 12C21.6122 12.6 21.2005 13 20.583 13H4.11656C3.49906 13 3.0874 12.6 3.0874 12C3.0874 11.4 3.49906 11 4.11656 11H20.583C21.2005 11 21.6122 11.4 21.6122 12Z"
                    fill="#747579" />
            </svg>
        </div>

        <div class="popup-body">
            <form action="" class="form" id="emailPopupform">
                <input type="hidden" id="templates_id">
                <div class="single-row">
                    <div class="single-input">
                        <label for="templates_type" class="field-label">Email Template</label>
                        <select class="select-list select2-with-search" name="templates_type" id="templates_type">
                            <option value="" data-class="emailTemplate">Email Template</option>
                            <option value="enquiryEmail" data-class="enquiryEmail">Study Abroad Enquiry</option>
                            <option value="offerLetter" data-class="offerLetter">Offer Letter</option>
                            <option value="callBackEmail"  data-class="callBackEmail">Call Back Email</option> 
                            <option value="universityCourseSuggestionsEmail"
                                data-class="universityCourseSuggestionsEmail">University/Course Suggestions</option>
                            <option value="customEmail" data-class="customEmail">Custom Email</option>
                        </select>
                    </div>
                    <div class="single-input optionalTemplate">
                        <label for="name" class="field-label">Name</label>
                        <input type="text" class="input-field" placeholder="Subject" value="">
                    </div>
                    <div
                        class="single-input optional-field enquiryEmail offerLetter universityCourseSuggestionsEmail customContactInformation customEmail">
                        <label for="name"
                            class="field-label optional-field enquiryEmail offerLetter universityCourseSuggestionsEmail customContactInformation customEmail"
                            name="Subject">Name</label>
                        <input type="text"
                            class="input-field optional-field enquiryEmail offerLetter universityCourseSuggestionsEmail customContactInformation customEmail templates_subject"
                            type="text" name="templates_subject" value="Custom Email" name="name"
                            placeholder="Subject" id="templates_subject">
                    </div>

                    <div
                        class="single-input file-select optional-field customEmail universityCourseSuggestionsEmail customContactInformation">
                        <small id="fileHelp" class="form-text text-muted">Allowed file extensions: Maximum file size:
                            20MB each.</small>
                        <p class="file-icon">
                            <input class="file"
                                class="optional-field customFile customEmail universityCourseSuggestionsEmail customContactInformation"
                                id="customFileD" type="file" name="customFile[]" placeholder="Attachment" multiple
                                onchange="checkFiles(this)" />
                            <img src="{{ asset('backend') }}/lead-management/images/pin-1.svg" alt="pin">
                        </p>
                    </div>
                </div>
                <div class="msg-section optionalTemplate">
                    <textarea class="input-field" name="" id="" placeholder="Template ...."></textarea>
                </div>

                <div class="msg-section optional-field enquiryEmail">
                    <textarea id="editor_enquiryEmail" rows="8" type="text" class="input-field editor1"
                        name="templates_message" placeholder="{{ __('enter') }} {{ __('notes') }}"> 
                    </textarea>
                </div>
                <div class="msg-section optional-field customEmail">
                    <textarea id="editor_customEmail" rows="8" type="text" class="input-field editor1"
                        name="templates_message" placeholder="{{ __('enter') }} {{ __('notes') }}">
                        
                    </textarea>
                </div>
                <div class="msg-section optional-field offerLetter">
                    <textarea id="editor_offerLetter" rows="8" type="text" class="input-field editor1"
                        name="templates_message" placeholder="{{ __('enter') }} {{ __('notes') }}">
                        
                    </textarea>
                </div>
                <div class="msg-section optional-field universityCourseSuggestionsEmail">
                    <textarea id="editor_universityCourseSuggestionsEmail" rows="8" type="text" class="input-field editor1"
                        name="templates_message" placeholder="{{ __('enter') }} {{ __('notes') }}">
                        
                    </textarea>
                </div>

                <div class="msg-section optional-field customContactInformation">
                    <textarea id="editor_customContactInformation" rows="8" type="text" class="input-field editor1"
                        name="templates_message" placeholder="{{ __('enter') }} {{ __('notes') }}">
                        
                    </textarea>
                </div>
                <div class="btns"><button class="common-btn" onclick="customEmail(event)">Send <i class="proceed_spin"
                            id="loader3" style="display: none;"></i></button> </div>
            </form>
        </div>


    </div>


<div class="timeline-popup">
    <img src="{{ asset('backend') }}/lead-management/images/cross.svg" class="close-timeline" alt="cross" width="100%" height="100%">
    <div class="t-body">
        <p class="head">Timeline</p>
        <img src="{{ asset('backend') }}/lead-management/images/timeline.png" alt="timeline" width="100%" height="100%">
    </div>
</div>

<div class="overlay"></div>
<div class="sidebar-overlay"></div>

<div class="loader"></div>


@endsection

@section('style')
<link rel="stylesheet" href="{{ asset('backend') }}/lead-management/css/lead.css?v={{env('CRM_VERSION')}}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css?v={{env('CRM_VERSION')}}" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css?v={{env('CRM_VERSION')}}" />
<style>

	/* Define the hover highlight color for the table row */
    .hoverTable tr:hover {
          background-color: #ece8fe;
    }
    .inactive-follow {
        border: 1px solid #da1c1c;
        color: #da1c1c;
        background: #FFFFFF;
        /* margin-right: 15px; */
    }

    body.zoom-80 {
        zoom: 70%;
    }

</style>

@endsection



@section('script')

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js?v={{env('CRM_VERSION')}}"
integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="{{ asset('backend') }}/lead-management/js/common.js?v={{env('CRM_VERSION')}}"></script>
<script src="{{ asset('backend') }}/lead-management/js/lead.js?v={{env('CRM_VERSION')}}"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js?v={{env('CRM_VERSION')}}"></script>

<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js?v={{env('CRM_VERSION')}}"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js?v={{env('CRM_VERSION')}}"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css?v={{env('CRM_VERSION')}}" />
<script src="{{ asset('tinymce/tinymce.min.js?v=' . env('CRM_VERSION')) }}" referrerpolicy="origin"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js?v={{env('CRM_VERSION')}}"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
@include('admin.lead-management.popup.whatsapp');
    <script>
        const formElement = document.getElementById('formSubmit');

        // $('#student_category, #assign_from ,#lead_type, #stageSelect, #subStageSelect,#preferred_country,#intake_month,#intake_years,#stageSelect,#assign_to,#assigned_rm,#payment_status,#source_value,#daterange, #daterangeCreated').on('change', function() {
        //     formElement.submit();
        // });
    </script>
    <script>
     $(document).ready(function() {
        $(".countloader").show();
        // Check screen size on document ready
            checkScreenSize();

        // Check screen size on window resize
        $(window).resize(function() {
            checkScreenSize();
        });

      

        // function setToCurrentTime(inputElement) {
        //     alert("tt");
        //     const currentTime = new Date();
        //     const hours = currentTime.getHours().toString().padStart(2, '0');
        //     const minutes = currentTime.getMinutes().toString().padStart(2, '0');
        //     const currentTimeString = `${hours}:${minutes}`;
        //     inputElement.type = 'time';
        //     inputElement.value = currentTimeString;
        // }

        setTimeout(function() {
            $(".loader").hide();
        }, 1000);
        leadManagementCounts();

        // $('.select2bsPreferredCountry').select2({
        //     theme: 'bootstrap4',
        //     multiple: true,
        //     placeholder: 'Select Preferred Country'
        //    });


        // $('.select2bsIntakeMonth').select2({
        //     theme: 'bootstrap4',
        //     multiple: true,
        //     placeholder: 'Select Intake Month',
        //     maximumSelectionLength: 3,
        // });

        // $('.select2bsIntakeYears').select2({
        //     theme: 'bootstrap4',
        //     multiple: true,
        //     placeholder: 'Select Intake Years',
        //     maximumSelectionLength: 2,
        // });

           

    var stages_name = "{{ request('stages') }}";
            // $.ajax({
            //     url: "{{ url('stageArray.php') }}?t=" + stages_name,
            //     success: function(res) {
            //         $("#subStageSelect").html(res);
            //     }
            // });
            
        $('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('');
            });


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

            $('input[name="daterangeCreated"]').on('cancel.daterangepicker', function(ev, picker) {
                $(this).val('');
            });

            
    });


    function checkScreenSize() {
        // Get the current screen width
        var screenWidth = $(window).width();
        // Set the zoom level based on screen width
        if (screenWidth < 1366) {
            $('body').addClass('zoom-80');
        } else {
            $('body').removeClass('zoom-80');
        }
    }


    function leadManagementCounts() {

        var assign_to =   $('#assign_to').val();
        $.ajax({
            url: "{{ route('admin.leadManagementCounts') }}",
            type: "get",
            data: {
                 assign_to: assign_to,
                _token: '{{ csrf_token() }}'
            },
            dataType: 'json',
            success: function (result) {
                 var total = "{{ @$totalCount }}"
                $('#inquiryButtonCount').text('(' + result.inquiryButtonCount + ')');
                $('#applicationButtonCount').text('(' + result.applicationButtonCount + ')');
                $('#offerButtonCount').text('(' + result.offerButtonCount + ')');
                $('#feePaymentButtonCount').text('(' + result.feePaymentButtonCount + ')');
                $('#deferedButtonCount').text('(' + result.deferedButtonCount + ')');
                $('#droppedButtonCount').text('(' + result.droppedButtonCount + ')');
                $('#visaButtonCount').text('(' + result.visaButtonCount + ')');
                $('#inquiryPendingCount').text(result.inquiryPendingCount);
                $('#applicationPendingCount').text(result.applicationPendingCount);
                $('#offerPendingCount').text(result.offerPendingCount);
                $('#visaPendingCount').text(result.visaPendingCount);
                $('#feePaymentPendingCount').text(result.feePaymentPendingCount);
                $('#deferedPendingCount').text(result.deferedPendingCount);
                $('#droppedPendingCount').text(result.droppedPendingCount);
                $('#activeTotal').text((total - result.droppedButtonCount));
                $('#myNonfollowedcount').text(result.myNonfollowedcount);
                $('#inactiveFollowCount').text(result.inactiveFollowCount);
                $('#workVisaPendingCount').text(result.workVisaPendingCount);
                $('#workVisaButtonCount').text('(' + result.workVisaButtonCount + ')');
                $('#testPreparationButtonCount').text('(' + result.testPreparationButtonCount + ')');
                $(".countloader").hide();
            },
            error: function (xhr, status, error) {
                $(".countloader").hide();
            }
        });
        
    }
        
    </script>
        {{-- ////////////////////////////form Submit by on change//////////////// --}}
        {{-- <script>
            const formElement = document.getElementById('formSubmit');
    
            $('#preferred_country, #lead_type, #student_category, #intake_years, #stageSelect').on('change', function() {
                formElement.submit();
            });
        </script> --}}


    {{-- ////////////////////////////custom Send Email///////////////////////// --}}

    <script>
        function customSendEmailModel(candidateId, candidateName, candidateEmail) {
            console.log("text" + candidateName);

            $('.email-popup').hide();
            // Clear and initialize form input fields
            $('#emailPopupform')[0].reset();
            $('#emailPopupform').find('select').val('').trigger('change');

            $("#templates_type").val('');
            $("#customFile").val('');

            $("#templates_id").val();
            $("#templates_user_name").val();
            $(".templates_user_email").val();

            $(".templates_user_name").val();
            $("#whatsApp_massage").val();
            $(".Wtemplates_message").val();

            $(".optional-field").hide();

            $("#templates_id").val(candidateId);
            $("#templates_user_name").val(candidateName);
            $(".templates_user_email").val(candidateEmail);
            $(".templates_user_name").text(candidateName);

            $(".email-popup").show();



        }

        $("#templates_type").change(function() {
            $(".optional-field").hide();
            $('#customFileD').val('');
            var className = $('option:selected', this).data('class').trim();

            templatesHideShowFunction(className);
            var candidateName = $(".templates_user_name").text().trim();
            console.log("classNamedd " + className + " candidateName " + candidateName);
            updateEditorContent(className, candidateName);
        });

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


        function templatesHideShowFunction(className) {
            $(".optionalTemplate").show();
            console.log("className " + className);
            if (className == 'enquiryEmail') {
                $('#templates_subject').val('Study Abroad Enquiry');
                $(".optionalTemplate").hide();
            } else if (className == 'customEmail') {
                $('#templates_subject').val('Custom Email');
                $(".optionalTemplate").hide();
            } else if (className == 'offerLetter') {
                $('#templates_subject').val('Congratulations on Acceptance of Your University Application! 🎉');
                $(".optionalTemplate").hide();
            } else if (className == 'universityCourseSuggestionsEmail') {
                $('#templates_subject').val('University/Course Suggestions');
                $(".optionalTemplate").hide();
            } else if (className == 'customContactInformation') {
                $('#templates_subject').val(
                    'Update us with your Contact Information for a Smooth Transition to Studying Abroad');
                $(".optionalTemplate").hide();
            } else if (className == 'emailTemplate') {
                $(".optionalTemplate").show();
            } else if (className == 'callBackEmail') {
                $('#templates_subject').val(
                    'Call Back Email');
                $(".optionalTemplate").hide();
            }





            if (className) {
                $("." + className).show();
            }

        }


        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);
            } else if (templateType === 'universityCourseSuggestionsEmail') {

                var universityCourseSuggestionsEmailContent = `<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. Please find attached for the shortlisted university & course suggestions as per your profile.
                                Kindly revert us back as soon as possible with your selected choices to proceed with application
                                Response awaited.</span></span></p>
                            </div>
                            <div>
                                <div style="color: rgb(34,34,34);">
                                
                                <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_universityCourseSuggestionsEmail").setContent(universityCourseSuggestionsEmailContent);
            } else if (templateType === 'customContactInformation') {

                var customContactInformationContent = `<p><strong>Dear <span>${candidateName}</span>,</strong></p>
                            <div dir="ltr">
                            <div>
                                <p>Greetings from Gradding!</p>
                        <p>We hope this message finds you in great spirits. We appreciate your interest in pursuing higher education abroad with Gradding. However, it seems that the contact number we have on file may not be accurate or not available on WhatsApp. To ensure that we can provide you with the best guidance and support, we kindly request you to provide us with an updated contact (or WhatsApp) number where we can reach out to you. This will enable us to schedule a call and discuss your study abroad plans in detail.</p>
                        <p>Please take a moment to reply to this email with your preferred contact number, or feel free to give us a call at +91-9773388670. We look forward to connecting with you and assisting you on this exciting educational journey.</p>
                            </div>
                            <div>
                                <div style="color: rgb(34,34,34);">
                                
                                <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_customContactInformation").setContent(customContactInformationContent);
            }


        }

        $(document).one("mousemove",function(){
            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
                    }
                }
            });


            tinymce.init({
                selector: `#editor_universityCourseSuggestionsEmail`,
                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_customContactInformation`,
                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 customEmail(event) {
            event.preventDefault();
            var id = $('#templates_id').val();
            var type = $('#templates_type').val();
            var subject = $('#templates_subject').val();
            var customFile = $('#customFileD').val();
            console.log(type);
            var message = null;

            var formData = new FormData();

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


            if (type === 'enquiryEmail') {
                message = tinymce.get("editor_enquiryEmail").getContent();
            } else if (type === 'customEmail') {
                message = tinymce.get("editor_customEmail").getContent();

                var isFileValid = checkFiles(customFileInput);

                if (isFileValid != true && customFile) {
                    toastr.error("Invalid file. Please check the file size and type.");
                    return;
                }
            } else if (type === 'offerLetter') {
                message = tinymce.get("editor_offerLetter").getContent();
            } else if (type === 'universityCourseSuggestionsEmail') {
                message = tinymce.get("editor_universityCourseSuggestionsEmail").getContent();
                var isFileValid = checkFiles(customFileInput);

                if (isFileValid != true && customFile) {
                    toastr.error("Invalid file. Please check the file size and type.");
                    return;
                }
            } else if (type === 'customContactInformation') {
                message = tinymce.get("editor_customContactInformation").getContent();
                var isFileValid = checkFiles(customFileInput);

                if (isFileValid != true && customFile) {
                    toastr.error("Invalid file. Please check the file size and type.");
                    return;
                }
            }



            if (!id) {
                toastr.error("ID is required.");
                return;
            }

            if (!type) {
                toastr.error("Templates Type is required.");
                return;
            }
            console.log(message);
            if(type != 'callBackEmail'){
                if (!subject || !message) {
                toastr.error("Templates Subject and Message are required.");
                return;
            }
            }
            const button = event.target;
            // button.style.display = 'none';
            button.disabled = true;
            button.style.backgroundColor = 'gray';
            const loader = document.getElementById('loader3');
            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';
                    button.disabled = false;
                    button.style.backgroundColor = '#066AC9';
                    var customFile = $('#customFileD').val('');
                    toastr.success("Email send successfully!");
                    $("body").removeClass("no-scroll");
                    $('#exampleModal_customEmail').find('[data-dismiss="modal"]').trigger('click');
                    $('.close-popup').trigger('click');
                    $("body").removeClass("no-scroll");
                },
                error: function(xhr, status, error) {
                    loader.style.display = 'none';
                    // button.style.display = 'inline-block';
                    button.disabled = false;
                    button.style.backgroundColor = '#066AC9';
                    // Handle the error response, e.g., show an error message
                    console.error(xhr.responseText);
                    toastr.error("Error sending email. Please try again later.");
                    $('.close-popup').trigger('click');
                    $("body").removeClass("no-scroll");
                }
            });

        };

        function checkFiles(input) {
            const maxFileSizeMB = 22;
            const allowedExtensions = ['pdf', 'doc', 'xlsx' ,'csv', 'docx', 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg'];

            const files = input.files;

            for (let i = 0; i < files.length; i++) {
                const file = files[i];

                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
                    return false;
                }
                // else if (!allowedExtensions.includes(fileExtension)) {
                //     alert('Invalid file extension. Please select valid files with extensions: ' + allowedExtensions.join(', '));
                //     input.value = ''; // Clear the file input
                //     return false;
                // }
            }
            return true;
        }
    </script>
    {{-- /////////////////////////follow-up////////////////////////// --}}
    <script>
        $(document).ready(function() {

            var dtToday = new Date();
            var month = dtToday.getMonth() + 1; // getMonth() is zero-based
            var day = dtToday.getDate();
            var year = dtToday.getFullYear();
            if (month < 10)
                month = '0' + month.toString();
            if (day < 10)
                day = '0' + day.toString();

            var maxDate = year + '-' + month + '-' + day;
            $('#follow-up-date').attr('min', maxDate);

            // Select the date and time input fields and the error message element
            var dateInput = $('#follow-up-date');
            var timeInput = $('#follow-up-time');
            var errorMsg = $('.follow-up-date-time-msg');

            // Function to validate date and time
            function validateDateTime() {
                var selectedDate = dateInput.val();
                var selectedTime = timeInput.val();

                if (!selectedDate || !selectedTime) {
                    errorMsg.text("Please select both a date and a time");
                    return false;
                }

                // Clear any error message if both date and time are selected
                errorMsg.text("");
                return true;
            }

            // Add change event listeners to date and time inputs
            dateInput.on('change', validateDateTime);
            timeInput.on('change', validateDateTime);
        });


        $('#follow-up').on('change', function() {
            var selectedOption = $(this).val();
            $('#form32').val(' ');
            if (selectedOption === 'no' || selectedOption === 'close') {
                $('#follow-up-date').val('');
                $('#follow-up-time').val('');
                $('.followDatetimehide').hide();
            } else {
                $('.followDatetimehide').show();
            }
        });


        function customFollowupModel(event, candidateId, userName) {
            event.preventDefault();
            $("#followClose").hide();
            $('.create-followup-popup').hide();
            $('#manage_followup_popup').attr('value', 'close');
            $("#customFollowUpShow").show();
            $("#followClose,#followCloseShow").hide();
            // Clear and initialize form input fields
            $('#FollowUpsForm')[0].reset();
            $('#FollowUpsForm').find('select').val('').trigger('change');

            // Show your popup or perform other actions here
            $("#follow-up-id").val(candidateId);
            $(".follow-up-userName").text(ucwords(userName));
            console.log("follow-up-id"+candidateId);
            $('.create-followup-popup').show();
        }

        function ucwords(str) {
            return str.replace(/\b\w/g, function (match) {
                return match.toUpperCase();
            });
        }



        $('#follow_up_status').on('change', function(event) {
            var follow_up_s = $(this).val();
            if (follow_up_s == 'Connected') {
                $('.comment_not_connected').hide();
                $('.comment_connected').show();
            } else if (follow_up_s == 'Not Connected') {
                $('.comment_not_connected').show();
                $('.comment_connected').hide();
            }
            $('.comment_not_connected').hide();
                $('.comment_connected').hide();

        });


        $('.comment_not_connected').hide();
        // $('.comment_connected').hide();
        $('.hide_comment').hide();


        $('#follow_up_status').on('change', function(event) {
            var follow_up_s = $(this).val();
            if (follow_up_s == 'Connected') {
                $('.comment_not_connected').hide();
                $('.comment_connected').show();
            } else if (follow_up_s == 'Not Connected') {
                $('.comment_not_connected').show();
                $('.comment_connected').hide();
            }

        });

        $('#comment_connected, #comment_not_connected').on('change', function(event) {
            $('.hide_comment').hide();
            var comment_connecteds = $(this).val();
            if (comment_connecteds === 'Other') {
                $('#comment').val("");
                $('.hide_comment').show();
                
            }else if(comment_connecteds != ''){
                $('#comment').val(comment_connecteds);
                $('.hide_comment').show();
            }
        });

        function customFollowupSave(event, closenext) {
            $('.text-danger').text('');
            
            event.preventDefault();

            var user_id = $("#follow-up-id").val();
            var comment = $('#comment').val();
            var type = $('#follow-up-type').val();
            var followupdate = $('#follow-up-date').val();
            var followuptime = $('#follow-up-time').val();

            var followupstage = $('#follow_up_stage').val();
            var followupdroppedreason = $('#stageSelect_hide_show').val();
            var followupdroppedreasoncomment = $('#follow_up_dropped_reason_comment').val();



            var datetimeMarage = followupdate + " " + followuptime;
            var formattedDateTime = null;
            var comment_not_connected = $('#comment_not_connected').val();
            var comment_connected = $('#comment_connected').val();
            var assign_to = $('#assignee_name').val();
            // Parse the datetime string into a JavaScript Date object
            if (datetimeMarage) {
                var parsedDate = new Date(datetimeMarage);

                // Format the date and time in the desired format
                var formattedDateTime = parsedDate.getFullYear() + "-" +
                    String(parsedDate.getMonth() + 1).padStart(2, '0') + "-" +
                    String(parsedDate.getDate()).padStart(2, '0') + " " +
                    String(parsedDate.getHours() % 12 || 12).padStart(2, '0') + ":" +
                    String(parsedDate.getMinutes()).padStart(2, '0') + ":" +
                    String(parsedDate.getSeconds()).padStart(2, '0') + " " +
                    (parsedDate.getHours() >= 12 ? "PM" : "AM");

            }


            var datetime = formattedDateTime;
            var follow_up_status = $('#follow_up_status').val();
            var priority = $('#priority').val();
            var followup = "close";


            if (!user_id) {
                toastr.error("ID is required.");
                return;
            }

            // Reset any previous error messages
            $('.text-danger').text('');

            var isValid = true;
            var customFollowupSave = false;
            // if (comment.trim() === '') {
            //     $('#comment').next('.text-danger').text('Please enter a comment.');
            //     isValid = false;
            // }

            if (type === '') {
                $('.follow-up-type-msg').text('Please select a type.');
                console.log(1);
                isValid = false;
                return;
            }


            if (follow_up_status === '') {
                $('.follow_up_status_msg').text('Please select a status.');
                console.log(2);
                isValid = false;
                return;

            } else {

                if (follow_up_status == "Connected") {
                    console.log("Connected");
                    if ($('#comment_connected').val() == '') {
                        $('.comment_connected_msg').text('Please select a comment.');
                        isValid = false;
                        return;
                    }

                } else if (follow_up_status == "Not Connected") {
                    console.log("comment_not_connected");
                    if ($('#comment_not_connected').val() == '') {
                        $('.comment_not_connected_msg').text('Please select a comment.');
                        isValid = false;
                        return;

                    }
                }
            }

            // if (priority === '') {
            //     $('#priority').next('.text-danger').text('Please select a priority.');
            // console.log(3);
            //     isValid = false;
            // }

            if (followup == '') {
                $('.follow_up_status_msg').text('Please select a status.');
                console.log(4);
                isValid = false;
                return;

            }

            // if (followup === undefined) {
            //     $('.follow-up-msg').text('Please select an option.');
            // console.log(5);
            //     isValid = false;
            // } else if (followup === 'yes' && $('#form32').val().trim() === '') {
            //     $('#datetime').find('.text-danger').text('Please enter a date and time.');
            // console.log(6);
            //     isValid = false;
            // }

            if (followup == '') {
                $('.follow-up-msg').text('Please select an option.');
                console.log(7);
                isValid = false;
                return;
            }


            if(closenext == 'close'){
                followup = "close";
                 $("#followClose").hide();
                 $("#followCloseShow").show();
                 $('#manage_followup_popup').attr('value', 'yes');
                 $("#customFollowUpShow").hide();
                if (!followupstage) {
                    $('.follow_up_stage_msg').text('Please select an option.');
                    isValid = false;
                    return;
                }
                if (followupstage && followupstage == "Student backed out / Dropped") {
                    if(!followupdroppedreason){
                        $('.follow_up_dropped_reason_msg').text('Please select an option.');
                        isValid = false;
                        return;
                    }
                    if (!followupdroppedreasoncomment) {
                        $('.follow_up_dropped_reason_comment_msg').text('Please enter a dropped reason.');
                        isValid = false;
                        return;
                    }
                   
                }
               
                return;
            }else if(closenext == 'closenext'){
                setDefaultTime();
                $('#manage_followup_popup').attr('value', 'yes');
                $("#customFollowUpShow").hide();
                $("#followClose").show();
                $("#followCloseShow").hide();
                return;
            }else if(closenext == 'closeSave'){
                if (!followupstage) {
                    $('.follow_up_stage_msg').text('Please select an option.');
                    isValid = false;
                    return;
                }
                if (followupstage && followupstage == "Student backed out / Dropped") {
                    if(!followupdroppedreason){
                        $('.follow_up_dropped_reason_msg').text('Please select an option.');
                        isValid = false;
                        return;
                    }
                    if (!followupdroppedreasoncomment) {
                        $('.follow_up_dropped_reason_comment_msg').text('Please enter a dropped reason.');
                        isValid = false;
                        return;
                    }
                    followup = "close";
                }
            }else{
                $("#followClose").show();
                $("#followCloseShow").hide();
                var followup = "yes";

            }
          






            if (followup != 'close' && followup != 'no' && datetime !== '') {
                var checkfollowupsDatetime = true;
                if (followupdate == '' || followuptime == '') {
                    $('.follow-up-date-time-msg').text('Please enter a date and time.');
                    console.log(8);
                    isValid = false;
                    checkfollowupsDatetime = false;
                }
                if (checkfollowupsDatetime) {
                   
                    $.ajax({
                        url: "{{ route('candidate.checkfollowupsDatetime') }}",
                        type: "get",
                        data: {
                            admin_id: assign_to,
                            datetime: datetime,
                            _token: '{{ csrf_token() }}'
                        },
                        dataType: 'json',
                        success: function(result) {

                            if (result.status == "1") {
                                console.log(9 + isValid);
                                console.log("isValidy" + isValid);
                                isValid = false;
                                console.log(9 + isValid);
                                console.log("isValidn" + isValid);
                                $('.follow-up-date-time-msg').text('This slot already book.');
                                // $('#datetime').find('.text-danger').text('This slot already book.');

                            } else if (isValid) {
                                saveFollowup(user_id,type,follow_up_status,priority,assign_to,comment_connected,comment_not_connected,comment,followup,datetime,event,followupstage,followupdroppedreason,followupdroppedreasoncomment);
                            }



                        }
                    });
                }



            } else {

                if (isValid) {
                    customFollowupSave = true;
                      saveFollowup(user_id,type,follow_up_status,priority,assign_to,comment_connected,comment_not_connected,comment,followup,datetime,event,followupstage,followupdroppedreason,followupdroppedreasoncomment);
                }
            }

            // if (isValid) {
            //     customFollowupSave = true;
            // }
            
            console.log("customFollowupSave " + customFollowupSave);
            // if (customFollowupSave) {
            //     const loader = document.getElementById('loader4');
            //     loader.style.display = 'inline-block';
            //     $.ajax({
            //         url: "{{ route('followup.storeFollowup', ['id' => ':id']) }}".replace(':id', user_id),
            //         type: "post",
            //         data: {
            //             type: type,
            //             follow_up_status: follow_up_status,
            //             priority: priority,
            //             assign_to: assign_to,
            //             comment_connected: comment_connected,
            //             comment_not_connected: comment_not_connected,
            //             comment: comment,
            //             followup_up: followup,
            //             datetime: datetime,
            //             _token: '{{ csrf_token() }}'
            //         },
            //         dataType: 'json',
            //         success: function(result) {
            //             loader.style.display = 'none';
            //             toastr.success("FollowUp Created successfully!");
            //             $('.create-followup-popup').hide();
            //             $(".overlay").hide();
            //         }
            //     });
            // }


        }

        // function saveFollowup(user_id,type,follow_up_status,priority,assign_to,comment_connected,comment_not_connected,comment,followup,datetime,event,stage,reason,reasonComment) {
        //     // const loader = document.getElementsByClassName('loader4');
        //     // const button = event.target;
        //     // button.style.display = 'none';
        //     // loader.style.display = 'inline-block';
        //     // var sumbittype = true;
        //     // if(followup == "close" && stage){
        //     //  sumbittype = false;
        //     //     if (confirm("Are you sure you want to change this stage: "+stage+"?")) {
        //     //         sumbittype = true;
        //     //     }
        //     // }
            
        //     // if(sumbittype){

        //         var sumbittype = true;
        //     if (followup == "close" && stage) {
        //         sumbittype = false;
        //         Swal.fire({
        //             title: "Are you sure?",
        //             text: "Are you sure you want to change this stage: " + stage + "?",
        //             icon: "warning",
        //             showCancelButton: true,
        //             confirmButtonText: "Yes",
        //             cancelButtonText: "No",
        //         }).then((result) => {
        //             if (result.isConfirmed) {
        //                 sumbittype = true;
        //                 // Perform any further actions if confirmed
        //             }
        //         });
        //     }
        //     if(sumbittype){

        //     const button = event.target;
        //     button.disabled = true;
        //     button.style.backgroundColor = 'gray';
        //     if(followup == "close"){
        //         var loader = document.getElementById('loader5');
        //     }else{
        //         var loader = document.getElementById('loader4');
        //     }
        //     loader.style.display = 'inline-block';

        //         $.ajax({
        //         url: "{{ route('followup.storeFollowup', ['id' => ':id']) }}".replace(':id', user_id),
        //         type: "post",
        //         data: {
        //             type: type,
        //             follow_up_status: follow_up_status,
        //             priority: priority,
        //             assign_to: assign_to,
        //             comment_connected: comment_connected,
        //             comment_not_connected: comment_not_connected,
        //             comment: comment,
        //             stage: stage,
        //             reasonComment: reasonComment,
        //             followup_up: followup,
        //             datetime: datetime,
        //             _token: '{{ csrf_token() }}'
        //         },
        //         dataType: 'json',
        //         success: function(result) {
        //             // loader.style.display = 'none';
        //             // button.style.display = 'inline-block';
        //             button.disabled = false;
        //             button.style.backgroundColor = '#055aab';
        //             loader.style.display = 'none';
                    
        //             toastr.success("FollowUp Created successfully!");
        //             $("body").removeClass("no-scroll");
        //             $('.create-followup-popup').hide();
        //             $(".overlay").hide();
        //         },
        //         error: function(xhr, status, error) {
        //             // loader.style.display = 'none';
        //             // button.style.display = 'inline-block';
        //             // Handle the error response, e.g., show an error message
        //             loader.style.display = 'none';
        //             // button.style.display = 'inline-block';
        //             button.disabled = false;
        //             button.style.backgroundColor = '#055aab';
        //             console.error(xhr.responseText);
        //             toastr.error("Something Wrong", 'Error!');
        //         }
        //     });
        //     }
         
        // }


        function saveFollowup(user_id, type, follow_up_status, priority, assign_to, comment_connected, comment_not_connected, comment, followup, datetime, event, stage, reason, reasonComment) {
            var sumbittype = true;

            if (followup == "close" && stage) {
                sumbittype = false;

                Swal.fire({
                    title: "Are you sure?",
                    text: "Are you sure you want to change this stage: " + stage + "?",
                    icon: "warning",
                    showCancelButton: true,
                    confirmButtonText: "Yes",
                    cancelButtonText: "No",
                }).then((result) => {
                    if (result.isConfirmed) {
                        sumbittype = true;
                        // Perform any further actions if confirmed
                        performFollowup(user_id, type, follow_up_status, priority, assign_to, comment_connected, comment_not_connected, comment, stage, reasonComment, followup, datetime, event);
                    }
                });
            } else {
                performFollowup(user_id, type, follow_up_status, priority, assign_to, comment_connected, comment_not_connected, comment, stage, reasonComment, followup, datetime, event);
            }
        }

        function performFollowup(user_id, type, follow_up_status, priority, assign_to, comment_connected, comment_not_connected, comment, stage, reasonComment, followup, datetime, event) {
            const button = event.target;
            button.disabled = true;
            button.style.backgroundColor = 'gray';
            var loader = followup === "close" ? document.getElementById('loader5') : document.getElementById('loader4');
            loader.style.display = 'inline-block';

            $.ajax({
                url: "{{ route('followup.storeFollowup', ['id' => ':id']) }}".replace(':id', user_id),
                type: "post",
                data: {
                    type: type,
                    follow_up_status: follow_up_status,
                    priority: priority,
                    assign_to: assign_to,
                    comment_connected: comment_connected,
                    comment_not_connected: comment_not_connected,
                    comment: comment,
                    stage: stage,
                    reasonComment: reasonComment,
                    followup_up: followup,
                    datetime: datetime,
                    _token: '{{ csrf_token() }}'
                },
                dataType: 'json',
                success: function(result) {
                    button.disabled = false;
                    button.style.backgroundColor = '#055aab';
                    loader.style.display = 'none';
                    refreshTable();
                    toastr.success("FollowUp Created successfully!");
                    $("body").removeClass("no-scroll");
                    $('.create-followup-popup').hide();
                    $(".overlay").hide();
                },
                error: function(xhr, status, error) {
                    loader.style.display = 'none';
                    button.disabled = false;
                    button.style.backgroundColor = '#055aab';
                    console.error(xhr.responseText);
                    toastr.error("Something Went Wrong", 'Error!');
                }
            });
        }

    </script>

    <script>
     

            function backBtnFollows(){
                var value = $('#manage_followup_popup').val();
                
                console.log("manage_followup_popup "+value);
                if(value == "close"){
                    $('.create-followup-popup').hide();
                   $('.overlay').hide();
                   $("body").removeClass("no-scroll");
                   $('#manage_followup_popup').attr('value', 'close');
                }else if(value == "yes"){
                    $("#customFollowUpShow").show();
                    $('#followCloseShow, #followClose').hide();
                    $('#manage_followup_popup').attr('value', 'close');
                }else{
                    $('.close-popup').trigger('click');
                    $("body").removeClass("no-scroll");
                    $('#manage_followup_popup').attr('value', 'close');
                }
               
            }

            $('#closee_mail_popup').click(function() {
                $('.close-popup').trigger('click');
                
            });


            $('.follow_up_stage').on('change', function() {
            var selectedOption = $(this).val();
            
            if(selectedOption == "Student backed out / Dropped"){
              stageSelect_hide_show("Student backed out / Dropped");
            
            }else if(selectedOption == "Offer Rejected"){
              stageSelect_hide_show("Offer Rejected");
            }else if(selectedOption == "Offer Accepted"){
              stageSelect_hide_show("Offer Accepted");
            }else{
                stageSelect_hide_show("no");
            }
            });

            function stageSelect_hide_show(selectedOption) {
                $(".stageSelect_hide_show, .stageType_hide_show").hide();
        
                if (selectedOption === 'Student backed out / Dropped') {      
                    $(".stageSelect_hide_show").show();
                   
                }
               
            }


            $('.stageTypeSelect_show').on('change', function() {
                var selectedOptiontype = $(this).val();
                $("#follow_up_dropped_reason_comment").val("");
                if (selectedOptiontype === 'other') {     
                    stageSelectype_hide_show("yes");
                }else{
                    $("#follow_up_dropped_reason_comment").val(selectedOptiontype);
                    stageSelectype_hide_show("no");
                }
            
            });

            function stageSelectype_hide_show(selectedOpftion) {
                console.log("selectedOpftion"+ selectedOpftion);
            if (selectedOpftion === 'yes') {      
                    $(".stageType_hide_show").show();
                } else {
                    $(".stageType_hide_show").hide();
                }
            }
            

        ////////////////////////defolet corent time ///////////////
        function setDefaultTime() {
            const timeInput = document.getElementById('follow-up-time');
            if (timeInput) {
                timeInput.value = getCurrentTimePlusOneMinute();
            }
        }

        function getCurrentTimePlusOneMinute() {
            const now = new Date();
            now.setMinutes(now.getMinutes() + 1); // Increment current time by one minute
            const hours = String(now.getHours()).padStart(2, '0');
            const minutes = String(now.getMinutes()).padStart(2, '0');
            return `${hours}:${minutes}`;
        }

        </script>

        <script>

        function refreshTable() {
            var assign_to = $('#assign_to').val();
            var url = "{{ route('admin.leadManagement', ['assign_to' => ':assign_to']) }}";
            url = url.replace(':assign_to', assign_to);
            $.ajax({
                url: window.location.href,
                type: 'GET',
                dataType: 'html',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(response) {
                    // Assuming your table has an id of 'leadManagementTable'
                    var tbodyContent = $(response).find('#leadManagementTable tbody').html();
                    $('#leadManagementTable tbody').html(tbodyContent);
                  
                },
                error: function(error) {
                    console.log('Error loading lead management data: ', error);
                }
            });
        }
        </script>


        <script>
            
            function handleLeadTypeEditClick(name,dropdownToggle, followupId) {
                var leadTypeSpan = $('#'+name + followupId);
                var editDropdown = $('#'+dropdownToggle + followupId);
                // // Toggle visibility of lead type and editable dropdown
                // leadTypeSpan.toggle();
                // editDropdown.toggle();
                $('.'+dropdownToggle+', .'+name).hide();
                $('.'+name).show();
                $('#'+name + followupId).hide();
                $('#'+dropdownToggle + followupId).show();
            }


            function handleLeadTypeSaveClick(button, name) {
                var userId = $(button).data('id');
                var followupID = $(button).data('followupid');
              
                if(name == 'leadEdit'){
                    var selectedLeadType = $(button).closest('td').find('select[name="lead_type"]').val();
                    handleLeadTypeUpdate(userId, selectedLeadType, followupID);
                }else if(name == 'assignTo'){
                    var selectedLeadType = $(button).closest('td').find('select[name="assign_to_change"]').val();
                    assignToChange(userId, selectedLeadType, 'Counselor');
                }else if(name == 'assignToRm'){
                    var selectedLeadType = $(button).closest('td').find('select[name="assign_to_rm_change"]').val();
                    assignToChange(userId, selectedLeadType, 'RM');
                }
                
            }

            // Function to handle AJAX request
            function handleLeadTypeUpdate(userId, selectedLeadType, followupID) {
                $(".loader").show();

                // Perform AJAX request to update lead type
                $.ajax({
                    method: 'POST',
                    url: "{{ route('admin.leadTypeUpdate', ['id' => ':id']) }}".replace(':id', userId),
                    data: {
                        _token: '{{ csrf_token() }}',
                        lead_type: selectedLeadType,
                    },
                    success: function (response) {
                        $(".loader").hide();
                        toastr.success("Lead type updated successfully!");
                        // updateLeadTypeUI(selectedLeadType, userId, followupID);
                                                // refreshTable();
                        refreshTable();
                        // You can call your custom function to refresh the table if needed
                    },
                    error: function (error) {
                        $(".loader").hide();
                        toastr.error("Something Went Wrong", 'Error!');
                        console.error('Error updating lead type:', error);
                    },
                });
            }
        </script>

        <script>
        function callBackEmailButton(id) {    
            if (confirm("Are you sure you want to Send Call Back Email ?")) {      
                $.ajax({
                    type: "POST",
                    data: {
                        type: "ajax",
                        _token: '{{ csrf_token() }}'
                    },
                    url: "{{ route('candidate.callBackEmail', ['id' => ':id']) }}".replace(':id', id),
                    success: function(response) {
                        if (response.success) {
                            toastr.success("Email send successfully!");

                        } else {
                            toastr.error("Failed Call Back Email.");
                        }
                    },
                    error: function(error) {
                        console.error(error);
                        toastr.error("An error occurred while processing your request.");
                    }
                });
            }
        }

        function welcomeEmailButton(id) {    
            if (confirm("Are you sure you want to Send Welcome Email ?")) {      
                $.ajax({
                    type: "POST",
                    data: {
                        type: "ajax",
                        _token: '{{ csrf_token() }}'
                    },
                    url: "{{ route('candidate.welcomeEmail', ['id' => ':id']) }}".replace(':id', id),
                    success: function(response) {
                        if (response.success) {
                            toastr.success("Email send successfully!");

                        } else {
                            toastr.error("Failed Welcome Email.");
                        }
                    },
                    error: function(error) {
                        console.error(error);
                        toastr.error("An error occurred while processing your request.");
                    }
                });
            }
        }

        function passwordEmailButton(id) {    
            if (confirm("Are you sure you want to update password ?")) {      
                $.ajax({
                    type: "POST",
                    data: {
                        type: "ajax",
                        _token: '{{ csrf_token() }}'
                    },
                    url: "{{ route('candidate.passwordUpdate', ['id' => ':id']) }}".replace(':id', id),
                    success: function(response) {
                        if (response.success) {
                            toastr.success("Email send successfully!");

                        } else {
                            toastr.error("Failed update password Email.");
                        }
                    },
                    error: function(error) {
                        console.error(error);
                        toastr.error("An error occurred while processing your request.");
                    }
                });
            }
        }

        
 ////////////////file name\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        document.getElementById('customFileD').onchange = function() {
            $('#fileHelp').html(" ");
            var file = document.getElementById('customFileD').files[0];
            if(file){
                $('#fileHelp').html(file['name']);
            }else{
                $('#fileHelp').html("Allowed file extensions: Maximum file size:20MB each.");
            }
        };
        </script>
        <script>
                function assignToChange(id,assign_to,type){

                    $(".loader").show();
                // 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() }}',
                            type
                        },
                        dataType: 'json',
                        success: function(result) {
                        if(result.status == "1"){
                                
                                $(".loader").hide();
                                toastr.success("Assign User Successfully");
                                refreshTable();
                             
                                
                            }else{
                                toastr.error("something went wrong");
                                $(".loader").hide();
                            }
                        
                        }
                    });
                // }
                }
        </script>
        <script>
            
            function leadManagementDelete(id){
            if (confirm('{{ __('are_you_sure_you_want_to_delete_this_item') }}')) {
                $(".loader").show();
            $.ajax({
                url: "{{ route('admin.leadManagement.destroy', ['id' => ':id']) }}".replace(':id', id),
                type: "DELETE",
                data: {
                    id: id,
                    _token: '{{ csrf_token() }}'
                },
                dataType: 'json',
                success: function(result) {
                if(result.status == "1"){
                        $(".loader").hide();
                        toastr.success("User Delete Successfully");
                        refreshTable();
                        
                    }else{
                        toastr.error("something went wrong");
                        $(".loader").hide();
                    }
                
                }
            });
            }
            }
        </script>

        <script>
            var country = "{{request('country')}}";
            $.ajax({
                url: "{{ url('countryArray.php') }}?t=" + country,
                success: function(res) {
                    $("#country").html(res);
                }
            });

            
            function lead_create_edit(){
                create_new_lead("save_and_edit");
            }

            function lead_create_close(){
                create_new_lead("save_and_close");
            }

            function create_new_lead(type){
                var flag = 0;
                $('.warning').html("");
                var emailInput = document.getElementById('email').value;
                

                
                var emailInput = document.getElementById('email').value;
                var flag = 0;

                // if ($('#email').val() == null || $('#email').val() == "") {
                //     createWarning("email", "Email Is Not Blank");
                //     flag = 1;
                // } else if (isValidEmail(emailInput) == false) {
                //     createWarning("email", "Enter A Valid Email Id");
                //     flag = 1;
                // }

                if ($('#name').val() == null || $('#name').val() == "") {
                    createWarning("name", "Name Is Not Blank");
                    flag = 1;
                }

                if ($('#phone').val() == null || $('#phone').val() == "") {
                    createWarning("phone", "Phone No. Is Not Blank");
                    flag = 1;
                }

                if ($('#country').val() == null || $('#country').val() == "") {
                    createWarning("country", "Country Is Not Blank");
                    flag = 1;
                }

                // if ($('#source').val() == null || $('#source').val() == "") {
                //     createWarning("source", "Select Source");
                //     flag = 1;
                // }

                formData = new FormData();
                formData.append("email", $('#email').val());
                formData.append("name", $('#name').val());
                formData.append("country", $('#country').val());
                formData.append("phone", $('#phone').val());
                formData.append("source", $('#source').val());
                if(flag == 0){
                    $.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                    });
                    $.ajax({
                        type: 'POST',
                        url: "{{ route('lead-management.create') }}",
                        data: formData,
                        cache: false,
                        processData: false,
                        contentType: false,
                        success: (res) => {

                            if(res.status == 1){
                                var candidate_id = res.candidate_id;
                                $('.create-lead-popup').hide();
                                $('.overlay').hide();
                                toastr.success("Create lead Successfully");
                                refreshTable();
                                if(type == "save_and_close"){
                                    
                                }else if(type == "save_and_edit"){
                                    var candidate_id = res.candidate_id;
                                    window.open('lead-management/' + candidate_id + '/edit', '_blank');
                                }
                               $('body').removeClass('no-scroll');
                            }
                            if(res.status == 2){
                                toastr.error("Something Went Wrong Try Again");
                            }
                            if(res.status == 3){
                                var form = document.getElementById('create_lead');
                                errors_form = res['error'];
                                form_validation_check(form , errors_form);

                            }
                        }
                    });
                }
            }

            function createWarning(inputId, warningMessage) {
                var inputElement = document.getElementById(inputId);
                var warningElement = document.createElement("p");
                warningElement.className = "warning";
                warningElement.textContent = warningMessage;
                inputElement.parentNode.insertBefore(warningElement, inputElement.nextSibling);
            }

            function isValidEmail(email) {
                // Regular expression pattern for email validation
                var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
                console.log(emailPattern.test(email));
                return emailPattern.test(email);
            }

            function form_validation_check(form , errors_form){
                $('.warning').html("");
                var code = "";
                for (const fieldName in errors_form) {
                    if (errors_form.hasOwnProperty(fieldName)) {
                        const errorMessages = errors_form[fieldName];
                        if (errorMessages.length > 0) {
                            code = code + `<p><strong> ${fieldName} : </strong>${errorMessages[0]} </p>`;
                            var warningElement = document.createElement("p");
                            warningElement.className = "warning";
                            warningElement.textContent = errorMessages[0];
                            var allElements = document.querySelectorAll('input[name="' + fieldName + '"], input[id="' + fieldName + '"],select[id="' + fieldName + '"], select[name="' + fieldName + '"]');
                            allElements.forEach(function(element) {
                                var warningElement = document.createElement("p");
                                warningElement.className = "warning";
                                warningElement.textContent = errorMessages[0];
                                element.parentNode.insertBefore(warningElement.cloneNode(true), element.nextSibling);
                            });
                        }
                    }
                }
               
            }

            $(document).on("click", ".create-lead_open", function() {
                let form = document.getElementById("create_lead");
                form.reset();
                $('#source').val('').trigger("change");
                $('#country').val('').trigger("change");
                if (window.innerWidth < 768) {
                    $(".create-lead-popup").animate({ left: "0" });
                } else {
                    $(".create-lead-popup").show();
                }
            })
        </script>

   

@endsection
