/******************************************************************************
 *   ______                                                                   *
 *  /       \                                                                 *
 * /$$$$$$  | ________  __    __   ______    ______                           *
 * $$ |__$$ |/        |/  |  /  | /      \  /      \                          *
 * $$    $$ |$$$$$$$$/ $$ |  $$ |/$$$$$$  |/$$$$$$  |                         *
 * $$$$$$$$ |  /  $$/  $$ |  $$ |$$ |  $$/ $$    $$ |                         *
 * $$ |  $$ | /$$$$/__ $$ \__$$ |$$ |      $$$$$$$$/                          *
 * $$ |  $$ |/$$      |$$    $$/ $$ |      $$       |                         *
 * $$/   $$/ $$$$$$$$/  $$$$$$/  $$/        $$$$$$$/                          *
 *                                                                            *
 * @PROJECT    : 3D Preview Extension [Magetop.com]                           *
 * @AUTHOR     : Azure - Developer                                            *
 * @COPYRIGHT  : © 2019  Magetop.com                                          *
 * @LINK       : https://Magetop.com                                          *
 * @CREATED    :  10/01/2022                                                  *
 ******************************************************************************/

define([
    'jquery',
    'Magento_Ui/js/modal/confirm',
    'Magento_Ui/js/modal/modal',
    'Magento_Ui/js/modal/alert',
    'mgt_advance_preview_helper',
    'product_preview_pro',
],function ($,confirmation,modal,alert,helper,productPreviewPro) {
    var customCart = {};
        customCart = {
        version: '2.5',
        place_url: '',
        placeCustomOrder : function() {
            var self = this;
            var url = self.place_url;
            let data = {};
            helper.doRequest(url,data,'advance-preview-loading','',function (response) {
                // console.log(response);
                if(response.status === 'success') {
                    $('.preview-custom-cart').html('');
                    $('.preview-cart-footer').css('display','none');
                    $('.preview-custom-cart-header').css('display','none');
                    $('.preview-custom-cart-footer').css('display','none');
                     window.location.href = $('#txt-home-url').val();
                    // $('#preview-custom-checkout-complete').css('display','block');
                    // self.refreshCart();
                }
            })
        },
        refreshCart : function() {
            var data = {};
            var url = 'http://18.141.220.117/advance_preview/index/testEmail';
            helper.doRequest(url,data,'advance-preview-loading','',function (response) {
                console.log(response);
            })
        },
        isAgreeCondition : function() {
            var rule1 = $('#preview-cart-rule-1').is(":checked");
            // var rule2 = $('#preview-cart-rule-2').is(":checked");
            if(rule1) {
                return true;
            }
            return  false;
        },
        initData : function() {
            var self = this;
            self.place_url = $('#txt-place-custom-order').val();
        },
        init: function () {
            var self = this;
            self.initData();
            $('#btn-custom-place-order').click(function () {

                if(self.isAgreeCondition()) {
                     self.placeCustomOrder();
                }
                else {
                    // console.log("Deo agree");
                    alert({
                        title: $.mage.__('Error'),
                        content: $.mage.__('You must read and agree the terms and conditions before placing an order')
                    })
                }
            })
            /*$('.preview-custom-cart-item-col-1').each(function () {
                var elementId = $(this).attr('id');
                var namePreview = $(this).attr('preview-file-name');
                var light = $(this).attr('preview-light');
                var zoom = $(this).attr('preview-zoom');
                var modelPreview = $(this).attr('model-preview');
                var productId = $(this).attr('product-id');
                light = parseInt(light);
                zoom = parseInt(zoom);



                if(elementId === undefined || namePreview === undefined || light === undefined || productId === undefined || modelPreview === undefined) {
                    console.log("Model not found");
                }
                else {
                    console.log("OK kekeke");
                    var defaultModel = 'product_id_'+productId+'/'+modelPreview+'/'+namePreview;
                    productPreviewPro.productPreviewImage(defaultModel, zoom, light,elementId);
                }

            })*/

        }
    }
    return customCart;
})
