<?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;">تعديل: <?= e($center['code']) ?> — <?= e($center['name_ar']) ?></h3>
    </div>
    <div style="padding:20px;">
        <form method="POST" action="/accounting/cost-centers/<?= (int)$center['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($center['code']) ?>" disabled dir="ltr" style="background:#F3F4F6;">
                </div>
                <div>
                    <label class="form-label">النوع <span style="color:#DC2626;">*</span></label>
                    <select name="type" class="form-select" required>
                        <option value="cost_center" <?= $center['type'] === 'cost_center' ? 'selected' : '' ?>>مركز تكلفة</option>
                        <option value="profit_center" <?= $center['type'] === 'profit_center' ? 'selected' : '' ?>>مركز ربحية</option>
                    </select>
                </div>
                <div>
                    <label class="form-label">الاسم (عربي) <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="name_ar" class="form-input" value="<?= e($center['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($center['name_en']) ?>" required dir="ltr">
                </div>
                <div>
                    <label class="form-label">الفرع</label>
                    <select name="branch_id" class="form-select">
                        <option value="">— بدون —</option>
                        <?php foreach ($branches as $b): ?>
                            <option value="<?= (int)$b['id'] ?>" <?= (int)$b['id'] === (int)($center['branch_id'] ?? 0) ? 'selected' : '' ?>><?= e($b['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)$center['is_active'] ? 'checked' : '' ?>> نشط
                    </label>
                </div>
                <div style="grid-column:1/-1;">
                    <label class="form-label">وصف</label>
                    <textarea name="description" class="form-textarea" rows="2"><?= e($center['description'] ?? '') ?></textarea>
                </div>
            </div>
            <div style="margin-top:20px;display:flex;gap:8px;">
                <button type="submit" class="btn btn-primary">حفظ</button>
                <a href="/accounting/cost-centers" class="btn btn-outline">إلغاء</a>
            </div>
        </form>
    </div>
</div>
<?php $__template->endSection(); ?>
