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

<?php $__template->section('title'); ?>حساب جديد<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;">إضافة حساب جديد لدليل الحسابات</h3>
    </div>
    <div style="padding:20px;">
        <form method="POST" action="/accounting/chart-of-accounts">
            <?= csrf_field() ?>
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
                <div>
                    <label class="form-label">كود الحساب <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="account_code" class="form-input" placeholder="مثال: 1101" required dir="ltr">
                </div>
                <div>
                    <label class="form-label">الحساب الأب</label>
                    <select name="parent_id" class="form-select">
                        <option value="">— بدون (حساب رئيسي) —</option>
                        <?php foreach ($parents as $p): ?>
                            <option value="<?= (int)$p['id'] ?>"><?= 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" required>
                </div>
                <div>
                    <label class="form-label">اسم الحساب (إنجليزي) <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="name_en" class="form-input" 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="">— اختر —</option>
                        <option value="asset">أصول</option>
                        <option value="liability">خصوم</option>
                        <option value="equity">حقوق ملكية</option>
                        <option value="revenue">إيرادات</option>
                        <option value="expense">مصروفات</option>
                    </select>
                </div>
                <div>
                    <label class="form-label">طبيعة الحساب <span style="color:#DC2626;">*</span></label>
                    <select name="account_nature" class="form-select" required>
                        <option value="">— اختر —</option>
                        <option value="debit">مدين</option>
                        <option value="credit">دائن</option>
                    </select>
                </div>
                <div>
                    <label class="form-label">رصيد افتتاحي</label>
                    <input type="number" name="opening_balance" class="form-input" value="0.00" step="0.01" dir="ltr">
                </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'] ?>"><?= 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_header" value="1"> حساب رئيسي (لا يُرحّل إليه)
                    </label>
                </div>
                <div style="grid-column:1/-1;">
                    <label class="form-label">وصف (عربي)</label>
                    <textarea name="description_ar" class="form-textarea" rows="2"></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(); ?>
