@extends('backEnd.master')
@section('title')
    @lang('student.my_profile')
@endsection
@push('css')
    <style>
        table#table_id thead tr th:not(:first-child) {
            padding-left: 30px !important;
        }

        table#table_id tbody tr td:not(:first-child),
        table#table_id tbody tr td:nth-child(2) {
            padding-left: 30px !important;
        }

        .leave_table {
            overflow: hidden;
        }

        .table tbody tr:last-child td,
        .table tbody tr:last-child th {
            border-bottom: none;
        }

        .QA_section .QA_table .table.school-table-style-parent-fees thead th,
        .QA_section .QA_table .table.school-table-style-parent-fees thead td {
            padding: 16px 30px !important;
        }

        .fc th {
            padding: 0 !important;
        }

        .finance-banking-panel {
            background: #ffffff;
            border: 1px solid #dfe4ec;
            border-radius: 8px;
            padding: 24px;
            box-shadow: 0 12px 28px rgba(17, 24, 39, 0.07);
        }

        .finance-banking-head {
            display: flex;
            justify-content: space-between;
            gap: 16px;
            align-items: center;
            flex-wrap: wrap;
            margin-bottom: 20px;
        }

        .finance-banking-head h3 {
            margin: 0;
            font-size: 22px;
            color: #111827;
        }

        .finance-banking-head p,
        .finance-invoice-meta {
            margin: 4px 0 0;
            color: #667085;
        }

        .finance-pay-link {
            white-space: nowrap;
        }

        .finance-unavailable {
            background: #fff7ed;
            border: 1px solid #fed7aa;
            border-radius: 8px;
            color: #9a3412;
            margin-bottom: 18px;
            padding: 14px 16px;
        }

        .finance-account-row {
            align-items: center;
            border-top: 1px solid #edf0f5;
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            justify-content: space-between;
            margin-bottom: 18px;
            padding-top: 16px;
        }

        .finance-account-row span {
            color: #667085;
            font-size: 13px;
        }

        .finance-account-row strong {
            color: #111827;
        }

        .finance-status-pill {
            border-radius: 999px;
            display: inline-flex;
            font-size: 12px;
            font-weight: 700;
            line-height: 1;
            padding: 7px 11px;
            text-transform: uppercase;
        }

        .finance-status-pill.paid {
            background: #e8f7ef;
            color: #137a42;
        }

        .finance-status-pill.partial,
        .finance-status-pill.optional_due {
            background: #fff4df;
            color: #a15c07;
        }

        .finance-status-pill.pending {
            background: #eef4ff;
            color: #3156a3;
        }

        .finance-status-pill.overdue,
        .finance-status-pill.failed {
            background: #fff0ef;
            color: #b3261e;
        }

        .finance-stat-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 14px;
            margin-bottom: 18px;
        }

        .finance-stat-card,
        .finance-invoice-card {
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            background: #fbfcfe;
            padding: 18px;
        }

        .finance-stat-card span {
            display: block;
            color: #64748b;
            font-size: 13px;
            margin-bottom: 8px;
        }

        .finance-stat-card strong {
            color: #111827;
            font-size: 27px;
            line-height: 1.2;
        }

        .finance-section-title {
            align-items: center;
            display: flex;
            justify-content: space-between;
            margin: 4px 0 12px;
        }

        .finance-section-title strong {
            color: #111827;
            font-size: 15px;
        }

        .finance-invoice-list {
            display: grid;
            gap: 12px;
        }

        .finance-invoice-card {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 14px;
            flex-wrap: wrap;
        }

        .finance-invoice-amount {
            text-align: right;
            color: #111827;
            font-weight: 700;
        }

        .finance-account-type {
            display: inline-block;
            margin-top: 6px;
            color: #475569;
            font-size: 13px;
            font-weight: 600;
        }

        .finance-money {
            display: inline-block;
            font-weight: 800;
            min-width: 120px;
            text-align: right;
            white-space: nowrap;
        }

        .finance-redirect-overlay {
            position: fixed;
            inset: 0;
            display: none;
            align-items: center;
            justify-content: center;
            background: rgba(15, 23, 42, 0.46);
            z-index: 9999;
            padding: 20px;
        }

        .finance-redirect-overlay.is-active {
            display: flex;
        }

        .finance-redirect-box {
            width: min(420px, 100%);
            background: #ffffff;
            border-radius: 8px;
            padding: 28px;
            text-align: center;
            box-shadow: 0 20px 60px rgba(15, 23, 42, 0.2);
        }

        .finance-spinner {
            width: 42px;
            height: 42px;
            border: 4px solid #e5e7eb;
            border-top-color: #2f6fed;
            border-radius: 50%;
            margin: 0 auto 16px;
            animation: finance-spin 0.9s linear infinite;
        }

        @keyframes finance-spin {
            to { transform: rotate(360deg); }
        }
    </style>
