<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ config('app.name', 'SPP App') }} | @yield('title')</title>

    <!-- Google Font: Source Sans Pro -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <!-- Font Awesome Icons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css">
    <!-- Select2 -->
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ttskch/select2-bootstrap4-theme@x.x.x/dist/select2-bootstrap4.min.css">
    
    @stack('styles')
</head>
<body class="hold-transition sidebar-mini layout-fixed layout-navbar-fixed">
<div class="wrapper">

    <!-- Navbar -->
    <nav class="main-header navbar navbar-expand navbar-white navbar-light">
        <!-- Left navbar links -->
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
            </li>
        </ul>

        <!-- Right navbar links -->
        <ul class="navbar-nav ml-auto">
            @auth
            <li class="nav-item">
                <form action="{{ route('logout') }}" method="POST" class="d-inline">
                    @csrf
                    <button type="submit" class="btn btn-default btn-flat border-0 bg-transparent text-secondary">
                        <i class="fas fa-sign-out-alt"></i> Logout
                    </button>
                </form>
            </li>
            @endauth
        </ul>
    </nav>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->
    <aside class="main-sidebar sidebar-dark-primary elevation-4">
        <!-- Brand Logo -->
        <a href="{{ route('dashboard') }}" class="brand-link">
            <span class="brand-text font-weight-light">{{ config('app.name', 'SPP App') }}</span>
        </a>

        <!-- Sidebar -->
        <div class="sidebar">
            <!-- Sidebar user panel (optional) -->
            @auth
            <div class="user-panel mt-3 pb-3 mb-3 d-flex">
                <div class="image">
                    <img src="https://ui-avatars.com/api/?name={{ urlencode(Auth::user()->name) }}&background=random" class="img-circle elevation-2" alt="User Image">
                </div>
                <div class="info">
                    <a href="#" class="d-block">{{ Auth::user()->name }}</a>
                    @if(Auth::user()->role)
                        <span class="badge badge-secondary" style="font-size: 0.75rem;">{{ Auth::user()->role->label }}</span>
                    @endif
                </div>
            </div>
            @endauth

            <!-- Sidebar Menu -->
            <nav class="mt-2">
                <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
                    <li class="nav-item">
                        <a href="{{ route('dashboard') }}" class="nav-link {{ request()->routeIs('dashboard') ? 'active' : '' }}">
                            <i class="nav-icon fas fa-tachometer-alt"></i>
                            <p>Dashboard</p>
                        </a>
                    </li>
                    
                    @if(Auth::user()->hasRole('admin'))
                    @php
                        $isDataMasterActive = request()->routeIs('tahun-ajaran.*') || request()->routeIs('kelas.*') || request()->routeIs('siswa.*') || request()->routeIs('tarif-pembayaran.*');
                    @endphp
                    <li class="nav-item {{ $isDataMasterActive ? 'menu-open' : '' }}">
                        <a href="#" class="nav-link {{ $isDataMasterActive ? 'active' : '' }}">
                            <i class="nav-icon fas fa-database"></i>
                            <p>
                                Data Master
                                <i class="right fas fa-angle-left"></i>
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="{{ route('tahun-ajaran.index') }}" class="nav-link {{ request()->routeIs('tahun-ajaran.*') ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Tahun Ajaran</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('kelas.index') }}" class="nav-link {{ request()->routeIs('kelas.*') ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Kelas</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('tarif-pembayaran.index') }}" class="nav-link {{ request()->routeIs('tarif-pembayaran.*') ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Data Tarif Pembayaran</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('siswa.index') }}" class="nav-link {{ request()->routeIs('siswa.*') ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Data Siswa</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                    
                    <li class="nav-item">
                        <a href="{{ route('kenaikan-kelas.index') }}" class="nav-link {{ request()->routeIs('kenaikan-kelas.*') ? 'active' : '' }}">
                            <i class="nav-icon fas fa-user-plus"></i>
                            <p>Registrasi Siswa</p>
                        </a>
                    </li>
                    @endif

                    @if(Auth::user()->hasRole('admin'))
                    @php
                        $isPembayaranActive = request()->routeIs('tagihan.*') || request()->routeIs('transaksi.*');
                    @endphp
                    <li class="nav-item {{ $isPembayaranActive ? 'menu-open' : '' }}">
                        <a href="#" class="nav-link {{ $isPembayaranActive ? 'active' : '' }}">
                            <i class="nav-icon fas fa-money-bill-wave"></i>
                            <p>
                                Pembayaran
                                <i class="right fas fa-angle-left"></i>
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="{{ route('transaksi.create') }}" class="nav-link {{ request()->routeIs('transaksi.*') ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Transaksi Pembayaran</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('tagihan.index') }}" class="nav-link {{ request()->routeIs('tagihan.*') ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Tagihan Siswa</p>
                                </a>
                            </li>
                        </ul>
                    </li>
                    @endif



                    @if(Auth::user()->hasAnyRole(['admin', 'bendahara', 'kepala_sekolah', 'yayasan', 'wali_kelas']))
                    @php
                        $isLaporanActive = request()->routeIs('laporan.*');
                    @endphp
                    <li class="nav-item {{ $isLaporanActive ? 'menu-open' : '' }}">
                        <a href="#" class="nav-link {{ $isLaporanActive ? 'active' : '' }}">
                            <i class="nav-icon fas fa-chart-line"></i>
                            <p>
                                Laporan
                                <i class="right fas fa-angle-left"></i>
                            </p>
                        </a>
                        <ul class="nav nav-treeview">
                            <li class="nav-item">
                                <a href="{{ route('laporan.index', ['tab' => 'spp']) }}" class="nav-link {{ request()->routeIs('laporan.*') && request('tab', 'spp') === 'spp' ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>SPP</p>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a href="{{ route('laporan.index', ['tab' => 'dpp']) }}" class="nav-link {{ request()->routeIs('laporan.*') && request('tab') === 'dpp' ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>DPP</p>
                                </a>
                            </li>
                            @if(!Auth::user()->hasRole('wali_kelas'))
                            <li class="nav-item">
                                <a href="{{ route('laporan.index', ['tab' => 'tagihan']) }}" class="nav-link {{ request()->routeIs('laporan.*') && request('tab') === 'tagihan' ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Tagihan</p>
                                </a>
                            </li>
                            @endif
                            @if(!Auth::user()->hasAnyRole(['wali_kelas', 'kepala_sekolah']))
                            <li class="nav-item">
                                <a href="{{ route('laporan.index', ['tab' => 'harian']) }}" class="nav-link {{ request()->routeIs('laporan.*') && request('tab') === 'harian' ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Harian</p>
                                </a>
                            </li>
                            @endif
                            @if(!Auth::user()->hasAnyRole(['wali_kelas', 'kepala_sekolah']))
                            <li class="nav-item">
                                <a href="{{ route('laporan.index', ['tab' => 'riwayat']) }}" class="nav-link {{ request()->routeIs('laporan.*') && request('tab') === 'riwayat' ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Riwayat Pembayaran</p>
                                </a>
                            </li>
                            @endif
                            @if(Auth::user()->hasAnyRole(['admin', 'bendahara']))
                            <li class="nav-item">
                                <a href="{{ route('laporan.riwayat-wa') }}" class="nav-link {{ request()->routeIs('laporan.riwayat-wa') ? 'active' : '' }}">
                                    <i class="far fa-circle nav-icon"></i>
                                    <p>Riwayat Pengiriman WA</p>
                                </a>
                            </li>
                            @endif
                        </ul>
                    </li>
                    @endif
                    
                    @if(Auth::user()->hasRole('admin'))
                    <li class="nav-item">
                        <a href="{{ route('users.index') }}" class="nav-link {{ request()->routeIs('users.*') ? 'active' : '' }}">
                            <i class="nav-icon fas fa-users"></i>
                            <p>Manajemen User</p>
                        </a>
                    </li>

                    @endif
                </ul>
            </nav>
            <!-- /.sidebar-menu -->
        </div>
        <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0">@yield('title')</h1>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->
        </div>
        <!-- /.content-header -->

        <!-- Main content -->
        <div class="content">
            <div class="container-fluid">
                @yield('content')
            </div><!-- /.container-fluid -->
        </div>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

    <!-- Main Footer -->
    <footer class="main-footer">
        <div class="float-right d-none d-sm-inline">
            Version 1.0.0
        </div>
        <strong>Copyright &copy; {{ date('Y') }} <a href="#">{{ config('app.name', 'SPP App') }}</a>.</strong> All rights reserved.
    </footer>
</div>
<!-- ./wrapper -->

<!-- REQUIRED SCRIPTS -->

<!-- jQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/js/adminlte.min.js"></script>
<!-- Select2 -->
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>

@stack('scripts')
</body>
</html>
