@view('header', [ 'title' => 'Edit account - Accounts - Admin' ])

<div class="breadcrumb">
    <ul>
        <li><a href="/">Banq</a></li>
        <li><a href="/admin">Admin</a></li>
        <li><a href="/admin/accounts">Accounts</a></li>
        <li><a href="/admin/accounts/{{ $account->id }}">{{ $account->name }}</a></li>
        <li class="is-active"><a href="/admin/accounts/{{ $account->id }}/edit">Edit</a></li>
    </ul>
</div>

<h1 class="title">Edit account</h1>

@view('errors')

<form method="post" action="/admin/accounts/{{ $account->id }}">
    @view('csrf_token')

    <div class="field">
        <label class="label" for="name">Name</label>
        <input class="input" type="text" id="name" name="name" value="{{ old('name', $account->name) }}" {{ !isset($errors) ? 'autofocus' : '' }} required>
    </div>

    <div class="field">
        <label class="label" for="type">Type</label>
        <select class="input" id="type" name="type" required>
            <option value="" disabled {{ old('type', $account->type) == '' ? 'selected' : '' }}>Choose a type</option>
            <option value="{{ Accounts::TYPE_SAVE }}" {{ old('type', $account->type) == Accounts::TYPE_SAVE ? 'selected' : '' }}>Save</option>
            <option value="{{ Accounts::TYPE_PAYMENT }}" {{ old('type', $account->type) == Accounts::TYPE_PAYMENT ? 'selected' : '' }}>Payment</option>
        </select>
    </div>

    <div class="field">
        <label class="label" for="user_id">User</label>
        <select class="input" id="user_id" name="user_id" required>
            @foreach ($users as $user):
                <option value="{{ $user->id }}" {{ $user->id == old('user_id', $account->user_id) ? 'selected' : ''}}>{{ $user->firstname }} {{ $user->lastname }}</option>
            @endforeach
        </select>
    </div>

    <div class="field">
        <label class="label" for="amount">Amount</label>
        <input class="input" type="number" id="amount" name="amount" step="0.01" value="{{ old('amount', $account->amount) }}" required>
    </div>

    <div class="field">
        <button class="button is-link" type="submit">Edit account</button>
    </div>
</form>

@view('footer')
