@extends('layouts.admin')

@section('title', 'Open Account')

@section('content')
<div class="fundi-page-header">
    <div>
        <h1>Open Account</h1>
        <p class="fundi-page-header__desc">Create a new customer account.</p>
    </div>
    <a href="{{ route('admin.accounts.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.accounts.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="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="account_type">Account Type *</label>
                    <select id="account_type" name="account_type" class="fundi-select" required>
                        @foreach(['savings','current','investment','loan_disbursement','escrow'] as $t)
                            <option value="{{ $t }}" @selected(old('account_type') === $t)>{{ ucfirst(str_replace('_',' ',$t)) }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="fundi-form-group">
                    <label for="currency">Currency</label>
                    <input type="text" id="currency" name="currency" class="fundi-input" value="{{ old('currency', 'NGN') }}" maxlength="3">
                </div>
                <div class="fundi-form-group">
                    <label for="interest_rate">Interest Rate (%)</label>
                    <input type="number" step="0.01" min="0" id="interest_rate" name="interest_rate" class="fundi-input" value="{{ old('interest_rate') }}">
                </div>
                <div class="fundi-form-group">
                    <label for="opened_at">Opened Date</label>
                    <input type="date" id="opened_at" name="opened_at" class="fundi-input" value="{{ old('opened_at', date('Y-m-d')) }}">
                </div>
            </div>
            <div class="fundi-form-actions">
                <button type="submit" class="fundi-btn fundi-btn--primary">Open Account</button>
                <a href="{{ route('admin.accounts.index') }}" class="fundi-btn fundi-btn--secondary">Cancel</a>
            </div>
        </form>
    </div>
</div>
@endsection
