<div>
    <x-layouts.app title="{{ __('Adjustments by Location') }}">
        <!-- Page Header -->
        <div class="page-header d-flex justify-content-between align-items-center">
            <div>
                <h1 class="page-title">{{ __('Adjustments by Location') }}</h1>
                <p class="text-muted mb-0">{{ __('Stock adjustments filtered by storage location') }}</p>
            </div>
            <div class="d-flex gap-2">
                <button wire:click="export" class="btn btn-outline-success">
                    <i class="fas fa-file-excel me-2"></i>{{ __('Export') }}
                </button>
                <a href="{{ route('pdf.report.adjustments-by-location', ['date_from' => $dateFrom, 'date_to' => $dateTo, 'location_id' => $locationFilter, 'type' => $typeFilter]) }}" class="btn btn-outline-info">
                    <i class="fas fa-download me-2"></i>{{ __('Download PDF') }}
                </a>
                <a href="{{ route('pdf.report.adjustments-by-location', ['date_from' => $dateFrom, 'date_to' => $dateTo, 'location_id' => $locationFilter, 'type' => $typeFilter, 'preview' => true]) }}" target="_blank" class="btn btn-outline-secondary">
                    <i class="fas fa-print me-2"></i>{{ __('Print') }}
                </a>
            </div>
        </div>

        <!-- Summary Cards -->
        <div class="row g-3 mb-4">
            <div class="col-md-4">
                <div class="card bg-primary text-white h-100">
                    <div class="card-body text-center">
                        <h6 class="text-white-50">{{ __('Total Adjustments') }}</h6>
                        <h2 class="mb-0">{{ number_format($summary->total_adjustments ?? 0) }}</h2>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card bg-success text-white h-100">
                    <div class="card-body text-center">
                        <h6 class="text-white-50">{{ __('Stock In') }}</h6>
                        <h2 class="mb-0">+{{ number_format($summary->total_in ?? 0, 0) }}</h2>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card bg-danger text-white h-100">
                    <div class="card-body text-center">
                        <h6 class="text-white-50">{{ __('Stock Out') }}</h6>
                        <h2 class="mb-0">-{{ number_format($summary->total_out ?? 0, 0) }}</h2>
                    </div>
                </div>
            </div>
        </div>

        <!-- Filters -->
        <div class="card mb-4">
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-md-3">
                        <label class="form-label">{{ __('From Date') }}</label>
                        <input type="date" class="form-control" wire:model.live="dateFrom">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">{{ __('To Date') }}</label>
                        <input type="date" class="form-control" wire:model.live="dateTo">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">{{ __('Location') }}</label>
                        <select class="form-select" wire:model.live="locationFilter">
                            <option value="">{{ __('All Locations') }}</option>
                            @foreach($locations as $location)
                                <option value="{{ $location->id }}">{{ $location->localized_name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">{{ __('Type') }}</label>
                        <select class="form-select" wire:model.live="typeFilter">
                            <option value="">{{ __('All') }}</option>
                            <option value="in">{{ __('Stock In') }}</option>
                            <option value="out">{{ __('Stock Out') }}</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <!-- Adjustments Table -->
        <div class="card">
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead class="table-light">
                            <tr>
                                <th>{{ __('Date') }}</th>
                                <th>{{ __('Product') }}</th>
                                <th>{{ __('Location') }}</th>
                                <th>{{ __('Type') }}</th>
                                <th class="text-center">{{ __('Quantity') }}</th>
                                <th>{{ __('Reason') }}</th>
                                <th>{{ __('User') }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($adjustments as $adj)
                                <tr wire:key="adj-{{ $adj->id }}">
                                    <td>{{ $adj->created_at->format('Y-m-d H:i') }}</td>
                                    <td>
                                        <strong>{{ $adj->product?->localized_name ?? '-' }}</strong>
                                        <small class="text-muted d-block">{{ $adj->product?->sku }}</small>
                                    </td>
                                    <td>{{ $adj->location?->localized_name ?? '-' }}</td>
                                    <td>
                                        <span class="badge bg-{{ $adj->type === 'in' ? 'success' : 'danger' }}">
                                            {{ $adj->type === 'in' ? __('In') : __('Out') }}
                                        </span>
                                    </td>
                                    <td class="text-center">{{ number_format($adj->quantity, 0) }}</td>
                                    <td>{{ $adj->reason ?? '-' }}</td>
                                    <td>{{ $adj->user?->name ?? '-' }}</td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="7" class="text-center py-4 text-muted">
                                        {{ __('No adjustments found.') }}
                                    </td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
            @if($adjustments->hasPages())
                <div class="card-footer">
                    {{ $adjustments->links() }}
                </div>
            @endif
        </div>
    </x-layouts.app>
</div>
