@extends('layouts.user')
@section('title', __('accounts.edit_account'))

@section('content')
<div class="max-w-3xl mx-auto space-y-4 text-xs">

    <div class="bg-white border p-4 shadow-sm">
        <div class="flex items-start justify-between gap-3 flex-wrap">
            <div>
                <div class="text-[11px] text-slate-500">{{ __('accounts.title') }}</div>
                <div class="text-xl font-extrabold text-slate-900">{{ __('accounts.edit_account') }}</div>
                <div class="text-xs text-slate-500 mt-1">{{ $account->name }}</div>
            </div>

            <a href="{{ route('user.accounts.index') }}"
               class="px-3 py-2 border bg-white text-xs font-semibold hover:bg-slate-50">
                {{ __('accounts.back') }}
            </a>
        </div>
    </div>

    @if($errors->any())
        <div class="border border-rose-200 bg-rose-50 p-3 text-xs text-rose-700">
            <div class="font-bold mb-2">{{ __('accounts.please_fix_these_errors') }}</div>
            <ul class="list-disc ml-5 space-y-1">
                @foreach($errors->all() as $e)
                    <li>{{ $e }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <div class="bg-white border p-4 shadow-sm">
        <form class="grid gap-4" method="POST" action="{{ route('user.accounts.update', $account) }}">
            @csrf
            @method('PUT')

            <div>
                <label class="text-xs font-semibold text-slate-700">{{ __('accounts.name') }}</label>
                <input class="mt-1.5 w-full border border-slate-200 px-3 py-2.5 text-xs focus:border-slate-400 focus:outline-none"
                       name="name"
                       value="{{ old('name', $account->name) }}"
                       required>
            </div>

            <div>
                <label class="text-xs font-semibold text-slate-700">{{ __('accounts.account_number_optional') }}</label>
                <input class="mt-1.5 w-full border border-slate-200 px-3 py-2.5 text-xs focus:border-slate-400 focus:outline-none"
                       name="account_number"
                       value="{{ old('account_number', $account->account_number) }}">
            </div>

            <div class="grid md:grid-cols-2 gap-4">
                <div>
                    <label class="text-xs font-semibold text-slate-700">{{ __('accounts.type') }}</label>
                    <select class="mt-1.5 w-full border border-slate-200 px-3 py-2.5 text-xs focus:border-slate-400 focus:outline-none"
                            name="type"
                            required>
                        <option value="bank" @selected(old('type', $account->type) === 'bank')>{{ __('accounts.bank') }}</option>
                        <option value="mfs" @selected(old('type', $account->type) === 'mfs')>{{ __('accounts.mfs') }}</option>
                        <option value="cash" @selected(old('type', $account->type) === 'cash')>{{ __('accounts.cash') }}</option>
                    </select>
                </div>

                <div>
                    <label class="text-xs font-semibold text-slate-700">{{ __('accounts.status') }}</label>
                    <select class="mt-1.5 w-full border border-slate-200 px-3 py-2.5 text-xs focus:border-slate-400 focus:outline-none"
                            name="status"
                            required>
                        <option value="active" @selected(old('status', $account->status) === 'active')>{{ __('accounts.active') }}</option>
                        <option value="inactive" @selected(old('status', $account->status) === 'inactive')>{{ __('accounts.inactive') }}</option>
                    </select>
                </div>
            </div>

            <div>
                <label class="text-xs font-semibold text-slate-700">{{ __('accounts.opening_balance') }}</label>
                <input type="number"
                       step="any"
                       class="mt-1.5 w-full border border-slate-200 px-3 py-2.5 text-xs focus:border-slate-400 focus:outline-none"
                       name="opening_balance"
                       value="{{ old('opening_balance', $account->opening_balance) }}">
            </div>

            <div class="flex gap-2 pt-1">
                <button class="px-4 py-2.5 bg-slate-900 text-white text-xs font-semibold hover:bg-slate-800">
                    {{ __('accounts.update_account') }}
                </button>

                <a href="{{ route('user.accounts.index') }}"
                   class="px-4 py-2.5 border bg-white text-xs font-semibold hover:bg-slate-50">
                    {{ __('accounts.cancel') }}
                </a>
            </div>
        </form>
    </div>
</div>
@endsection