<x-app-layout>
    <x-slot name="header">{{ __('daily_income') }}</x-slot>

    <div class="card shadow-sm mb-4">
        <div class="card-body">
            <form method="GET" action="{{ route('reports.daily') }}" class="row g-2 align-items-end">
                <div class="col-auto">
                    <label for="date" class="form-label">{{ __('Date') }}</label>
                    <input type="date" id="date" name="date" class="form-control" value="{{ $date }}">
                </div>
                <div class="col-auto">
                    <button type="submit" class="btn btn-primary">{{ __('Filter') }}</button>
                    <a href="{{ route('reports.daily.pdf', ['date' => $date]) }}" class="btn btn-outline-danger ms-2">
                        <i class="bi bi-file-earmark-pdf"></i> PDF
                    </a>
                </div>
            </form>
        </div>
    </div>

    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <div class="card text-bg-success shadow-sm">
                <div class="card-body text-center">
                    <h6 class="card-title">{{ __('sales') }}</h6>
                    <h3>{{ number_format($sales, 2) }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card text-bg-warning shadow-sm">
                <div class="card-body text-center">
                    <h6 class="card-title">{{ __('purchases') }}</h6>
                    <h3>{{ number_format($purchases, 2) }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card text-bg-danger shadow-sm">
                <div class="card-body text-center">
                    <h6 class="card-title">{{ __('expenses') }}</h6>
                    <h3>{{ number_format($expenses, 2) }}</h3>
                </div>
            </div>
        </div>
    </div>

    <div class="card shadow-sm mb-4">
        <div class="card-header fw-bold">{{ __('Summary') }}</div>
        <div class="card-body p-0">
            <table class="table table-bordered mb-0">
                <tbody>
                    <tr>
                        <td>{{ __('sales') }}</td>
                        <td class="text-end text-success fw-bold">{{ number_format($sales, 2) }}</td>
                    </tr>
                    <tr>
                        <td>{{ __('purchases') }}</td>
                        <td class="text-end text-warning fw-bold">{{ number_format($purchases, 2) }}</td>
                    </tr>
                    <tr>
                        <td>{{ __('expenses') }}</td>
                        <td class="text-end text-danger fw-bold">{{ number_format($expenses, 2) }}</td>
                    </tr>
                    <tr class="table-dark">
                        <td><strong>{{ __('Net Income') }}</strong></td>
                        @php $net = $sales - $purchases - $expenses; @endphp
                        <td class="text-end fw-bold {{ $net >= 0 ? 'text-success' : 'text-danger' }}">
                            {{ number_format($net, 2) }}
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    @if($customers->count())
    <div class="card shadow-sm">
        <div class="card-header fw-bold">{{ __('customer_dues') }}</div>
        <div class="card-body p-0">
            <table class="table table-striped mb-0">
                <thead class="table-dark">
                    <tr>
                        <th>#</th>
                        <th>{{ __('Name') }}</th>
                        <th>{{ __('Phone') }}</th>
                        <th class="text-end">{{ __('Due') }}</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($customers as $i => $customer)
                    <tr>
                        <td>{{ $i + 1 }}</td>
                        <td>{{ $customer->name }}</td>
                        <td>{{ $customer->phone }}</td>
                        <td class="text-end text-danger">{{ number_format($customer->current_due, 2) }}</td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
    @endif

</x-app-layout>
