@php($asset = $asset ?? null)

<div style="display:grid; grid-template-columns: repeat(2, 1fr); gap:16px;">
    <div class="form-group">
        <label class="form-label" for="asset_code">Asset Code</label>
        <input class="input" type="text" id="asset_code" name="asset_code" value="{{ old('asset_code', $asset?->asset_code) }}" required>
    </div>
    <div class="form-group">
        <label class="form-label" for="name">Name</label>
        <input class="input" type="text" id="name" name="name" value="{{ old('name', $asset?->name) }}" required>
    </div>
    <div class="form-group">
        <label class="form-label" for="category">Category</label>
        <input class="input" type="text" id="category" name="category" value="{{ old('category', $asset?->category) }}" placeholder="e.g. Buildings, Vehicles">
    </div>
    <div class="form-group">
        <label class="form-label" for="purchase_date">Purchase Date</label>
        <input class="input" type="date" id="purchase_date" name="purchase_date" value="{{ old('purchase_date', optional($asset?->purchase_date)->format('Y-m-d')) }}">
    </div>
    <div class="form-group">
        <label class="form-label" for="purchase_cost">Purchase Cost</label>
        <input class="input" type="number" step="0.01" min="0" id="purchase_cost" name="purchase_cost" value="{{ old('purchase_cost', $asset?->purchase_cost ?? 0) }}" required>
    </div>
    <div class="form-group">
        <label class="form-label" for="salvage_value">Salvage Value</label>
        <input class="input" type="number" step="0.01" min="0" id="salvage_value" name="salvage_value" value="{{ old('salvage_value', $asset?->salvage_value ?? 0) }}">
    </div>
    <div class="form-group">
        <label class="form-label" for="useful_life_months">Useful Life (months)</label>
        <input class="input" type="number" min="1" id="useful_life_months" name="useful_life_months" value="{{ old('useful_life_months', $asset?->useful_life_months) }}">
    </div>
    <div class="form-group">
        <label class="form-label" for="depreciation_method">Depreciation Method</label>
        <input class="input" type="text" id="depreciation_method" name="depreciation_method" value="{{ old('depreciation_method', $asset?->depreciation_method ?? 'straight_line') }}">
    </div>
    <div class="form-group">
        <label class="form-label" for="asset_account_id">Asset Account</label>
        <select class="input" id="asset_account_id" name="asset_account_id">
            <option value="">Select account</option>
            @foreach ($assetAccounts as $account)
                <option value="{{ $account->id }}" @selected(old('asset_account_id', $asset?->asset_account_id) == $account->id)>
                    {{ $account->code }} — {{ $account->name }}
                </option>
            @endforeach
        </select>
    </div>
    <div class="form-group">
        <label class="form-label" for="depreciation_account_id">Depreciation Account</label>
        <select class="input" id="depreciation_account_id" name="depreciation_account_id">
            <option value="">Select account</option>
            @foreach ($depreciationAccounts as $account)
                <option value="{{ $account->id }}" @selected(old('depreciation_account_id', $asset?->depreciation_account_id) == $account->id)>
                    {{ $account->code }} — {{ $account->name }}
                </option>
            @endforeach
        </select>
    </div>
    <div class="form-group">
        <label class="form-label" for="location">Location</label>
        <input class="input" type="text" id="location" name="location" value="{{ old('location', $asset?->location) }}">
    </div>
    <div class="form-group">
        <label class="form-label" for="serial_number">Serial Number</label>
        <input class="input" type="text" id="serial_number" name="serial_number" value="{{ old('serial_number', $asset?->serial_number) }}">
    </div>
    <div class="form-group">
        <label class="form-label" for="status">Status</label>
        <input class="input" type="text" id="status" name="status" value="{{ old('status', $asset?->status ?? 'active') }}">
    </div>
    <div class="form-group" style="grid-column: span 2;">
        <label class="form-label" for="notes">Notes</label>
        <textarea class="input" id="notes" name="notes" rows="3">{{ old('notes', $asset?->notes) }}</textarea>
    </div>
</div>
