<script src="<?= base_url() ?>assets/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="<?= base_url() ?>assets/jquery.chained.js"></script>
<section class="page-section mb-0 " style="padding-bottom: 60px;">
    <div class="container">

        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <?php if ($this->session->flashdata('konfirmasi')) {
                    ?>
                    <div class="alert alert-warning" role="alert">
                        <small> <span class="glyphicon glyphicon-warning-sign"></span> 
                            <?php
                            echo "<center><i>" . $this->session->flashdata('konfirmasi') . "</i></center>";
                            ?>                        
                        </small>
                    </div>
                    <?php
                }
                ?>
                <?php
                $jmlcart = $this->cart->total_items();
                if ($jmlcart == 0) {
                    ?>
                    <div class="alert alert-warning" role="alert">
                        <small> <span class="glyphicon glyphicon-warning-sign"></span> Maaf anda keranjang belanja anda masih kosong, silahkan melanjutkan belanja anda..</small>
                    </div>
                    <div class="pull-right">
                        <a href="<?= base_url() ?>toko" class="btn btn-mod btn-round btn-large">Lanjut Belanja</a>
                    </div>
                    <?php
                } else {
                    ?>
                    <table class="table table-striped shopping-cart-table">
                        <tr>
                            <th class="hidden-xs">
                                Photo
                            </th>
                            <th>
                                Product
                            </th>
                            <th>
                                Q-ty
                            </th>
                            <th>
                                Berat
                            </th>
                            <th>
                                Total
                            </th>
                            <th>

                            </th>
                        </tr>

                        <?php
                        $tberat = 0;
                        $total = 0;
                        foreach ($this->cart->contents() as $items) {
                            ?>  
                            <tr>
                                <td class="hidden-xs">
                                    <a href=""><img src="<?= base_url() ?>assets/product_image/<?= $items['foto'] ?>" alt="" width="70px"/></a>
                                </td>
                                <td>
                                    <a href="#" title=""><?= $items['name'] ?></a>
                                </td>
                                <td>
                                    <form class="form">
                                        <input type="number" disabled class="input-sm" style="width: 60px;" min="1" max="100" value="<?= $items['qty'] ?>" />
                                    </form>
                                </td>
                                <td>
                                    <a href="#" title=""><?= $items['berat'] ?></a>
                                </td>

                                <td>
                                    <div style="float: left">Rp.</div>
                                    <div style="float: right"><?= number_format($items['total'], 2) ?></div>
                                </td>
                                <td>
                                    <a href="<?= base_url() ?>toko/deleteProduct/<?= $items['rowid'] ?>"><i class="fa fa-times"></i> <span class="hidden-xs">Remove</span></a>
                                </td>
                            </tr>
                            <?php
                            $tberat += $items['berat'];
                            $total += $items['total'];
                        }
                        ?>

                    </table>

                    <hr />

                    <div class="row">
                        <div class="col-sm-8">
                            <div class="lead mt-0 mb-30">
                                Berat Total: <?= $tberat ?> kg <br/>
                                Order Total: <strong>Rp. <?= number_format($total) ?></strong>
                            </div>

                            <div>
                                <a href="#" id="selesai" class="btn btn-mod btn-medium btn-round">Selesai Belanja</a>
                            </div>
                        </div>
                        <div class="col-sm-4 text align-right">

                            <div>
                                <a href="<?= base_url() ?>toko" class="btn btn-mod btn-gray btn-round btn-small">Tambah Barang</a>
                            </div>

                        </div>
                    </div>


                    <?php
                }
                ?>
            </div>
        </div>

    </div>
