<div class="container-fluid">
    <div class="container">
        <h3 class="text-center btn-block " style="background-color:#F3920F;color: #fff;padding: 10px 0 3px;margin: 0;border-radius: 5px;text-transform: uppercase;">
            <i> <?= $user->name ?> </:></i> : <small>Product Setup Form </small>
        </h3>
    </div>
    <br>
    <br>
</div>

<div class="container">
    <div class="table-responsive">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>SL</th>
                    <th>name</th>
                    <th>Price</th>
                    <th>Qty</th>
                    <th>Dis.</th>
                    <th>Sizes</th>
                    <th>Colors</th>
                    <th>CTG</th>
                    <th>DHAKA</th>
                    <th>Status</th>
                    <th>Manage</th>
                </tr>
            </thead>

            <tbody class="productData">

            </tbody>


        </table>
    </div>
</div>

<!-- Script start  -->


<script src="https://cdn.ckeditor.com/4.11.3/standard-all/ckeditor.js"></script>
<script src="<?= base_url() . 'app-assets/js/image-compressor.min.js' ?>"></script>


<script>
    $(document).ready(function() {
        AllProducts();

    });


    function AllProducts() {
        var tr = '';
        var sizes = '';
        var colors = '';
        $.ajax({
            method: "get",
            url: "https://myadmin.mali-mart.com/api/all-products",
            data: {
                own_refer_id: '<?= $user->own_refer_id ?>'
            },
            dataType: "json",
            success: function(res) {
                console.log(res);
                console.log(res.length);
                if (res.length) {
                    for (var i = 0; i < res.length; i++) {
                        console.log("Name : ", res[i].name + " Sizes are : " + res[i].sizes);
                        tr += '<tr>' +
                            '<td> ' + (i + 1) + ' </td> ' +
                            '<td> ' + res[i]['name'] + ' </td> ' +
                            '<td> ' + (res[i]['marcent_price'] + res[i]['discount']) + ' Tk </td> ' +
                            '<td> ' + res[i]['quantity'] + ' </td> ' +
                            '<td> ' + res[i]['discount'] + ' </td> ' +
                            '<td> ' + (res[i]['sizes'] != null ? res[i]['sizes'].replace('[', '').replace(']',
                                '') : 'No size') + ' </td> ' +
                            '<td> ' + (res[i]['colors'] != null ? res[i]['colors'].replace('[', '').replace(']',
                                '') : 'No Color') + ' </td> ' +
                            '<td> ' + res[i]['ship_ctg'] + ' Tk</td> ' +
                            '<td> ' + res[i]['ship_dhk'] + ' Tk</td> ' +
                            '<td> ' + res[i]['status'] + '</td> ' +
                            '<td>' +
                            '<a href="<?= base_url() ?>ProductController/editProduct/' + res[i]['id'] + '" ' +
                            'class="btn btn-success btn-small"><i class="fa fa-edit"></i></a> ' +
                            '<a href="https://mali-mart.com/cats/product/' + res[i]['id'] + '" ' +
                            'class="btn btn-primary btn-small"><i class="fa fa-eye"></i></a>' +
                            '</td>' +
                            '</tr>';
                    }
                }

                $(".productData").html(tr);

            }
        });
    }



    //    Image Processing End
</script>

<!-- Script End  -->