<?php
// view: pages/suppliers/view
?>
<?php $supplier = $supplier ?? null; ?>

<?php if (!$supplier): ?>
  <div class="alert alert-danger">مورد غير موجود</div>
<?php return; endif; ?>

<div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mb-3">
  <div>
    <h4 class="mb-0">تفاصيل المورد</h4>
    <div class="text-muted small"><?= e((string)($supplier['code'] ?? '')) ?></div>
  </div>

  <div class="d-flex gap-2">
    <a class="btn btn-outline-secondary" href="<?= e(url('/parties/suppliers')) ?>">
      <i class="fa-solid fa-arrow-right me-1"></i>رجوع
    </a>
    <a class="btn btn-primary" target="_blank" href="<?= e(url('/prints/supplier')) ?>?id=<?= (int)$supplier['id'] ?>">
      🖨 طباعة
    </a>
    <?php if (can('suppliers.edit')): ?>
      <a class="btn btn-dark" href="<?= e(url('/parties/suppliers')) ?>?edit=<?= (int)$supplier['id'] ?>">
        تعديل
      </a>
    <?php endif; ?>
  </div>
</div>

<div class="row g-3">
  <div class="col-12">
    <div class="card shadow-sm" style="border-radius: 16px;">
      <div class="card-body">
        <div class="row g-3">
          <div class="col-lg-4">
            <div class="text-muted small">اسم المورد</div>
            <div class="fw-bold fs-5"><?= e((string)$supplier['name']) ?></div>
          </div>

          <div class="col-lg-4">
            <div class="text-muted small">الأدوار</div>
            <div class="fw-bold">
              <?php if ((int)($supplier['is_supplier'] ?? 0) === 1): ?>
                <span class="badge text-bg-primary">مورد</span>
              <?php endif; ?>
              <?php if ((int)($supplier['is_customer'] ?? 0) === 1): ?>
                <span class="badge text-bg-secondary">عميل</span>
              <?php endif; ?>
            </div>
          </div>
          <div class="col-lg-2">
            <div class="text-muted small">الحالة</div>
            <?php if ((int)$supplier['is_active'] === 1): ?>
              <span class="badge text-bg-success">نشط</span>
            <?php else: ?>
              <span class="badge text-bg-secondary">موقوف</span>
            <?php endif; ?>
          </div>
          <div class="col-lg-3">
            <div class="text-muted small">هاتف</div>
            <div class="fw-bold"><?= e((string)($supplier['phone'] ?? '-')) ?></div>
          </div>
          <div class="col-lg-3">
            <div class="text-muted small">هاتف 2</div>
            <div class="fw-bold"><?= e((string)($supplier['phone2'] ?? '-')) ?></div>
          </div>

          <div class="col-lg-4">
            <div class="text-muted small">البريد</div>
            <div class="fw-bold"><?= e((string)($supplier['email'] ?? '-')) ?></div>
          </div>
          <div class="col-lg-4">
            <div class="text-muted small">رقم ضريبي</div>
            <div class="fw-bold"><?= e((string)($supplier['tax_no'] ?? '-')) ?></div>
          </div>
          <div class="col-lg-4">
            <div class="text-muted small">رصيد افتتاحي</div>
            <div class="fw-bold"><?= format_money($supplier['opening_balance'] ?? 0) ?></div>
          </div>

          <div class="col-12">
            <div class="text-muted small">العنوان</div>
            <div class="fw-bold"><?= e((string)($supplier['address'] ?? '-')) ?></div>
          </div>

          <div class="col-12">
            <div class="text-muted small">ملاحظات</div>
            <div class="fw-bold"><?= e((string)($supplier['notes'] ?? '-')) ?></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
