@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-book mr-2"></i>Buku Besar</h1>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        
        @if(auth()->user()->role == 'admin')
            <div class="card card-secondary card-outline card-tabs">
                <div class="card-header p-0 pt-1 border-bottom-0">
                    <ul class="nav nav-tabs" id="custom-tabs-bb-tab" role="tablist">
                        <li class="nav-item">
                            <a class="nav-link active" id="tab-bb-total" data-toggle="pill" href="#content-bb-total" role="tab">Total Gabungan</a>
                        </li>
                        @foreach($branches as $index => $branch)
                        <li class="nav-item">
                            <a class="nav-link" id="tab-bb-{{ $index }}" data-toggle="pill" href="#content-bb-{{ $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-bb-total">
                             <div class="alert alert-info"><i class="fas fa-info-circle"></i> Buku Besar Gabungan.</div>
                             @include('partials.table_buku_besar', ['ledger' => $ledgerTotal])
                        </div>
                        @foreach($branches as $index => $branch)
                        <div class="tab-pane fade" id="content-bb-{{ $index }}">
                             @include('partials.table_buku_besar', ['ledger' => $branchLedgers[$branch] ?? []])
                        </div>
                        @endforeach
                     </div>
                </div>
            </div>
        @else
             <!-- KARYAWAN VIEW -->
            <div class="card shadow border-0">
                <div class="card-header bg-secondary text-white">
                    <i class="fas fa-table mr-2"></i>Data Buku Besar - {{ session('branch') }}
                </div>
                <div class="card-body table-responsive">
                    <table class="table table-bordered table-striped">
                        <thead class="bg-secondary text-white">
                            <tr>
                                <th>Tanggal</th>
                                <th>Akun</th>
                                <th>Keterangan</th>
                                <th>Debet</th>
                                <th>Kredit</th>
                                <th>Saldo</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>2025-09-01</td>
                                <td>Kas</td>
                                <td>Penjualan</td>
                                <td>Rp20.000</td>
                                <td>-</td>
                                <td>Rp20.000</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        @endif

    </div>
</section>
@endsection