</section>
<!-- End Section -->
<section class="page-section pt-0 pb-100">
    <div class="container">
        <hr/>
        <div id="formPemesan" style="display: none;">

            <h3 class="small-title font-alt text-center">
                <b>FORM PEMBELIAN</b>
            </h3>

            <form action="#" class="form">
                <div class="col-sm-6">
                    <p class="small-title font-alt">Identitas Pembeli</p>
                    <div class="mb-10">
                        <input placeholder="nama pembeli" class="input-md form-control" autofocus type="text" pattern=".{3,100}">
                    </div>
                    <div class="mb-10">
                        <input placeholder="email pembeli" class="input-md form-control" type="text" pattern=".{3,100}">
                    </div>
                    <div class="mb-10">
                        <input placeholder="no telp/ hp" class="input-md form-control" type="text" pattern=".{3,100}">
                    </div>

                    <div class="mb-10">
                        <textarea class="input-md form-control" placeholder="Alamat Pembeli"></textarea>
                    </div>
                </div>
                <div class="col-sm-6">
                    <p class="small-title font-alt">Pengiriman</p>
                    <div class="mb-10">
                        <input placeholder="nama penerima" class="input-md form-control" type="text" pattern=".{3,100}">
                    </div>

                    <div class="mb-10">
                        <input placeholder="no telp/ hp penerima" class="input-md form-control" type="text" pattern=".{3,100}">
                    </div>

                    <div class="mb-10">
                        <textarea class="input-md form-control" placeholder="Alamat Penerima"></textarea>
                    </div>

                </div>
                <br/>
                <hr/>
                <div style="clear: both"></div>
                <div class="col-sm-6">
                    <p class="small-title font-alt">Pembayaran</p>
                    <div class="mb-10">
                        <select required class="form-control" name="pembayaran_bank">
                            <option value="">-Pilih Pembayaran-</option>
                            <option value="bca">BCA</option>
                            <option value="bri">BRI</option>
                            <option value="mandiri">Mandiri</option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-6">

                    <div class="mb-10">
                        <table class="table">
                            <tbody>
                                <tr>
                                    <td class=""><b>Berat Total: </b></td>
                                    <td class=""> <?= $tberat ?> Kg</td>
                            <input type="hidden" id="brt_ongkir" value="<?= $tberat ?>">
                            </tr>
                            <tr>
                                <td><span class="required">*</span> Provinsi:</td>
                                <td>
                                    <?php
                                    $province_ori = json_decode(GetProv(), TRUE);
                                    echo "<select name='prov_origin' required class='form-control form-control-sm' id='prov_origin'>";
                                    echo "<option value=''>Pilih Provinsi...!!!</option>";
                                    for ($i = 1; $i < count($province_ori['rajaongkir']['results']); $i++) {
                                        echo "<option value='" . $province_ori['rajaongkir']['results'][$i]['province_id'] . "' class='jne tiki pos all' >" . $province_ori['rajaongkir']['results'][$i]['province'] . "</option>";
                                    }
                                    echo "</select>";
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td><span class="required">*</span> Region / State:</td>
                                <td>
                                    <?php
                                    $city_ori = json_decode(GetCity(), TRUE);
                                    echo "<select name='city_origin' required class='form-control form-control-sm' id='city_origin'>";
                                    echo "<option class='' selected>Pilih Kota Asal...!!!</option>";
                                    for ($x = 1; $x < count($city_ori['rajaongkir']['results']); $x++) {
                                        echo "<option value='" . $city_ori['rajaongkir']['results'][$x]['city_id'] . "' class='" . $city_ori['rajaongkir']['results'][$x]['province_id'] . "' >" . $city_ori['rajaongkir']['results'][$x]['type'] . " " . $city_ori['rajaongkir']['results'][$x]['city_name'] . "</option>";
                                    }
                                    echo "</select>";
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td><span class="required" id="postcode-required">*</span> Jasa Ekspedisi:</td>
                                <td>
                                    <select class="form-control" name="courir" id="kurir">
                                        <option value="jne">JNE</option>
                                        <option value="pos">POS</option>
                                        <option value="tiki">TIKI</option>
                                    </select>
                                </td>
                            </tr>

                            </tbody>
                        </table>
                        <input type="button" class="button" id="button-quote" value="Cek Ongkir" onclick="cari_ongkir()">
                        <script>
                            function cari_ongkir() {
                                var kota_tujuan = $('#city_origin').val();
                                var berat = $('#brt_ongkir').val();
                                var kurir = $('#kurir').val();
                                $('#loading_ongkir').show();

                                if (kota_tujuan != "" || berat != "" || kurir != "") {
                                    $.ajax({
                                        type: "POST",
                                        url: "<?= base_url() ?>toko/myOngkir",
                                        data: "city_destination=" + kota_tujuan + "&berat=" + berat + "&kurir=" + kurir,
                                        success: function(data) {
                                            $('#loading_ongkir').fadeOut();
                                            $("#show_ongkir").html(data);
                                        }
                                    });
                                } else {
                                    alert("isi kota tujuan dan kurir yang digunakan..");
                                }
                            }
                        </script>
                        <div id="loading_ongkir" style="display: none;">
                            <i class="fa fa-refresh fa-spin fa-3x fa-fw"></i>
                            <span class="sr-only">Loading...</span>
                        </div>
                        <div id="show_ongkir">

                        </div>
                    </div>
                </div>
                <div style="clear: both"></div>
                <hr/>
                <div class="cart-total">
                    <table id="total">
                        <tbody>
                            <tr>
                                <td><b>Berat Total:</b></td>
                                <td><?= $tberat ?> Kg</td>
                            </tr>
                            <tr>
                                <td><b>Total Harga:</b></td>
                                <td>Rp. <?= number_format($total) ?></td>
                            </tr>
                            <tr>
                                <td><b>Jasa Pengiriman:</b></td>
                                <td id="pengiriman_by">Rp. </td>
                            </tr>
                            <tr>
                                <td><b>Total Pembayaran:</b></td>
                                <td><b style="font-size: 14px" id="totals"></b></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div style="clear: both"></div>
                <hr/>
                <div class="pull-right">
                    <button type="submit"  class="btn btn-mod btn-medium btn-round">
                        BELI SEKARANG
                    </button>

                </div>
            </form>

        </div>



    </div>
</section>
<br/>
<br/>
<script>
    $(document).ready(function() {
        $("#selesai").click(function() {
            $("#formPemesan").toggle(1000);
            return false;
        });
    });
</script>
<script>
    $('#city_origin').chained('#prov_origin');
    $('#city_destination').chained('#prov_destination');
    $(".alert").alert();
</script>