<?php 
    $barang      = $this -> app -> get_barang_detail($id);
    $data_grosir = $this -> app -> get_barang_grosir($id, $satuan);
    $satuan      = $satuan ? $this -> db -> get_where('satuan', ['id' => $satuan]) -> row() : null;
    $satuan      = $satuan ? $satuan -> nama : null;
?>

<?php if($data_grosir) : ?>
    <?php foreach($data_grosir as $grosir) : ?>
        <div class="row mb-3">
            <div class="col-sm-4 mb-2">
                <input type="hidden" name="grosir_id[]" value="<?= $grosir -> id ?>">
                <div class="input-group">
                    <input type="number" 
                            class="form-control nochange" 
                            placeholder="Isi" 
                            value="<?= $grosir -> min ?>"
                            name="min_stock[]" 
                            required
                    >
                    <div class="input-group-text">
                        <?= $satuan ?>
                    </div>
                </div>
            </div>
            <div class="col-sm-8 mb-2">
                <div class="input-group">
                    <input type="text" 
                            class="form-control form_uang" 
                            placeholder="Harga Grosir" 
                            value="<?= form_uang($grosir -> harga) ?>"
                            name="grosir_price[]" 
                            required
                    >
                    <button class="btn btn-danger btn_hps_grosir" data-id="<?= $grosir -> id ?>" data-aksi="1">
                        <i class="fa fa-trash"></i>
                    </button>
                </div>
            </div>
        </div>
    <?php endforeach ?>
<?php else: ?>
    <div class="row mb-3">
        <div class="col-sm-4 mb-2">
            <input type="hidden" name="grosir_id[]" value="0">
            <div class="input-group">
                <input type="number" class="form-control nochange" placeholder="Min" name="min_stock[]" required>
                <div class="input-group-text">
                    <?= $satuan ?>
                </div>
            </div>
        </div>
        <div class="col-sm-8 mb-2">
            <div class="input-group">
                <input type="text" class="form-control form_uang" placeholder="Harga Grosir" name="grosir_price[]" required>
                <button class="btn btn-danger btn_hps_grosir disabled" data-id="0" data-aksi="0">
                    <i class="fa fa-trash"></i>
                </button>
            </div>
        </div>
    </div>
<?php endif ?>

<div class="grosir_data_list d-none">
    <div class="row mb-3">
        <div class="col-sm-4 mb-2">
            <input type="hidden" name="grosir_id[]" value="0">
            <div class="input-group">
                <input type="number" class="form-control nochange" placeholder="Min" name="min_stock[]">
                <div class="input-group-text">
                    <?= $satuan ?>
                </div>
            </div>
        </div>
        <div class="col-sm-8 mb-2">
            <div class="input-group">
                <input type="text" class="form-control form_uang" placeholder="Harga Grosir" name="grosir_price[]">
                <button class="btn btn-danger btn_hps_grosir" data-id="0" data-aksi="1">
                    <i class="fa fa-trash"></i>
                </button>
            </div>
        </div>
    </div>
</div>