@extends(auth()->user()->role == 'admin' ? 'layouts.admin' : 'layouts.app')

@section('content')
<div class="content-header">
    <div class="container-fluid">
        <h1 class="m-0"><i class="fas fa-clipboard-list mr-2"></i>Jurnal Umum</h1>
    </div>
</div>

<section class="content">
    <div class="container-fluid">

        @if(auth()->user()->role == 'admin')
            <div class="card card-primary card-outline card-tabs">
                <div class="card-header p-0 pt-1 border-bottom-0">
                    <ul class="nav nav-tabs" id="custom-tabs-ju-tab" role="tablist">
                        <li class="nav-item">
                            <a class="nav-link active" id="tab-ju-total" data-toggle="pill" href="#content-ju-total" role="tab">Total Gabungan</a>
                        </li>
                        @foreach($branches as $index => $branch)
                        <li class="nav-item">
                            <a class="nav-link" id="tab-ju-{{ $index }}" data-toggle="pill" href="#content-ju-{{ $index }}" role="tab">{{ $branch }}</a>
                        </li>
                        @endforeach
                    </ul>
                </div>
                <div class="card-body">
                     <div class="tab-content">
                        <div class="tab-pane fade show active" id="content-ju-total">
                             <div class="alert alert-info"><i class="fas fa-info-circle"></i> Jurnal Gabungan.</div>
                             @include('partials.table_jurnal_umum', ['journal' => $journalTotal])
                        </div>
                        @foreach($branches as $index => $branch)
                        <div class="tab-pane fade" id="content-ju-{{ $index }}">
                             @include('partials.table_jurnal_umum', ['journal' => $branchJournals[$branch] ?? []])
                        </div>
                        @endforeach
                     </div>
                </div>
            </div>
        @else
             <!-- KARYAWAN VIEW -->
            <div class="card shadow border-0">
                <div class="card-header bg-primary text-white">
                    <i class="fas fa-table mr-2"></i>Data Jurnal Umum - {{ session('branch') }}
                </div>
                <div class="card-body table-responsive">
                    <table class="table table-bordered table-striped">
                        <thead class="bg-primary text-white">
                            <tr>
                                <th>Tanggal</th>
                                <th>Keterangan</th>
                                <th>Reff</th>
                                <th>Debet</th>
                                <th>Kredit</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>2025-09-01</td>
                                <td>Kas pada Penjualan</td>
                                <td>101</td>
                                <td>Rp20.000</td>
                                <td>-</td>
                            </tr>
                             <tr>
                                <td>2025-09-01</td>
                                <td>Penjualan</td>
                                <td>401</td>
                                <td>-</td>
                                <td>Rp20.000</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        @endif

    </div>
</section>
@endsection