@endpush
@section('mainContent')
    @php
        @$setting = generalSetting();
        if (!empty(@$setting->currency_symbol)) {
            @$currency = @$setting->currency_symbol;
        } else {
            @$currency = optional(Auth::user())->currency_symbol ?: 'KSh';
        }
        $financeIntegrationEnabled = !empty($financeIntegrationEnabled);
        $financeStatus = data_get($financeSummary, 'status', 'pending');
        $financeUser = Auth::user();
        $financeCurrency = data_get($financeSummary, 'currency', optional($financeUser)->currency_code ?: 'KES');
        $financeUserType = strtolower((string) data_get($financeSummary, 'user_type', optional($financeUser)->user_type ?: 'local'));
        $financeUserType = $financeUserType === 'international' ? 'international' : 'local';
        $financeAccountLabel = $financeUserType === 'international' ? 'International Student' : 'Local Student';
        $financeOutstandingDisplay = data_get($financeSummary, 'formatted_balance')
            ?: data_get($financeSummary, 'formatted_mandatory_outstanding')
            ?: 'Not available';
        $financePaidDisplay = data_get($financeSummary, 'formatted_total_paid') ?: 'Not available';
        $financeInvoices = $financeInvoices ?? [];
        $financeUnavailable = $financeIntegrationEnabled && empty($financeSummary);
        $financeAmount = static function ($value) {
            $value = html_entity_decode((string) $value, ENT_QUOTES | ENT_HTML5, 'UTF-8');
            $value = str_replace(["\xc2\xa0", '&nbsp;'], ' ', $value);
            $value = strip_tags($value);
            $value = preg_replace('/\s+/', ' ', $value);

            return trim(is_string($value) ? $value : '');
        };
        $financeStatusLabel = ucfirst(str_replace('_', ' ', (string) $financeStatus));
        $financeStatusClass = preg_replace('/[^a-z0-9_-]/', '', strtolower((string) $financeStatus));
    @endphp
    <section class="student-details">
        <div class="container-fluid p-0">
            <div class="white-box student-portal-hero">
                <div class="premium-dashboard-hero student-dashboard-hero">
                    <div>
                        <span class="premium-eyebrow">Student portal</span>
                        <h2>@lang('student.welcome_to') {{ @$student_detail->full_name }}</h2>
                        @php
                            $dashboardRecord = @$student_detail->studentRecords ? (@$student_detail->studentRecords->where('is_default', 1)->first() ?: @$student_detail->studentRecords->first()) : null;
                        @endphp
                        <p>
                            {{ @$student_detail->admission_no }}
                            @if (@$student_detail->class && @$student_detail->section)
                                &middot; {{ @$student_detail->class->class_name }} ({{ getStudentAcademicGroupLabel($dashboardRecord) }})
                            @endif
                        </p>
                    </div>
                    <div class="student-quick-actions">
                        @if ($financeIntegrationEnabled && !empty($financePayUrl))
                            <a href="{{ $financePayUrl }}" class="primary-btn fix-gr-bg js-finance-pay">Pay Fees</a>
                        @elseif (\Illuminate\Support\Facades\Route::has(generalSetting()->fees_status == 0 ? 'student_fees' : 'fees.student-fees-list'))
                            <a href="{{ route(generalSetting()->fees_status == 0 ? 'student_fees' : 'fees.student-fees-list') }}" class="primary-btn fix-gr-bg">Pay Fees</a>
                        @endif
                        @if (\Illuminate\Support\Facades\Route::has('student_result'))
                            <a href="{{ route('student_result') }}" class="primary-btn tr-bg">Results</a>
                        @endif
                        @if (\Illuminate\Support\Facades\Route::has('student-profile'))
                            <a href="{{ route('student-profile') }}" class="primary-btn tr-bg">Profile</a>
                        @endif
                    </div>
                </div>
            <div class="row row-gap-30">
                @if (userPermission('dashboard-subject'))
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route('student_units') }}" class="d-block">
                            <div class="white-box single-summery cyan">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('common.subject')</h3>
                                        <p class="mb-0">@lang('student.total_subject')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if (isset($totalSubjects))
                                            {{ count(@$totalSubjects) }}
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif
                @if (userPermission('dashboard-notice') && userPermission('student_noticeboard'))
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route('student_noticeboard') }}" class="d-block">
                            <div class="white-box single-summery violet">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('student.notice')</h3>
                                        <p class="mb-0">@lang('student.total_notice')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if (isset($totalNotices))
                                            {{ count(@$totalNotices) }}
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif
                @if (userPermission('dashboard-exam'))
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route('student_exam_schedule') }}" class="d-block">
                            <div class="white-box single-summery violet">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('student.exam')</h3>
                                        <p class="mb-0">@lang('student.total_exam')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if (isset($exams))
                                            {{ count(@$exams) }}
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif
                @if (userPermission('dashboard-online-exam'))
                    <div class="col-lg-3 col-md-6">
                        @if (moduleStatusCheck('OnlineExam'))
                            <a href="{{ route('om_student_online_exam') }}" class="d-block">
                            @else
                                <a href="{{ route('student_online_exam') }}" class="d-block">
                        @endif
                        <div class="white-box single-summery blue">
                            <div class="d-flex justify-content-between">
                                <div>
                                    <h3>@lang('student.online_exam')</h3>
                                    <p class="mb-0">@lang('student.total_online_exam')</p>
                                </div>
                                <h1 class="gradient-color2">
                                    @if (isset($online_exams))
                                        {{ count(@$online_exams) }}
                                    @endif
                                </h1>
                            </div>
                        </div>
                        </a>
                    </div>
                @endif
                @if (userPermission('dashboard-teachers'))
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route('student_lecturers') }}" class="d-block">
                            <div class="white-box single-summery fuchsia">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('student.teachers')</h3>
                                        <p class="mb-0">@lang('student.total_teachers')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if (isset($teachers))
                                            {{ count(@$teachers) }}
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif
                @if (userPermission('dashboard-issued-books'))
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route('student_book_issue') }}" class="d-block">
                            <div class="white-box single-summery cyan">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('student.issued_book')</h3>
                                        <p class="mb-0">@lang('student.total_issued_book')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if (isset($issueBooks))
                                            {{ count(@$issueBooks) }}
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif
                @if (userPermission('dashboard-pending-homeworks'))
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route('student_assignments') }}" class="d-block">
                            <div class="white-box single-summery violet">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('student.pending_home_work')</h3>
                                        <p class="mb-0">@lang('student.total_pending_home_work')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if (isset($homeworkLists))
                                            {{ count(@$homeworkLists) }}
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif
                @if (userPermission('dashboard-attendance-in-current-month'))
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route('student_my_attendance') }}" class="d-block">
                            <div class="white-box single-summery blue">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('student.attendance_in_current_month')</h3>
                                        <p class="mb-0">@lang('student.total_attendance_in_current_month')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if (isset($attendances))
                                            {{ count(@$attendances) }}
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif

                @php
                    $feesDue = 0;
                    $totalPoint = 0;
                    $balance_fees = 0;
                    foreach ($student_detail->studentRecords as $record) {
                        if (!$financeIntegrationEnabled) {
                            foreach ($record->feesInvoice as $key => $studentInvoice) {
                                $amount = $studentInvoice->Tamount;
                                $weaver = $studentInvoice->Tweaver;
                                $fine = $studentInvoice->Tfine;
                                $paid_amount = $studentInvoice->Tpaidamount;
                                $sub_total = $studentInvoice->Tsubtotal;
                                $feesDue += $amount + $fine - ($paid_amount + $weaver);
                            }
                            foreach ($record->directFeesInstallments as $feesInstallment) {
                                $balance_fees += discount_fees($feesInstallment->amount, $feesInstallment->discount_amount) - $feesInstallment->paid_amount;
                            }
                        }
                        foreach ($record->incidents as $incident) {
                            $totalPoint += $incident->point;
                        }
                    }
                @endphp
                @if ($financeIntegrationEnabled)
                    <div class="col-lg-12">
                        <div class="finance-banking-panel">
                            <div class="finance-banking-head">
                                <div>
                                    <h3>Finance</h3>
                                    <p>Student finance summary</p>
                                </div>
                                <span class="finance-status-pill {{ $financeStatusClass ?: 'pending' }}">{{ $financeStatusLabel }}</span>
                                @if (!empty($financePayUrl))
                                    <a href="{{ $financePayUrl }}" class="primary-btn fix-gr-bg finance-pay-link js-finance-pay">Pay Now</a>
                                @endif
                            </div>

                            <div class="finance-account-row">
                                <span>Account Type</span>
                                <strong>{{ $financeAccountLabel }} ({{ $financeCurrency }})</strong>
                            </div>

                            @if ($financeUnavailable)
                                <div class="finance-unavailable">
                                    Finance system temporarily unavailable. Cached balances will appear here when a previous sync exists.
                                </div>
                            @endif

                            <div class="finance-stat-grid">
                                <div class="finance-stat-card">
                                    <span>Outstanding Balance</span>
                                    <strong class="finance-money">{{ $financeAmount($financeOutstandingDisplay) }}</strong>
                                </div>
                                <div class="finance-stat-card">
                                    <span>Paid Amount</span>
                                    <strong class="finance-money">{{ $financeAmount($financePaidDisplay) }}</strong>
                                </div>
                            </div>

                            <div class="finance-section-title">
                                <strong>Invoice List</strong>
                            </div>
                            <div class="finance-invoice-list">
                                @forelse ($financeInvoices as $invoice)
                                    <div class="finance-invoice-card">
                                        <div>
                                            <strong>{{ data_get($invoice, 'invoice_number') ?: data_get($invoice, 'title', 'Invoice') }}</strong>
                                            <p class="finance-invoice-meta">
                                                {{ ucfirst(str_replace('_', ' ', data_get($invoice, 'status', 'pending'))) }}
                                                @if (data_get($invoice, 'due_date'))
                                                    &middot; Due {{ data_get($invoice, 'due_date') }}
                                                @endif
                                            </p>
                                        </div>
                                        <div class="finance-invoice-amount">
                                            <span class="finance-money">{{ $financeAmount(data_get($invoice, 'formatted_balance', 'Not available')) }}</span>
                                        </div>
                                    </div>
                                @empty
                                    <div class="finance-invoice-card">
                                        <div>
                                            <strong>No invoices available</strong>
                                            <p class="finance-invoice-meta">Finance data will appear here after the next WordPress sync.</p>
                                        </div>
                                    </div>
                                @endforelse
                            </div>

                            <div class="finance-redirect-overlay" id="financeRedirectOverlay" aria-hidden="true">
                                <div class="finance-redirect-box">
                                    <div class="finance-spinner" aria-hidden="true"></div>
                                    <h4>Redirecting to secure payment portal...</h4>
                                    <p>Please wait while we connect you to the finance engine.</p>
                                </div>
                            </div>

                            @if (!empty($financePayUrl))
                                <script>
                                    document.addEventListener('DOMContentLoaded', function () {
                                        document.querySelectorAll('.js-finance-pay').forEach(function (link) {
                                            link.addEventListener('click', function () {
                                                var overlay = document.getElementById('financeRedirectOverlay');
                                                if (overlay) {
                                                    overlay.classList.add('is-active');
                                                }
                                            });
                                        });
                                    });
                                </script>
                            @endif
                        </div>
                    </div>
                @else
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route(generalSetting()->fees_status == 0 ? 'student_fees' : 'fees.student-fees-list') }}" class="d-block">
                            <div class="white-box single-summery fuchsia">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('student.fees')</h3>
                                        <p class="mb-0">@lang('student.total_due_fees')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if(!moduleStatusCheck('University'))
                                            @if (generalSetting()->fees_status == 0)
                                                @if (directFees())
                                                    {{ $currency }}{{ $balance_fees }}
                                                @else
                                                    {{ $currency }}{{ $old_fees }}
                                                @endif
                                            @elseif (isset($feesDue))
                                                {{ $currency }}{{ $feesDue }}
                                            @endif
                                        @else
                                            @if (generalSetting()->fees_status == 1)
                                                {{ $currency }}{{ $feesDue }}

                                            @else 
                                                @if (isset($due_amount))
                                                    {{ $currency }}{{ $due_amount }}
                                                @endif
                                            @endif
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif
                @if (moduleStatusCheck('BehaviourRecords'))
                    <div class="col-lg-3 col-md-6">
                        <a href="{{ route('student-profile') }}" class="d-block">
                            <div class="white-box single-summery cyan">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <h3>@lang('student.behaviour_point')</h3>
                                        <p class="mb-0">@lang('student.total_behaviour_point')</p>
                                    </div>
                                    <h1 class="gradient-color2">
                                        @if (isset($totalPoint))
                                            {{ $totalPoint }}
                                        @endif
                                    </h1>
                                </div>
                            </div>
                        </a>
                    </div>
                @endif
            </div>
            </div>
            <div class="row mt-40">
                @if (userPermission('student_class_routine'))
                    @include('backEnd.studentPanel._class_routine_content', [
                        'sm_weekends' => $sm_weekends,
                        'records' => $records,
                        'routineDashboard' => $routineDashboard,
                    ])
                @endif
                @if (userPermission('student_my_attendance'))
                    @include('backEnd.studentPanel.inc._attendance_statistics')
                    @include('backEnd.studentPanel.inc._dashboard_subject_attendance_tab')
                @endif
                <div class="col-md-12 mt-40">
                    @if (!$financeIntegrationEnabled && userPermission('fees.student-fees-list'))
                        <div class="white-box">
                            @include('backEnd.studentPanel.inc._fees_info', ['currency' => $currency])
                        </div>
                    @endif
                </div>

                <div class="col-md-12 mt-40">
                        @if (userPermission('student_exam_schedule'))
                    <div class="container-fluid p-0">
                        <div class="white-box">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                    <div class="main-title">
                                        <h3 class="mb-15">@lang('exam.exam_routine')</h3>
                                    </div>
                                </div>
                                <div class="col-lg-12 student-details up_admin_visitor">
                                    <ul class="nav nav-tabs tabs_scroll_nav" role="tablist">
                                        @php
                                            $exams = [];
                                        @endphp
                                        @foreach ($records as $record)
                                            @if ($record->Exam)
                                                @foreach ($record->Exam as $key => $exam)
                                                    @php
                                                        $s = $exam->exam_type_id . $exam->class_id . $exam->section_id;
                                                    @endphp
                                                    @if (!in_array($s, $exams))
                                                        @php
                                                            array_push($exams, $s);
                                                        @endphp
                                                        <li class="nav-item">
                                                            <a class="nav-link @if ($key == 0) active @endif"
                                                                href="#tabExam{{ $key }}" role="tab"
                                                                data-toggle="tab">{{ $exam->examType->title }}
                                                                - {{ moduleStatusCheck('University') ? $record->unSemesterLabel->name : $record->class->class_name }}
                                                                ({{ getStudentAcademicGroupLabel($record) }})
                                                            </a>
                                                        </li>
                                                    @endif
                                                @endforeach
                                            @endif
                                        @endforeach
                                    </ul>
                                    <div class="tab-content">
                                        @foreach ($records as $key => $record)
                                            @if ($record->Exam)
                                                @foreach ($record->Exam as $key => $exam)
                                                    @php
                                                        $exam_routines = App\SmExamSchedule::getAllExams($exam->class_id, $exam->section_id, $exam->exam_type_id);
                                                    @endphp
                                                    <div role="tabpanel"
                                                        class="tab-pane fade  @if ($key == 0) active show @endif"
                                                        id="tabExam{{ $key }}">
                                                        <div class="container-fluid p-0">
                                                            <div class="col-lg-12 p-0">
                                                                <x-table>
                                                                    <div class="table-responsive">
                                                                        <table id="default_table" class="table"
                                                                            cellspacing="0"
                                                                            width="100%">
                                                                            <thead>
                                                                                <tr>
                                                                                    <th style="width:10%;">
                                                                                        @lang('exam.date_&_day')
                                                                                    </th>
                                                                                    <th>@lang('exam.subject')</th>
                                                                                    <th>@lang('common.class_Sec')</th>
                                                                                    <th>@lang('exam.teacher')</th>
                                                                                    <th>@lang('exam.time')</th>
                                                                                    <th>@lang('exam.duration')</th>
                                                                                    <th>@lang('exam.room')</th>
    
                                                                                </tr>
                                                                            </thead>
                                                                            <tbody>
                                                                                @foreach ($exam_routines as $date => $exam_routine)
                                                                                    <tr
                                                                                        class="{{ Carbon::parse($exam_routine->date)->format('Y-m-d') == Carbon::now()->format('Y-m-d') ? 'main-border-color' : '' }}">
                                                                                        <td>{{ dateConvert($exam_routine->date) }}
                                                                                            <br>{{ Carbon::createFromFormat('Y-m-d', $exam_routine->date)->format('l') }}
                                                                                        </td>
                                                                                        <td>
                                                                                            <strong>
                                                                                                {{ $exam_routine->subject ? $exam_routine->subject->subject_name : '' }}
                                                                                            </strong>
                                                                                            {{ $exam_routine->subject ? '(' . $exam_routine->subject->subject_code . ')' : '' }}
                                                                                        </td>
                                                                                        <td>{{ $exam_routine->class ? $exam_routine->class->class_name : '' }}
                                                                                            {{ $exam_routine->section ? '(' . $exam_routine->section->section_name . ')' : '' }}
                                                                                        </td>
                                                                                        <td>{{ $exam_routine->teacher ? $exam_routine->teacher->full_name : '' }}
                                                                                        </td>
    
                                                                                        <td> {{ date('h:i A', strtotime(@$exam_routine->start_time)) }}
                                                                                            -
                                                                                            {{ date('h:i A', strtotime(@$exam_routine->end_time)) }}
                                                                                        </td>
                                                                                        <td>
                                                                                            @php
                                                                                                $duration = strtotime($exam_routine->end_time) - strtotime($exam_routine->start_time);
                                                                                            @endphp
    
                                                                                            {{ timeCalculation($duration) }}
                                                                                        </td>
    
                                                                                        <td>{{ $exam_routine->classRoom ? $exam_routine->classRoom->room_no : '' }}
                                                                                        </td>
    
                                                                                    </tr>
                                                                                @endforeach
    
                                                                            </tbody>
                                                                        </table>
                                                                    </div>
                                                                </x-table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                @endforeach
                                            @endif
                                        @endforeach
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                @endif
                </div>
                @if (userPermission('student_teacher'))
                    <div class="container-fluid mt-40">
                        <div class="row">
                            <div class="col-lg-12">
                                @include('backEnd.studentPanel.inc._teacher_list')
                            </div>
                        </div>
                    </div>
                @endif
                @if (userPermission('leave'))
                    <div class="container-fluid mt-40">
                        <div class="row">
                            <div class="col-lg-12">
                                @include('backEnd.studentPanel.inc._leave_type')
                            </div>
                        </div>
                    </div>
                @endif
                <div class="container-fluid mt-40">
                    <div class="row">
                        <div class="col-lg-12">
                            @include('backEnd.studentPanel.inc._complaint_list_tab')
                        </div>
                    </div>
                </div>
            </div>
            <div class="white-box mt-40">
                @if (userPermission('dashboard-calendar'))
                <div class="row">
                    <div class="col-lg-12">
                        @include('backEnd.communicate.commonAcademicCalendar')
                    </div>
                </div>
            @endif
            </div>
        </div>
    </section>

    <div id="fullCalModal" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span> <span
                            class="sr-only">close</span></button>
                    <h4 id="modalTitle" class="modal-title"></h4>
                </div>
                <div class="modal-body text-center">
                    <img src="" alt="There are no image" id="image" height="150" width="auto">
                    <div id="modalBody"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="primary-btn tr-bg" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

    <?php
    $count_event = 0;
    @$calendar_events = [];
    foreach ($holidays as $k => $holiday) {
        @$calendar_events[$k]['title'] = $holiday->holiday_title;
    
        @$calendar_events[$k]['start'] = $holiday->from_date;
    
        @$calendar_events[$k]['end'] = Carbon::parse($holiday->to_date)
            ->addDays(1)
            ->format('Y-m-d');
    
        @$calendar_events[$k]['description'] = $holiday->details;
    
        @$calendar_events[$k]['url'] = $holiday->upload_image_file;
    
        $count_event = $k;
        $count_event++;
    }
    
    foreach ($events as $k => $event) {
        @$calendar_events[$count_event]['title'] = $event->event_title;
    
        @$calendar_events[$count_event]['start'] = $event->from_date;
    
        @$calendar_events[$count_event]['end'] = Carbon::parse($event->to_date)
            ->addDays(1)
            ->format('Y-m-d');
        @$calendar_events[$count_event]['description'] = $event->event_des;
        @$calendar_events[$count_event]['url'] = $event->uplad_image_file;
        $count_event++;
    }
    ?>

@endsection
@include('backEnd.communicate.academic_calendar_css_js')
