<?php echo $header; $itemIndex=1;?>
<script>
    let items=[];
function dataLayerItemPush(eventName, items) {
let params = {
            "event": eventName,
            "ecommerce": {
                "checkout": {
                    "actionField": {
                        "step": 1,
                        "option": "Cart"
                    },
                    "items": items
                }
            }
        };
window.dataLayer.push(params);
    //console.log('>>>['+eventName+']>>> items 0 name:'+items[0].item_name);
        //if (eventName=='remove_from_cart') {alert(1)}
    }
</script>
<style>
    {margin: 0 !important;}
</style>
<script>
    let dataLayerProducts = [];
window.dataLayer.push({
        "event": "situation",
        "pageType": "cart",
        "siteServer": "s1",
        "userSituation": "<?=$dataLayer['userType']?>",
        "userId": "<?=$dataLayer['customer_id']?>",
        "userHashedEmail": "<?=$dataLayer['emailHash']?>",
        "breadcrumb": "Anasayfa / Sepet"
    });
</script>
<style>
.bread-desk {
    margin-top:60px
}
@media (max-width: 768px) {
.bread-desk {
    margin-top:5px
}
}
</style>
<div class="container-fluid p-0 bread_backg bread-desk">
  <div class="container">
      <ul class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
        <?php } ?>
      </ul>
  </div>
