<link rel="stylesheet" href="//select2.github.io/dist/css/select2.min.css">
<link rel="stylesheet" href="<?= base_url() ?>newassets/backend/select2-bootstrap.css">
<script src="//select2.github.io/dist/js/select2.min.js"></script>
<!-- **********************************************************************************************************************************************************
    MAIN CONTENT
    *********************************************************************************************************************************************************** -->
<!--main content start-->
<section id="main-content">
    <section class="wrapper">
        <div class="row mt">
            <div class="col-lg-12">
                <div class="content-panel">
                    <h4 class="pull-left"><i class="fa fa-angle-right"></i> Data Products</h4>
                    <div class="pull-right" style="padding-right: 10px;">
                        <a href="<?= base_url() ?>admin/product/tambah_data">
                            <button type="button" class="btn btn-primary btn-xs">Insert Data</button>
                        </a>
                    </div>
                    <section id="unseen">
                        <table id="example" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>Products Name</th>
                                    <th>Stock</th>
                                    <th>Cost</th>
                                    <th>Price</th>
                                    <th>Discount</th>
                                    <th>Description</th>
                                    <th>New Product until</th>
                                    <th>Featured</th>
                                    <th>Active</th>
                                    <th style="width: 10%">&nbsp;</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($data_product->num_rows() == 0) {
                                    echo "<tr><td colspan='7'>Data Belum Ada</td></tr>";
                                } else {
                                    foreach ($data_product->result() as $pro) {
                                        ?>
                                        <tr>
                                            <td><?= $pro->product_name ?></td>
                                            <td><?= $pro->stock ?></td>
                                            <td><?= $pro->cost ?></td>
                                            <td><?= $pro->price ?></td>
                                            <td><?= $pro->discount ?></td>
                                            <td><?= $pro->description ?></td>
                                            <td><?= DateToIndo($pro->new) ?>
                                                <?php
                                                if ($pro->new > date("Y-m-d")) {
                                                    echo "";
                                                } else {
                                                    echo "<font color='red' size='3'><b>*</b></font>";
                                                }
                                                ?>
                                            </td>
                                            <td><?= $pro->featured ?></td>
                                            <td><?= $pro->status ?></td>
                                            <td width="12%">
                                                <div class="btn-group">
                                                    <button type="button" class="btn btn-theme dropdown-toggle" data-toggle="dropdown">
                                                        Action <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu" role="menu">
                                                        <li><a href="#" data-toggle="modal" data-target=".kategori" onclick="return setkategori('<?= $pro->id ?>')" >Set Tag Kategori</a></li>
                                                        <li><a href="#" data-toggle="modal" data-target=".stock" onclick="return setStok('<?= $pro->id ?>')" >Set Stock</a></li>
                                                        <li>
                                                            <?php
                                                            if ($pro->status == "Yes") {
                                                                ?>
                                                                <a href="<?= base_url() ?>admin/product/changeNonActive/<?= $pro->id ?>">Change NonActive</a>
                                                                <?php
                                                            } else {
                                                                ?>
                                                                <a href="<?= base_url() ?>admin/product/changeActive/<?= $pro->id ?>">Change Active</a>
                                                                <?php
                                                            }
                                                            ?>
                                                        </li>
                                                        <li>
                                                            <?php
                                                            if ($pro->featured == "Yes") {
                                                                ?>
                                                                <a href="<?= base_url() ?>admin/product/changeNonFeatured/<?= $pro->id ?>">Change NonFeatured</a>
                                                                <?php
                                                            } else {
                                                                ?>
                                                                <a href="<?= base_url() ?>admin/product/changeFeatured/<?= $pro->id ?>">Change Featured</a>
                                                                <?php
                                                            }
                                                            ?>
                                                        </li>
                                                        <li>
                                                            <?php
                                                            if ($pro->new > date("Y-m-d")) {
                                                                ?>
                                                                <a href="<?= base_url() ?>admin/product/nonAktifNew/<?= $pro->id ?>" >NonAktif New</a>
                                                                <?php
                                                            } else {
                                                                ?>
                                                                <a href="#" data-toggle="modal" data-target=".new" onclick="return setNew('<?= $pro->id ?>')" >Set New Product</a>
                                                                <?php
                                                            }
                                                            ?>                                                            
                                                        </li>
                                                        <li><a href="#" data-toggle="modal" data-target=".discount" onclick="return setDiskon('<?= $pro->id ?>')" >Set Discount</a></li>

                                                        <li><a href="<?= base_url() ?>admin/product/edit_data/<?= $pro->id ?>">Edit Data</a></li>
                                                        <li><a href="<?= base_url() ?>admin/product/deleteData/<?= $pro->id ?>">Delete</a></li>
                                                    </ul>
                                                </div>
                                            </td>
                                        </tr>
                                        <?php
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                        <div class="modal fade discount" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" id="modal">
                            <div class="modal-content">
                                <form method="post" action="<?= base_url() ?>admin/product/setDiscount">
                                    <div class="modal-header">Change Discount</div>
                                    <div class="modal-body">
                                        <input type="hidden" name="id_product" id="id_product">
                                        <div class="form-group">
                                            <label class="col-sm-2 col-sm-2 control-label">Discount</label>
                                            <div class="col-sm-10">
                                                <input type="text" class="form-control" value="" name="diskon">
                                            </div>
                                        </div>
                                        <br>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-primary">Simpan</button>
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="modal fade new" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" id="modal">
                            <div class="modal-content">
                                <form method="post" action="<?= base_url() ?>admin/product/setNewProduct">
                                    <div class="modal-header">Set New Product</div>
                                    <div class="modal-body">
                                        <input type="hidden" name="id_product" id="id_productNew">
                                        <div class="form-group">
                                            <label class="col-sm-2 col-sm-2 control-label">New Product Until</label>
                                            <div class="col-sm-10">
                                                <input type="date" class="form-control" value="" name="new">
                                            </div>
                                        </div>
                                        <br>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-primary">Simpan</button>
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                    </div>

                                </form>

                            </div>
                        </div>
                        <div class="modal fade stock" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" id="modal">
                            <div class="modal-content">
                                <form method="post" action="<?= base_url() ?>admin/product/setStockProduct">
                                    <div class="modal-header">Set New Product</div>
                                    <div class="modal-body">
                                        <input type="hidden" name="id_product" id="id_productStok">
                                        <div class="form-group">
                                            <label class="col-sm-2 col-sm-2 control-label">Stock</label>
                                            <div class="col-sm-10">
                                                <input type="number" class="form-control" value="" name="stok">
                                            </div>
                                        </div>
                                        <br>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-primary">Simpan</button>
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                    </div>

                                </form>

                            </div>
                        </div>

                        <div class="modal fade kategori" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" id="modal">
                            <div class="modal-content">
                                <form method="post" action="<?= base_url() ?>admin/product/set_kategori">
                                    <div class="modal-header">Set Kategori</div>
                                    <div class="modal-body">
                                        <input type="hidden" name="id_product" id="id_productCt">
                                        <div class="form-group">
                                            <label class="col-sm-2 col-sm-2 control-label">Kategori</label>
                                            <div class="col-sm-10">
                                                <select name="tagline[]" style="width: 100%" id="multiple" class="form-control select2-multiple" multiple>
                                                    <option value="">-</option> 
                                                    <?php
                                                    foreach ($kategori->result() as $ktg) {
                                                        ?>
                                                        <option value="<?= $ktg->id ?>"><?= $ktg->name ?></option>
                                                        <?php
                                                    }
                                                    ?>
                                                </select>
                                            </div>
                                        </div>
                                        <br>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-primary">Simpan</button>
                                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                    </div>

                                </form>

                            </div>
                        </div>
                    </section>
                    <font color="red" size="3"><b>*</b></font> Expired New Date
                    <div style="clear: both"></div>
                </div>
            </div>
        </div><!--row -->
    </section>
</section>
<script>
    function setDiskon(id_product) {
        $("#id_product").val(id_product);
    }
    function setNew(id_product) {
        $("#id_productNew").val(id_product);
    }
    function setStok(id_product) {
        $("#id_productStok").val(id_product);
    }
    function setkategori(id_product) {
        $("#id_productCt").val(id_product);
    }
    

    $(".select2, .select2-multiple").select2({
    });

</script>
