@extends('layouts.app')

@section('content')
<div class="card">
    <div class="card-body">
        <h1 class="h4 mb-3">Initial Currency Stock</h1>
        <form method="POST" action="{{ route('setup.initial-stocks.update') }}">
            @csrf
            <div class="table-responsive">
                <table class="table table-striped align-middle">
                    <thead>
                        <tr>
                            <th>Currency</th>
                            <th class="text-end">Starting Quantity</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($currencies as $currency)
                            <tr>
                                <td class="fw-semibold">{{ $currency->code }} - {{ $currency->name }}</td>
                                <td>
                                    <input class="form-control text-end atm-decimal" name="stocks[{{ $currency->id }}][quantity]" inputmode="numeric" placeholder="0.00" value="{{ old('stocks.' . $currency->id . '.quantity', optional($currency->stock)->quantity ?? 0) }}" required>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td class="text-muted text-center" colspan="2">Add currencies before setting initial stock.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            @if($currencies->isNotEmpty())
                <button class="btn btn-primary" type="submit">Update Stock</button>
            @endif
        </form>
    </div>
</div>
@endsection
