<?php // vars: $category, $errors, $is_edit ?>
<div class="d-flex justify-content-between align-items-center mb-3">
  <h4 class="mb-0"><?= $is_edit ? 'تعديل مجموعة مصروفات' : 'إضافة مجموعة مصروفات' ?></h4>
  <a class="btn btn-outline-secondary" href="<?= e(url('/finance/expenses/categories')) ?>">رجوع</a>
</div>

<?php if (!empty($errors)): ?>
  <div class="alert alert-danger"><ul class="mb-0"><?php foreach ($errors as $er): ?><li><?= e($er) ?></li><?php endforeach; ?></ul></div>
<?php endif; ?>

<form class="card p-3" method="post">
  <?= csrf_field() ?>
  <div class="row g-3">
    <div class="col-md-5">
      <label class="form-label">اسم المجموعة</label>
      <input type="text" class="form-control" name="name" value="<?= e($category['name']) ?>" required>
    </div>
    <div class="col-md-3">
      <label class="form-label">الكود</label>
      <input type="text" class="form-control" name="code" value="<?= e($category['code']) ?>">
    </div>
    <div class="col-md-2">
      <label class="form-label">الترتيب</label>
      <input type="number" class="form-control" name="sort_order" value="<?= e((string)$category['sort_order']) ?>">
    </div>
    <div class="col-md-2">
      <label class="form-label">الحالة</label>
      <select class="form-select" name="is_active">
        <option value="1" <?= ((int)$category['is_active']===1?'selected':'') ?>>نشطة</option>
        <option value="0" <?= ((int)$category['is_active']===0?'selected':'') ?>>غير نشطة</option>
      </select>
    </div>
    <div class="col-12">
      <label class="form-label">ملاحظات</label>
      <input type="text" class="form-control" name="notes" value="<?= e($category['notes']) ?>">
    </div>
  </div>
  <div class="mt-3 d-flex gap-2">
    <button class="btn btn-primary" type="submit"><i class="fa-solid fa-floppy-disk"></i> حفظ</button>
    <a class="btn btn-outline-secondary" href="<?= e(url('/finance/expenses/categories')) ?>">إلغاء</a>
  </div>
</form>
