<?php // vars: $account, $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($bank_accounts_url ?? '/finance/bank-accounts')) ?>">رجوع</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($account['name']) ?>" required>
    </div>
    <div class="col-md-6">
      <label class="form-label">اسم البنك</label>
      <input type="text" class="form-control" name="bank_name" value="<?= e($account['bank_name']) ?>">
    </div>
    <div class="col-md-4">
      <label class="form-label">رقم الحساب</label>
      <input type="text" class="form-control" name="account_no" value="<?= e($account['account_no']) ?>">
    </div>
    <div class="col-md-4">
      <label class="form-label">IBAN</label>
      <input type="text" class="form-control" name="iban" value="<?= e($account['iban']) ?>">
    </div>
    <div class="col-md-2">
      <label class="form-label">العملة</label>
      <input type="text" class="form-control" name="currency_code" value="<?= e($account['currency_code'] ?: 'EGP') ?>">
    </div>
    <div class="col-md-2">
      <label class="form-label">الحالة</label>
      <select class="form-select" name="is_active">
        <option value="1" <?= ((int)$account['is_active']===1?'selected':'') ?>>نشط</option>
        <option value="0" <?= ((int)$account['is_active']===0?'selected':'') ?>>غير نشط</option>
      </select>
    </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($account['opening_balance']) ?>">
    </div>
    <div class="col-md-9">
      <label class="form-label">ملاحظات</label>
      <input type="text" class="form-control" name="notes" value="<?= e($account['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($bank_accounts_url ?? '/finance/bank-accounts')) ?>">إلغاء</a>
  </div>
</form>
