@extends('layouts.admin')

@section('title', 'New Loan Application')

@section('content')
<div class="fundi-page-header">
    <div>
        <h1>New Loan Application</h1>
        <p class="fundi-page-header__desc">Submit a loan application for underwriting.</p>
    </div>
    <a href="{{ route('admin.loans.index') }}" class="fundi-btn fundi-btn--secondary">Back</a>
</div>

<div class="fundi-card">
    <div class="fundi-card__body fundi-card__body--padded">
        <form method="POST" action="{{ route('admin.loans.store') }}">
            @csrf
            <div class="fundi-form-grid">
                <div class="fundi-form-group">
                    <label for="customer_id">Customer *</label>
                    <select id="customer_id" name="customer_id" class="fundi-select" required>
                        <option value="">— Select —</option>
                        @foreach($customers as $c)
                            <option value="{{ $c->id }}" @selected(old('customer_id') == $c->id)>{{ $c->customer_no }} — {{ $c->display_name }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="fundi-form-group">
                    <label for="product_id">Product *</label>
                    <select id="product_id" name="product_id" class="fundi-select" required>
                        <option value="">— Select —</option>
                        @foreach($products as $p)
                            <option value="{{ $p->id }}" @selected(old('product_id') == $p->id)>{{ $p->name }} ({{ $p->interest_rate }}%)</option>
                        @endforeach
                    </select>
                </div>
                <div class="fundi-form-group">
                    <label for="branch_id">Branch</label>
                    <select id="branch_id" name="branch_id" class="fundi-select">
                        <option value="">— Select —</option>
                        @foreach($branches as $b)
                            <option value="{{ $b->id }}" @selected(old('branch_id') == $b->id)>{{ $b->name }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="fundi-form-group">
                    <label for="principal">Principal (₦) *</label>
                    <input type="number" step="0.01" min="1" id="principal" name="principal" class="fundi-input" value="{{ old('principal') }}" required>
                </div>
                <div class="fundi-form-group">
                    <label for="tenor_months">Tenor (months) *</label>
                    <input type="number" min="1" id="tenor_months" name="tenor_months" class="fundi-input" value="{{ old('tenor_months') }}" required>
                </div>
                <div class="fundi-form-group">
                    <label for="interest_rate">Interest Rate (%)</label>
                    <input type="number" step="0.0001" min="0" id="interest_rate" name="interest_rate" class="fundi-input" value="{{ old('interest_rate') }}">
                </div>
                <div class="fundi-form-group">
                    <label for="interest_method">Interest Method</label>
                    <select id="interest_method" name="interest_method" class="fundi-select">
                        <option value="">Product default</option>
                        @foreach(['reducing','flat','discount'] as $m)
                            <option value="{{ $m }}" @selected(old('interest_method') === $m)>{{ ucfirst($m) }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="fundi-form-group">
                    <label for="processing_fee">Processing Fee (₦)</label>
                    <input type="number" step="0.01" min="0" id="processing_fee" name="processing_fee" class="fundi-input" value="{{ old('processing_fee') }}">
                </div>
                <div class="fundi-form-group">
                    <label for="credit_score">Credit Score</label>
                    <input type="number" min="0" max="900" id="credit_score" name="credit_score" class="fundi-input" value="{{ old('credit_score') }}">
                </div>
            </div>
            <div class="fundi-form-group">
                <label for="purpose">Purpose</label>
                <input type="text" id="purpose" name="purpose" class="fundi-input" value="{{ old('purpose') }}">
            </div>
            <div class="fundi-form-actions">
                <button type="submit" class="fundi-btn fundi-btn--primary">Submit Application</button>
                <a href="{{ route('admin.loans.index') }}" class="fundi-btn fundi-btn--secondary">Cancel</a>
            </div>
        </form>
    </div>
</div>
@endsection
