@extends('layouts.app')

@section('content')
<div class="row justify-content-center">
    <div class="col-lg-6">
        <div class="card">
            <div class="card-body">
                <h1 class="h4 mb-3">Edit Account</h1>
                <form method="POST" action="{{ route('accounts.update', $account) }}">
                    @csrf
                    @method('PUT')
                    <div class="mb-3">
                        <label class="form-label" for="name">Name</label>
                        <input class="form-control" id="name" name="name" value="{{ old('name', $account->name) }}" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label" for="currency_id">Currency</label>
                        <select class="form-select" id="currency_id" name="currency_id" required>
                            @foreach($currencies as $currency)
                                <option value="{{ $currency->id }}" @selected(old('currency_id', $account->currency_id) == $currency->id)>
                                    {{ $currency->code }} - {{ $currency->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label" for="type">Type</label>
                        <select class="form-select" id="type" name="type" required>
                            <option value="bank" @selected(old('type', $account->type) === 'bank')>Bank</option>
                            <option value="cash" @selected(old('type', $account->type) === 'cash')>Cash</option>
                        </select>
                    </div>
                    <div class="d-flex gap-2">
                        <button class="btn btn-primary" type="submit">Update Account</button>
                        <a class="btn btn-outline-secondary" href="{{ route('accounts.index') }}">Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
