@extends('layouts.app')

@section('content')
<div class="row justify-content-center">
    <div class="col-lg-6">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">Record Borrow</h5>
            </div>
            <div class="card-body">
                <form method="POST" action="{{ route('borrows.store') }}">
                    @csrf
                    <div class="row g-3">
                        <div class="col-md-12">
                            <label class="form-label" for="agent_id">Agent</label>
                            <select class="form-select" id="agent_id" name="agent_id" required>
                                <option value="">Select agent</option>
                                @foreach($agents as $agent)
                                    <option value="{{ $agent->id }}" @selected(old('agent_id') == $agent->id)>
                                        {{ $agent->name }}
                                    </option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-md-12">
                            <label class="form-label" for="currency_id">Currency to Borrow</label>
                            <select class="form-select" id="currency_id" name="currency_id" required>
                                <option value="">Select currency</option>
                                @foreach($currencies as $currency)
                                    <option value="{{ $currency->id }}" @selected(old('currency_id') == $currency->id)>
                                        {{ $currency->code }} - {{ $currency->name }}
                                    </option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-md-12">
                            <label class="form-label" for="target_account_id">Target Account (To receive borrowed currency)</label>
                            <select class="form-select" id="target_account_id" name="target_account_id" required>
                                <option value="">Select target account</option>
                                @foreach($accounts as $account)
                                    <option value="{{ $account->id }}" @selected(old('target_account_id') == $account->id)>
                                        {{ $account->name }} - {{ number_format((float) $account->balance, 2) }} {{ $account->currency->code }}
                                    </option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-md-12">
                            <label class="form-label" for="date">Transaction Date</label>
                            <input type="date" class="form-control" id="date" name="date" value="{{ old('date', now()->format('Y-m-d')) }}" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" for="quantity">Quantity Borrowed</label>
                            <input class="form-control text-end atm-decimal" id="quantity" name="quantity" inputmode="numeric" placeholder="0.00" value="{{ old('quantity') }}" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label" for="rate">Agreed Rate</label>
                            <input class="form-control text-end atm-decimal" id="rate" name="rate" inputmode="numeric" placeholder="0.00" value="{{ old('rate') }}" required>
                        </div>
                    </div>
                    <div class="d-flex justify-content-end mt-4">
                        <button class="btn btn-primary" type="submit">Save Borrow</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
