@extends('layouts.admin')

@section('title', 'Stock Audit Report')

@section('content')
<x-admin.report-page title="Stock Audit Report" subtitle="Completed stock audits with excess and shortage totals.">
    <form method="GET" action="{{ route('admin.reports.stock-audit') }}" class="ci-filters ci-filters--report">
        @include('admin.reports.partials.location-filter', ['ci' => true])
        <div class="ci-filters__field">
            <label for="start_date">Start Date</label>
            <input type="date" name="start_date" id="start_date" value="{{ $startDate }}">
        </div>
        <div class="ci-filters__field">
            <label for="end_date">End Date</label>
            <input type="date" name="end_date" id="end_date" value="{{ $endDate }}">
        </div>
        <div class="ci-filters__actions">
            <button type="submit" class="ci-btn ci-btn--primary">Apply</button>
        </div>
    </form>

    <div class="ci-table-card">
        <div class="ci-table-wrap">
            <table class="ci-table">
                <thead>
                    <tr>
                        <th>Audit Name</th>
                        <th>Shop</th>
                        <th>Audit Date</th>
                        <th>Total Products Checked</th>
                        <th class="ci-end">Total Excess</th>
                        <th class="ci-end">Total Shortage</th>
                        <th>Created By</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($audits as $row)
                        <tr>
                            <td>{{ $row->audit->audit_name }}</td>
                            <td>{{ $row->audit->location?->name ?? '—' }}</td>
                            <td class="ci-muted">{{ $row->audit->audit_date->format('Y-m-d') }}</td>
                            <td class="ci-num">{{ $row->total_checked }}</td>
                            <td class="ci-end">
                                <span class="ci-pill ci-pill--success">+{{ number_format($row->total_excess, 2) }}</span>
                            </td>
                            <td class="ci-end">
                                <span class="ci-pill ci-pill--danger">-{{ number_format($row->total_shortage, 2) }}</span>
                            </td>
                            <td>{{ $row->audit->creator?->name ?? '—' }}</td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="7">
                                <div class="ci-empty">
                                    <i class="bi bi-clipboard-check"></i>
                                    <h3>No Audits Found</h3>
                                    <p>No completed audits in this date range.</p>
                                </div>
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</x-admin.report-page>
@endsection
