<?php
$account    = $account ?? [];
$glAccounts = $glAccounts ?? [];
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Code <span class="text-danger">*</span></label>
        <input type="text" name="code" class="form-control text-uppercase" maxlength="30"
               value="<?= esc(old('code', $account['code'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Name <span class="text-danger">*</span></label>
        <input type="text" name="name" class="form-control" value="<?= esc(old('name', $account['name'] ?? '')) ?>" required>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Currency</label>
        <input type="text" name="currency" class="form-control text-uppercase" maxlength="10"
               value="<?= esc(old('currency', $account['currency'] ?? 'USD')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">GL Account <span class="text-danger">*</span></label>
        <select name="account_id" class="form-select" required>
            <option value="">— Select account —</option>
            <?php foreach ($glAccounts as $gl): ?>
                <option value="<?= $gl['id'] ?>" <?= (string) old('account_id', $account['account_id'] ?? '') === (string) $gl['id'] ? 'selected' : '' ?>>
                    <?= esc($gl['code'] . ' — ' . $gl['name']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Opening Balance</label>
        <input type="number" name="opening_balance" class="form-control" step="0.01"
               value="<?= esc(old('opening_balance', $account['opening_balance'] ?? '0.00')) ?>">
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Status</label>
        <select name="status" class="form-select">
            <?php foreach (['active', 'inactive'] as $s): ?>
                <option value="<?= $s ?>" <?= old('status', $account['status'] ?? 'active') === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field" style="grid-column: 1 / -1;">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $account['notes'] ?? '')) ?></textarea>
    </div>
</div>