</div>
<div class="container">
    <?php if ($attention) { ?>
    <div class="alert alert-info"><i class="fa fa-info-circle"></i> <?php echo $attention; ?>
        <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <?php if ($success) { ?>
    <div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
        <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <?php if ($error_warning) { ?>
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
        <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <?php if (isset($error_checkout)) { ?>
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_checkout; ?>
        <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <div class="row"><?php echo $column_left; ?>
        <?php if ($column_left && $column_right) { ?>
        <?php $class = 'col-sm-6'; ?>
        <?php } elseif ($column_left || $column_right) { ?>
        <?php $class = 'col-sm-9'; ?>
        <?php } else { ?>
        <?php $class = 'col-sm-12'; ?>
        <?php } ?>
        <div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
            <h1><?php echo $heading_title; ?>
                <?php if ($weight) { ?>
                &nbsp;(<?php echo $weight; ?>)
                <?php } ?>
            </h1>
            <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
                <div class="table">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <td class="text-left"></td>
                            <?php if(1==2){ ?>
                            <td class="text-center"><?php echo $column_image; ?></td>
                            <?php } ?>
                            <td class="text-center"><?php echo $column_customer_order_image; ?></td>
                            <td class="text-left"><?php echo $column_name; ?></td>
                            <td class="text-right"><?php echo $column_total; ?></td>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($products as $index=>$product) { ?>
                        <?php if (!in_array($product['product_id'], $gift_products)) { ?>
                        <tr>
                            <td class="text-left">
                                <div class="input-group btn-block" style="max-width: 200px;">
                            <span class="input-group-btn">
                                 <script>
                                    <?php
                                        $_productName = $product["name"];
                                    if (strpos($_productName, '<br>') !== false) {
                                        $_productName = explode('<br>',$_productName)[0];
                                    }
                                        ?>
                                        let item<?=$product['product_id'].'_'.$itemIndex?> = {
                                        "item_name": "<?=$_productName?>",
                                        "item_id": "<?=$product["product_id"]?>",
                                        "price": "<?=strtr($product['price'], [','=>'.', '₺'=>''])?>",
                                        "item_brand": "<?=$product["category_brands"]?>",
                                        "item_category": "<?=$product["breadcrumb1"].' / '.$product["breadcrumb2"].' / '.$product["breadcrumb3"]?>",
                                        "item_variant": "<?=$product["model"]?>",
                                        "item_list_name": "<?=$product["category_name"]?>",
                                        "quantity":"<?=$product["quantity"]?>",
                                        "index": "<?=$itemIndex?>",
                                    };
                                    items.push(item<?=$product['product_id'].'_'.$itemIndex?>);
                                </script>
                                <button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>"
                                        class="btn btn-danger btn-danger-optimize" onclick="dataLayerItemPush('remove_from_cart', [item<?=$product['product_id'].'_'.$itemIndex?>]); cart.remove('<?php echo $product['cart_id']; ?>')">
                                    <i class="fa fa-times-circle"></i>
                                </button>
                                </span>
                            </div>
                            </td>
                            <?php if(1==2){ ?>
                            <td class="text-center"><?php if ($product['thumb']) { ?>
                                <a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>"
                                                                               alt="<?php echo $product['name']; ?>"
                                                                               title="<?php echo $product['name']; ?>"
                                                                               class="img-thumbnail"/></a>
                                <?php } ?></td>
                            <?php } ?>
                            <td class="text-left">
                                <?php if($product['customcase_image']){ ?>
                                <?php if((int)$product['product_type']!=11){?>
                                <img width="50" height="80" src="<?php echo $product['case_image']; ?>" alt="Frame"
                                     style="position:absolute;">
                                <?php } ?>
                                <!--<img width="49" height="80" src="<?php echo $product['customcase_image']; ?>" alt="">-->
                                <img width="<?php echo (int)$product['product_type']==11?52:49;?>" height="<?php echo (int)$product['product_type']==11?60:80;?>" src="<?php echo $product['customcase_image']; ?>" style="margin-left:<?php echo (int)$product['product_type']==11?'7px':'0px';?>" alt="">

                                <?php }else if($product['customer_order_image']){ ?>
                                <a target="_blank" href="<?php echo $product['customer_order_image']; ?>"><img
                                            src="<?php echo $product['customer_order_image']; ?>" width="60"></a>
                                <?php }else{ ?>
                                .
                                <?php } ?>
                            </td>
                            <td class="text-left">
                                <?php if($product['product_id'] != '5134'){ ?>
                                    <b class="fs-16"><?= str_replace ('Telefon Kılıfı', '', $product ['category_brands']); ?>/</b>
                                    <b class="fs-16"><?= str_replace ('Telefon Kılıfı', '', $product ['category_name']); ?></b>
                                    <br />
                                <?php } ?>
                                <?php if($product['customcase_image']){ ?>
                                <a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?><br><?php echo $product['product_id']; ?>-<?php echo $product['model']; ?></a>
                                <?php }else{ ?>
                                <a href="<?php echo $product['href']; ?>"> <?= $product['name']; ?><br><?php echo $product['product_id']; ?>-<?php echo $product['model']; ?></a>
                                <ul>
                                    <?php foreach($product['sub_products_as_options'] as $s_product){ ?>
                                    <li>
                                        <img src="<?=$s_product['thumb'];?>" width="30">
                                        <?=$s_product['name'];?><br><?php echo $product['product_id']; ?>-<?php echo $product['model']; ?>
                                    </li>
                                    <?php } ?>
                                </ul>
                                <?php  } ?>
<?php if (!$product['stock']) { ?>
                                <span class="text-danger">***</span>
                                <?php } ?>
                                <?php if ($product['option']) { ?>
                                <?php foreach ($product['option'] as $option) { ?>
                                <br/>
                                <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?></small>
                                <?php } ?>
                                <?php } ?>
                                <?php if ($product['reward']) { ?>
                                <br/>
                                <small><?php echo $product['reward']; ?></small>
                                <?php } ?>
                                <?php if ($product['recurring']) { ?>
                                <br/>
                                <span class="label label-info"><?php echo $text_recurring_item; ?></span>
                                <small><?php echo $product['recurring']; ?></small>
                                <?php } ?></td>
                            <td class="text-right"><?php echo $product['total']; ?></td>
                        </tr>
<?php $itemIndex++; ?>
<?php } ?>
                        <?php foreach ($vouchers as $voucher) { ?>
                        <tr>
                            <td></td>
                            <td class="text-left"><?php echo $voucher['description']; ?></td>
                            <td class="text-left"></td>
                            <td class="text-left">
                                <div class="input-group btn-block" style="max-width: 200px;">
                                    <input type="text" name="" value="1" size="1" disabled="disabled"
                                           class="form-control"/>
                                    <span class="input-group-btn">
                                    <button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>"
                                            class="btn btn-danger" onclick="voucher.remove('<?php echo $voucher[';key;']; ?>';)"><i
                                                class="fa fa-times-circle"></i></button>
                                    </span></div>
                            </td>
                            <td class="text-right"><?php echo $voucher['amount']; ?></td>
                            <td class="text-right"><?php echo $voucher['amount']; ?></td>
                        </tr>
                        <?php } ?>
                        <?php } ?>
                        </tbody>
                    </table>
                </div>
            </form>
            <br/>
                        <div class="buttons clearfix">
                            <?php if($empty_cart_button){ ?>
                            <div class="hidden">
                                <a class="btn btn-danger" onclick="emptyCart()">Sepeti Boşalt</a>
                            </div>
                            <?php } ?>
                <div class="text-center">

                    <br>
                    <style>
                    .btn-cart-optimize{
                        background-color: #28c328;
                        border-color: #28c328;
                        font-size: 20px;
                        padding: 13px 20px;
                        margin-bottom:10px;
                    }
                    .btn-danger-optimize{
                        border: none;
                        background: none;
                        color: red;
                    }
                    </style>
                    <!--<a href="<?php echo $checkout; ?>" class="btn btn-primary btn-cart-optimize" style="width:100%" onclick="dataLayerButtonClick('<?=$button_checkout?>')"><?=$button_checkout?></a>-->
                    <a class="btn btn-primary btn-cart-optimize" style="width:100%" onclick="prepareCheckout()"><?=$button_checkout?></a>
                    <br />
                    <span class="text_or">Veya</span>
                    <a href="/" class="btn btn-link" onclick="dataLayerButtonClick('Veya Alışverişe Devam Et!')">Veya Alışverişe Devam Et!</a>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-4 col-sm-offset-8">
                    <table class="table table-bordered">
                        <?php foreach ($totals as $total) { ?>
                        <tr>
                            <td class="text-right"><strong><?php echo $total['title']; ?>:</strong></td>
                            <td class="text-right"><?php echo $total['text']; ?></td>
                        </tr>
                        <?php } ?>
                    </table>
                </div>
            </div>

            <?php echo $content_bottom; ?></div>
        <?php echo $column_right; ?></div>
</div>
    <div class="modal fade" id="cart-check-modal">
    <div class="modal-dialog">
        <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title text-center"><b>TELEFON MODELİ KONTROLÜ</b></h4>
        </div>
        <div class="modal-body">
                            <p class="text-center">Siparişini Tamamlamadan Önce Son Bir Kontrol <i class="fa fa-hand-o-down" aria-hidden="true"></i></p>
                            <table class="table table-bordered">
                            <tbody>
                                
                            <?php 
                            $itemIndex=1;
                            foreach ($products as $product) { ?>
                            <?php if (!in_array($product['product_id'], $gift_products)) { ?>
                            <tr>
                                <?php if(1==2){ ?>
                                <td class="text-center"><?php if ($product['thumb']) { ?>
                                    <a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>"
                                                                                alt="<?php echo $product['name']; ?>"
                                                                                title="<?php echo $product['name']; ?>"
                                                                                class="img-thumbnail"/></a>
                                    <?php } ?></td>
                                <?php } ?>
                                    <td class="text-left">
                                    <?php if($product['customcase_image']){ ?>
                                    <?php if((int)$product['product_type']!=11){?>
                                    <img width="50" height="80" src="<?php echo $product['case_image']; ?>" alt="Frame"
                                        style="position:absolute;">
                                    <?php } ?>
                                    <!--<img width="49" height="80" src="<?php echo $product['customcase_image']; ?>" alt="">-->
                                    <img width="<?php echo (int)$product['product_type']==11?52:49;?>" height="<?php echo (int)$product['product_type']==11?60:80;?>" src="<?php echo $product['customcase_image']; ?>" style="margin-left:<?php echo (int)$product['product_type']==11?'7px':'0px';?>" alt="">

                                    <?php }else if($product['customer_order_image']){ ?>
                                    <a target="_blank" href="<?php echo $product['customer_order_image']; ?>"><img
                                                src="<?php echo $product['customer_order_image']; ?>" width="60"></a>
                                    <?php }else{ ?>
                                    .
                                    <?php } ?>
                                </td>
                                <td class="text-left">
                                    <?php if($product['product_id'] != '5134'){ ?>
                                        <!--<b class="fs-16"><?= str_replace ('Telefon Kılıfı', '', $product ['category_brands']); ?>/</b>-->
                                        <b class="fs-16"><?= str_replace ('Telefon Kılıfı', '', $product ['category_name']); ?></b>
                                        <br />
                                    <?php } ?>
                                <?php if (!$product['stock']) { ?>
                                    <span class="text-danger">***</span>
                                    <?php } ?>
                                    <?php if ($product['option']) { ?>
                                    <?php foreach ($product['option'] as $option) { ?>
                                    <br/>
                                    <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?></small>
                                    <?php } ?>
                                    <?php } ?>
                                    <?php if ($product['reward']) { ?>
                                    <br/>
                                    <small><?php echo $product['reward']; ?></small>
                                    <?php } ?>
                                    <?php if ($product['recurring']) { ?>
                                    <br/>
                                    <span class="label label-info"><?php echo $text_recurring_item; ?></span>
                                    <small><?php echo $product['recurring']; ?></small>
                                    <?php } ?></td>
                                <td>
                                <div class="cart-check-icon-wrapper" id="check-icon-wrapper-<?= $product['cart_id'] ?>">
                                    <i class="fa fa-check cart-check-icon" aria-hidden="true"></i>
                                </div>
                                    <a class="btn btn-success" style="width:100%; margin-bottom: 1rem" id="check-button-<?= $product['cart_id'] ?>" onclick="checkProduct(<?= $product['product_id'] ?>, <?=$product['cart_id'] ?>)">
                                        <i class="fa fa-check-circle text-white" aria-hidden="true"></i> 
                                        Onayla
                                    </a>
                                    <a class="btn btn-warning" style="width:100%;" id="change-button-<?= $product['cart_id'] ?>" onclick="changeProduct(<?= $product['product_id']?>, <?= $product['cart_id'] ?>, <?= $itemIndex ?>)">
                                        <i class="fa fa-refresh text-white" aria-hidden="true"></i> 
                                        Değiştir
                                    </a>
                                    <span id="change-alert-text-<?= $product['cart_id'] ?>" class="change-alert-text text-danger">*Değiştir butonuna bastığınızda ürün sepetten silinir</span>
                                </td>
                            </tr>
                        <?php $itemIndex++; ?>
                        <?php } ?>
                            <?php foreach ($vouchers as $voucher) { ?>
                            <tr>
                                <td></td>
                                <td class="text-left"><?php echo $voucher['description']; ?></td>
                                <td class="text-left"></td>
                                <td class="text-left">
                                    <div class="input-group btn-block" style="max-width: 200px;">
                                        <input type="text" name="" value="1" size="1" disabled="disabled"
                                            class="form-control"/>
                                        <span class="input-group-btn">
                                        <button type="button" data-toggle="tooltip" title="<?php echo $button_remove; ?>"
                                                class="btn btn-danger" onclick="voucher.remove('<?php echo $voucher[';key;']; ?>';)"><i
                                                    class="fa fa-times-circle"></i></button>
                                        </span></div>
                                </td>
                                <td class="text-right"><?php echo $voucher['amount']; ?></td>
                                <td class="text-right"><?php echo $voucher['amount']; ?></td>
                            </tr>
                            <?php } ?>
                            <?php } ?>
                            </tbody>
                        </table>
        </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

<style>
    .cart-check-icon-wrapper {
        align-items: center;
        justify-content: center;
        min-height: 80px;
        display: none;
    }
    .cart-check-icon {
        font-size: 30px;
        color: #fff;
        padding: 10px;
        background: #28c328;
        border-radius: 50%;
    }
    .change-alert-text {
        display: flex;
        justify-content: center;
        margin-top: 5px;
        font-weight: 500;
        font-size: 10px;
    }
</style>
<script>
var checkCount = 0;

function prepareCheckout() {
    $('#cart-check-modal').modal('show')
}

function checkProduct(productID, cartID) {
    $('#check-icon-wrapper-'+cartID).css('display','flex');
    $('#check-button-'+cartID).css('display','none');
    $('#change-button-'+cartID).css('display','none');
    $('#change-alert-text-'+cartID).css('display','none');

    checkCount++;
    validateChecks();
}

function validateChecks() {
    if(checkCount == items.length) {
        location = 'checkout';
    }
}

function changeProduct(productID, cartID, itemIndex){
    dataLayerItemPush('remove_from_cart', ['item' + productID +'_' + itemIndex]); 
    $.ajax({
        url: 'index.php?route=checkout/cart/remove',
        type: 'post',
        data: 'key=' + cartID,
        dataType: 'json',
        success: function(json) {
            location = 'index.php?route=product/product&product_id='+productID;
        }
    });
}

    function emptyCart() {
        var conf = confirm("Sepetinizdeki tüm ürünler silinecektir. Onaylıyor musunuz?");

        if(conf){
            <?php foreach ($products as $product) { ?>
                //console.log('<?=$product["cart_id"]?>');
                cart.remove('<?=$product["cart_id"]?>');
            <?php } ?>

            location.reload();
        }
    }

</script>


<script>
    dataLayerItemPush('begin_checkout', items)

</script>


<?php
if($CretioOneTag_status)
{
?>
<!-- Criteo Basket/Cart Tag -->
<script type="text/javascript" src="//static.criteo.net/js/ld/ld.js" async="true"></script>
<script type="text/javascript">
window.criteo_q = window.criteo_q || [];
var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";
window.criteo_q.push(
 { event: "setAccount", account: '<?php echo $CretioOneTag_id ?>'}, // You should never update this line
 { event: "setEmail", email: "" }, // Can be an empty string
 { event: "setSiteType", type: deviceType},
 { event: "viewBasket", item: [
   <?php
foreach ($products as $product) {
    ?>
        {id: "<?php echo $product['product_id'] ?>", price: <?php echo str_replace(',','.',str_replace('₺','',$product['price'])) ?>, quantity: <?php echo $product['quantity'] ?>},
    <?php
}
?>
]}
);
</script>
<!-- END Criteo Basket/Cart Tag -->
<?php
}
?>
<?php echo $footer; ?>

<link rel="stylesheet" href="/catalog/view/theme/deercase/stylesheet/sweet-modal2/jquery.sweet-modal.css" />
<script defer src="/catalog/view/theme/deercase/stylesheet/sweet-modal2/jquery.sweet-modal.js"></script>