<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="container mt-4">
    <h4>Edit Produk Keluar</h4>

    <form action="<?= base_url('admin/product_out/update/' . $product['kode']) ?>" method="post">
        <?= csrf_field() ?>
        
        <div class="mb-3">
            <label for="kode" class="form-label">Kode Transaksi</label>
            <input type="text" class="form-control" id="kode" name="kode" value="<?= $product['kode'] ?>" readonly>
        </div>

        <div class="mb-3">
            <label for="item_id" class="form-label">Nama Barang</label>
            <select name="item_id" id="item_id" class="form-control" required>
                <option value="">-- Pilih Barang --</option>
                <?php foreach ($items as $item): ?>
                    <option value="<?= $item['id'] ?>" <?= $item['id'] == $product['item_id'] ? 'selected' : '' ?>>
                        <?= $item['nama'] ?> (<?= $item['barcode'] ?>)
                    </option>
                <?php endforeach; ?>
            </select>
        </div>

        <div class="mb-3">
            <label for="barcode" class="form-label">Barcode</label>
            <input type="text" class="form-control" name="barcode" id="barcode" value="<?= $product['barcode'] ?>" readonly>
        </div>

        <div class="mb-3">
            <label for="gudang_id" class="form-label">Gudang</label>
            <select name="gudang_id" id="gudang_id" class="form-control" required>
                <option value="">-- Pilih Gudang --</option>
                <?php foreach ($gudangs as $gudang): ?>
                    <option value="<?= $gudang['id'] ?>" <?= $gudang['id'] == $product['gudang_id'] ? 'selected' : '' ?>>
                        <?= $gudang['nama'] ?>
                    </option>
                <?php endforeach; ?>
            </select>
        </div>

        <div class="mb-3">
            <label for="qty" class="form-label">Jumlah</label>
            <input type="number" class="form-control" name="qty" id="qty" value="<?= $product['qty'] ?>" required>
        </div>

        <div class="mb-3">
            <label for="tanggal_keluar" class="form-label">Tanggal Keluar</label>
            <input type="datetime-local" class="form-control" name="tanggal_keluar" id="tanggal_keluar" 
            value="<?= date('Y-m-d\TH:i', strtotime($product['tanggal_keluar'])) ?>" required>
        </div>

        <div class="mb-3">
            <label for="keterangan" class="form-label">Keterangan</label>
            <textarea name="keterangan" id="keterangan" class="form-control"><?= $product['keterangan'] ?></textarea>
        </div>

        <button type="submit" class="btn btn-primary">Update</button>
        <a href="<?= base_url('admin/product_out') ?>" class="btn btn-secondary">Batal</a>
    </form>
</div>

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