<?php
// vars: $cashbox, $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($cashboxes_url ?? '/finance/cashboxes')) ?>">رجوع</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-6">
      <label class="form-label">اسم الخزنة</label>
      <input type="text" class="form-control" name="name" value="<?= e($cashbox['name']) ?>" required>
    </div>
    <div class="col-md-3">
      <label class="form-label">رصيد افتتاحي</label>
      <input type="number" step="0.01" class="form-control" name="opening_balance" value="<?= e($cashbox['opening_balance']) ?>">
    </div>
    <div class="col-md-3">
      <label class="form-label">الحالة</label>
      <select class="form-select" name="is_active">
        <option value="1" <?= ((int)$cashbox['is_active']===1?'selected':'') ?>>نشطة</option>
        <option value="0" <?= ((int)$cashbox['is_active']===0?'selected':'') ?>>غير نشطة</option>
      </select>
    </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($cashboxes_url ?? '/finance/cashboxes')) ?>">إلغاء</a>
  </div>
</form>
