@extends('layouts.app')
@section('title', __('Products & Stock'))
@section('content')
<div class="card">
    <div class="card-body">
        <div class="d-flex flex-wrap gap-2 justify-content-between mb-3">
            <form class="d-flex gap-2"><input name="search" class="form-control" placeholder="{{ __('Search name or SKU') }}" value="{{ request('search') }}"><button class="btn btn-light"><i class="fa-solid fa-magnifying-glass"></i></button></form>
            <a href="{{ route('products.create') }}" class="btn btn-success"><i class="fa-solid fa-plus me-1"></i>{{ __('Add Product') }}</a>
        </div>
        <div class="table-responsive">
            <table class="table align-middle">
                <thead><tr><th>{{ __('Product') }}</th><th>{{ __('Category') }}</th><th>{{ __('Retail') }}</th><th>{{ __('Wholesale') }}</th><th>{{ __('Stock') }}</th><th></th></tr></thead>
                <tbody>
                    @forelse($products as $product)
                        <tr><td><strong>{{ $product->name }}</strong><small class="d-block text-muted">{{ $product->sku }} - {{ $product->unit }}</small></td><td>{{ $product->category?->name ?? '-' }}</td><td class="money">{{ number_format($product->retail_price, 2) }} {{ $moneyCode }}</td><td class="money">{{ number_format($product->wholesale_price, 2) }} {{ $moneyCode }}</td><td><span class="badge {{ $product->stock_quantity <= $product->low_stock_at ? 'badge-danger' : 'badge-soft' }} rounded-pill">{{ $product->stock_quantity }}</span></td><td class="text-end"><a href="{{ route('products.edit', $product) }}" class="btn btn-light btn-sm"><i class="fa-solid fa-pen"></i></a><form class="d-inline" method="POST" action="{{ route('products.destroy', $product) }}" onsubmit="return confirm('{{ __('Remove this product?') }}')">@csrf @method('DELETE')<button class="btn btn-light btn-sm text-danger"><i class="fa-solid fa-trash"></i></button></form></td></tr>
                    @empty
                        <tr><td colspan="6" class="text-center text-muted py-5">{{ __('Add your first product to begin.') }}</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        {{ $products->links('pagination::bootstrap-5') }}
    </div>
</div>
@endsection
