@extends('layouts.admin')

@section('content')
<style>
    @media (max-width: 576px) {
        .content-header h1 { font-size: 1.3rem; }
        .card-body { padding: 0.75rem !important; }
        .nav-tabs .nav-link { padding: 0.4rem 0.6rem; font-size: 0.85rem; }
        .table th, .table td { font-size: 0.82rem; padding: 0.5rem 0.5rem; white-space: nowrap; }
    }
</style>
<div class="content-header">
    <div class="container-fluid">
        <h1 class="m-0"><i class="fas fa-balance-scale mr-2"></i>Neraca Laba Rugi</h1>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        
        <div class="card custom-card mb-4 mt-2">
            <div class="card-body p-3 shadow-sm">
                <form action="{{ url()->current() }}" method="GET">
                    <div class="row">
                        <div class="col-12 col-sm-6 col-md-3 mb-2">
                            <label class="small font-weight-bold text-muted"><i class="fas fa-calendar-alt mr-1"></i> Tahun</label>
                            <select name="year" class="form-control form-control-sm">
                                <option value="">Semua Tahun</option>
                                @for($y = date('Y'); $y >= 2020; $y--)
                                    <option value="{{ $y }}" {{ request('year') == $y ? 'selected' : '' }}>{{ $y }}</option>
                                @endfor
                            </select>
                        </div>
                        <div class="col-12 col-sm-6 col-md-3 mb-2">
                            <label class="small font-weight-bold text-muted"><i class="fas fa-moon mr-1"></i> Bulan</label>
                            <select name="month" class="form-control form-control-sm">
                                <option value="">Semua Bulan</option>
                                @php
                                    $months = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
                                @endphp
                                @foreach($months as $i => $m)
                                    <option value="{{ $i + 1 }}" {{ request('month') == ($i + 1) ? 'selected' : '' }}>{{ $m }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-12 col-sm-12 col-md-6 mb-2 d-flex align-items-end flex-wrap gap-2">
                            <div class="d-flex flex-wrap" style="gap: 8px;">
                                <button type="submit" class="btn btn-sm btn-warning text-white">
                                    <i class="fas fa-check-circle mr-1"></i> Filter
                                </button>
                                <a href="{{ url()->current() }}" class="btn btn-sm btn-secondary">
                                    <i class="fas fa-undo mr-1"></i> Reset
                                </a>
                                <a href="{{ url()->current() }}/export-pdf?{{ http_build_query(request()->all()) }}" class="btn btn-sm btn-danger" target="_blank">
                                    <i class="fas fa-file-pdf mr-1"></i> Export PDF
                                </a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <div class="card card-warning card-outline card-tabs">
            <div class="card-header p-0 pt-1 border-bottom-0">
                <ul class="nav nav-tabs" id="custom-tabs-neraca-tab" role="tablist">
                    <li class="nav-item">
                        <a class="nav-link active" id="tab-neraca-total" data-toggle="pill" href="#content-neraca-total" role="tab">Total Gabungan</a>
                    </li>
                    @foreach($branches as $index => $branch)
                    <li class="nav-item">
                        <a class="nav-link" id="tab-neraca-{{ $index }}" data-toggle="pill" href="#content-neraca-{{ $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-neraca-total">
                            <div class="alert alert-info"><i class="fas fa-info-circle"></i> Laporan Keuangan Gabungan.</div>
                            <div class="table-responsive">
                                @include('partials.table_neraca', ['data' => $dataTotal, 'type' => 'total'])
                            </div>
                    </div>
                    @foreach($branches as $index => $branch)
                    <div class="tab-pane fade" id="content-neraca-{{ $index }}">
                            <div class="table-responsive">
                                @include('partials.table_neraca', ['data' => $branchData[$branch] ?? [], 'type' => 'branch'])
                            </div>
                    </div>
                    @endforeach
                </div>
            </div>
        </div>

    </div>
</section>
@endsection
