<?= $this->extend('layout/management_layout') ?>
<?= $this->section('content') ?>

<div class="container my-4">
  <h3 class="mb-3">Audit — <?= esc($item['name']) ?></h3>
  <?= view('partials/flash_messages') ?>

  <div class="alert alert-info">
    <strong>Current On Hand:</strong> <?= (int)$item['quantity'] ?> pcs
  </div>

  <form method="post" action="<?= site_url('inventory/classroom/audit/'.$item['id']) ?>">
    <?= csrf_field() ?>
    <div class="row g-3">
      <div class="col-md-3">
        <label class="form-label">Needs Repair</label>
        <input type="number" min="0" class="form-control" name="needs_repair_qty"
               value="<?= (int)$item['needs_repair_qty'] ?>">
      </div>
      <div class="col-md-3">
        <label class="form-label">Total Loss (Need Replace)</label>
        <input type="number" min="0" class="form-control" name="need_replace_qty"
               value="<?= (int)$item['need_replace_qty'] ?>">
      </div>
      <div class="col-md-3">
        <label class="form-label">Cannot Find</label>
        <input type="number" min="0" class="form-control" name="cannot_find_qty"
               value="<?= (int)$item['cannot_find_qty'] ?>">
      </div>
      <div class="col-md-3">
        <label class="form-label">Derived Good (read-only)</label>
        <input type="number" class="form-control" value="<?= max(0, (int)$item['quantity'] - (int)$item['needs_repair_qty']) ?>" readonly>
        <div class="form-text">Good = On Hand − Needs Repair</div>
      </div>
    </div>

    <div class="mt-3 d-flex gap-2">
      <button class="btn btn-primary">Save Audit</button>
      <a class="btn btn-outline-secondary" href="<?= site_url('inventory/classroom') ?>">Cancel</a>
    </div>
  </form>
</div>

<?= $this->endSection() ?>
