<?php $this->start('body'); ?>
<?php $f = $this->data['form']; ?>

<div class="d-flex align-items-center justify-content-between mb-3">
  <h5 class="mb-0 fw-semibold"><i class="fas fa-plus me-2 text-muted"></i>Add Vendor</h5>
  <a href="<?= PROOT; ?>Vendors" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-left me-1"></i>Back</a>
</div>

<?= $this->raw('fb_msg'); ?>

<form method="POST" action="<?= PROOT; ?>Vendors/save" class="card border-0 shadow-sm" autocomplete="off">
  <?= csrf_field(); ?>
  <div class="card-body">
    <h6 class="text-uppercase text-muted small mb-3">Identity</h6>
    <div class="row g-3">
      <div class="col-md-8"><label class="form-label">Vendor name <span class="text-danger">*</span></label>
        <input type="text" name="vendor_name" class="form-control" required value="<?= htmlspecialchars($f['vendor_name'] ?? ''); ?>" placeholder="e.g. Puma Energy Tanzania Ltd"></div>
      <div class="col-md-4"><label class="form-label">Category</label>
        <select name="vendor_category" class="form-select">
          <option value="">— select —</option>
          <?php foreach (['fuel_supplier'=>'Fuel supplier','workshop'=>'External workshop','spare_parts'=>'Spare parts','tyres'=>'Tyres','lubricants'=>'Lubricants','insurance'=>'Insurance','landlord'=>'Landlord','utilities'=>'Utilities','telecoms'=>'Telecoms','professional'=>'Professional services','other'=>'Other'] as $k=>$v): ?>
            <option value="<?= $k; ?>" <?= ($f['vendor_category'] ?? '')===$k?'selected':''; ?>><?= $v; ?></option>
          <?php endforeach; ?>
        </select></div>

      <div class="col-md-4"><label class="form-label">TIN</label><input type="text" name="vendor_tin" class="form-control" value="<?= htmlspecialchars($f['vendor_tin'] ?? ''); ?>"></div>
      <div class="col-md-4"><label class="form-label">VRN</label><input type="text" name="vendor_vrn" class="form-control" value="<?= htmlspecialchars($f['vendor_vrn'] ?? ''); ?>"></div>
    </div>

    <hr class="my-4">
    <h6 class="text-uppercase text-muted small mb-3">Contact</h6>
    <div class="row g-3">
      <div class="col-md-4"><label class="form-label">Phone 1</label><input type="text" name="vendor_phone_1" class="form-control" value="<?= htmlspecialchars($f['vendor_phone_1'] ?? ''); ?>"></div>
      <div class="col-md-4"><label class="form-label">Phone 2</label><input type="text" name="vendor_phone_2" class="form-control" value="<?= htmlspecialchars($f['vendor_phone_2'] ?? ''); ?>"></div>
      <div class="col-md-4"><label class="form-label">Email</label><input type="email" name="vendor_email" class="form-control" value="<?= htmlspecialchars($f['vendor_email'] ?? ''); ?>"></div>
      <div class="col-md-8"><label class="form-label">Address</label><input type="text" name="vendor_address" class="form-control" value="<?= htmlspecialchars($f['vendor_address'] ?? ''); ?>"></div>
      <div class="col-md-2"><label class="form-label">PO Box</label><input type="text" name="vendor_po_box" class="form-control" value="<?= htmlspecialchars($f['vendor_po_box'] ?? ''); ?>"></div>
      <div class="col-md-2"><label class="form-label">City</label><input type="text" name="vendor_city" class="form-control" value="<?= htmlspecialchars($f['vendor_city'] ?? ''); ?>"></div>
      <div class="col-md-4"><label class="form-label">Country</label><input type="text" name="vendor_country" class="form-control" value="<?= htmlspecialchars($f['vendor_country'] ?? 'TANZANIA'); ?>"></div>
      <div class="col-md-8"><label class="form-label">Website</label><input type="text" name="vendor_website" class="form-control" value="<?= htmlspecialchars($f['vendor_website'] ?? ''); ?>"></div>
    </div>
  </div>
  <div class="card-footer bg-white d-flex justify-content-end gap-2 py-3">
    <a href="<?= PROOT; ?>Vendors" class="btn btn-outline-secondary">Cancel</a>
    <button class="btn btn-primary"><i class="fas fa-save me-1"></i>Save vendor</button>
  </div>
</form>

<?php $this->end(); ?>
