<?php $__template->layout('Layout.main'); ?>

<?php $__template->section('title'); ?>تعديل حساب — <?= e($account['account_code']) ?><?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;">تعديل حساب: <?= e($account['account_code']) ?> — <?= e($account['name_ar']) ?></h3>
    </div>
    <div style="padding:20px;">
        <form method="POST" action="/accounting/chart-of-accounts/<?= (int)$account['id'] ?>">
            <?= csrf_field() ?>
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
                <div>
                    <label class="form-label">كود الحساب</label>
                    <input type="text" class="form-input" value="<?= e($account['account_code']) ?>" disabled dir="ltr" style="background:#F3F4F6;">
                </div>
                <div>
                    <label class="form-label">الحساب الأب</label>
                    <select name="parent_id" class="form-select" disabled>
                        <option value="">— بدون —</option>
                        <?php foreach ($parents as $p): ?>
                            <option value="<?= (int)$p['id'] ?>" <?= (int)$p['id'] === (int)($account['parent_id'] ?? 0) ? 'selected' : '' ?>><?= e($p['account_code']) ?> — <?= e($p['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label class="form-label">اسم الحساب (عربي) <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="name_ar" class="form-input" value="<?= e($account['name_ar']) ?>" required>
                </div>
                <div>
                    <label class="form-label">اسم الحساب (إنجليزي) <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="name_en" class="form-input" value="<?= e($account['name_en']) ?>" required dir="ltr">
                </div>
                <div>
                    <label class="form-label">نوع الحساب <span style="color:#DC2626;">*</span></label>
                    <select name="account_type" class="form-select" required>
                        <option value="asset" <?= $account['account_type'] === 'asset' ? 'selected' : '' ?>>أصول</option>
                        <option value="liability" <?= $account['account_type'] === 'liability' ? 'selected' : '' ?>>خصوم</option>
                        <option value="equity" <?= $account['account_type'] === 'equity' ? 'selected' : '' ?>>حقوق ملكية</option>
                        <option value="revenue" <?= $account['account_type'] === 'revenue' ? 'selected' : '' ?>>إيرادات</option>
                        <option value="expense" <?= $account['account_type'] === 'expense' ? 'selected' : '' ?>>مصروفات</option>
                    </select>
                </div>
                <div>
                    <label class="form-label">طبيعة الحساب <span style="color:#DC2626;">*</span></label>
                    <select name="account_nature" class="form-select" required>
                        <option value="debit" <?= $account['account_nature'] === 'debit' ? 'selected' : '' ?>>مدين</option>
                        <option value="credit" <?= $account['account_nature'] === 'credit' ? 'selected' : '' ?>>دائن</option>
                    </select>
                </div>
                <div>
                    <label class="form-label">مركز التكلفة الافتراضي</label>
                    <select name="cost_center_id" class="form-select">
                        <option value="">— بدون —</option>
                        <?php foreach ($cost_centers as $cc): ?>
                            <option value="<?= (int)$cc['id'] ?>" <?= (int)$cc['id'] === (int)($account['cost_center_id'] ?? 0) ? 'selected' : '' ?>><?= e($cc['code']) ?> — <?= e($cc['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label class="form-label" style="display:flex;align-items:center;gap:8px;">
                        <input type="checkbox" name="is_active" value="1" <?= (int)$account['is_active'] ? 'checked' : '' ?>> حساب نشط
                    </label>
                    <label class="form-label" style="display:flex;align-items:center;gap:8px;margin-top:8px;">
                        <input type="checkbox" name="is_header" value="1" <?= (int)$account['is_header'] ? 'checked' : '' ?>> حساب رئيسي
                    </label>
                </div>
                <div style="grid-column:1/-1;">
                    <label class="form-label">وصف (عربي)</label>
                    <textarea name="description_ar" class="form-textarea" rows="2"><?= e($account['description_ar'] ?? '') ?></textarea>
                </div>
            </div>
            <div style="margin-top:20px;display:flex;gap:8px;">
                <button type="submit" class="btn btn-primary">حفظ التعديلات</button>
                <a href="/accounting/chart-of-accounts" class="btn btn-outline">إلغاء</a>
            </div>
        </form>
    </div>
</div>
<?php $__template->endSection(); ?>
