@php
    $v = $selected;
    $s = $statement;
@endphp
<div class="billing-statement-doc" id="billing-statement-print">
    <div class="billing-statement-doc__header row g-3 mb-4">
        <div class="col-md-6">
            <h5 class="fw-semibold mb-2">{{ $company->name ?? config('app.name') }}</h5>
            @if($company)
                <p class="text-muted small mb-0">
                    @if($company->address){{ $company->address }}<br>@endif
                    @if($company->city){{ $company->city }}, {{ $company->state }} {{ $company->pincode }}<br>@endif
                    @if($company->phone){{ $company->phone }}<br>@endif
                    @if($company->email){{ $company->email }}@endif
                </p>
            @endif
        </div>
        <div class="col-md-6 text-md-end">
            <h4 class="fw-bold text-uppercase mb-1">Statement of Accounts</h4>
            <p class="text-muted mb-0">
                From {{ $s['from']->format('d - M - Y') }} To {{ $s['to']->format('d - M - Y') }}
            </p>
        </div>
    </div>

    <div class="row g-3 mb-4">
        <div class="col-md-7">
            <p class="text-muted small mb-1">To</p>
            <h6 class="fw-semibold">{{ $v->name }}</h6>
            <address class="small text-muted mb-1">
                @foreach($v->billingAddressLines() as $line)
                    {{ $line }}<br>
                @endforeach
            </address>
            @if($v->email)<div class="small"><i class="ri-mail-line"></i> {{ $v->email }}</div>@endif
            @if($v->phone)<div class="small"><i class="ri-phone-line"></i> {{ $v->phone }}</div>@endif
            @if($v->gstin)<div class="small mt-1"><strong>GSTIN:</strong> {{ $v->gstin }}</div>@endif
        </div>
        <div class="col-md-5">
            <div class="billing-statement-summary">
                <div class="billing-statement-summary__head">Account summary</div>
                <div class="billing-statement-summary__row">
                    <span>Carry Forward</span>
                    <span>₹{{ number_format($s['carry_forward'], 2) }}</span>
                </div>
                <div class="billing-statement-summary__row">
                    <span>Billed Amount</span>
                    <span>₹{{ number_format($s['billed_amount'], 2) }}</span>
                </div>
                <div class="billing-statement-summary__row">
                    <span>Amount paid</span>
                    <span>₹{{ number_format($s['amount_paid'], 2) }}</span>
                </div>
                <div class="billing-statement-summary__row billing-statement-summary__row--total">
                    <span>Balance due</span>
                    <span>₹{{ number_format($s['balance_due'], 2) }}</span>
                </div>
            </div>
        </div>
    </div>

    <div class="table-responsive">
        <table class="table table-bordered billing-statement-table mb-0">
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Transaction</th>
                    <th>Details</th>
                    <th class="text-end">Amount (₹)</th>
                    <th class="text-end">Payments (₹)</th>
                    <th class="text-end">Balance (₹)</th>
                </tr>
            </thead>
            <tbody>
                @foreach($s['rows'] as $row)
                    <tr class="{{ !empty($row['is_carry_forward']) ? 'table-light' : '' }}">
                        <td>{{ $row['date']->format('d - M - Y') }}</td>
                        <td>{{ $row['transaction'] }}</td>
                        <td>{{ $row['details'] ?: '—' }}</td>
                        <td class="text-end">{{ $row['amount'] > 0 ? number_format($row['amount'], 2) : '0.00' }}</td>
                        <td class="text-end">{{ $row['payment'] > 0 ? number_format($row['payment'], 2) : '0.00' }}</td>
                        <td class="text-end fw-medium">{{ number_format($row['balance'], 2) }}</td>
                    </tr>
                @endforeach
            </tbody>
            <tfoot>
                <tr class="table-light">
                    <td colspan="5" class="text-end fw-semibold">Balance due</td>
                    <td class="text-end fw-bold">₹{{ number_format($s['balance_due'], 2) }}</td>
                </tr>
            </tfoot>
        </table>
    </div>

    <p class="text-muted small text-center mt-4 mb-0">Statement of accounts — {{ config('app.name', 'Billing ERP') }}</p>
</div>
