/**
 * Created by User on 15.03.2018.
 */
var GtagManager = {
    selectors: {},
    init: function () {
        this.getSelectors();
        this.addProduct();
        this.checkoutProgress();
    },
    getSelectors: function () {
        return this.selectors = {
            'add_product': $('p#add_to_cart'),
            'checkout_progress': $('input[type=button].confirm_button'),
            'qty': $('input[name=qty]')
        };
    },
    addProduct: function () {
        var self = this;
        $(self.selectors.add_product).on('click', function () {
            gtag('event', 'begin_checkout', {
                "items": [
                    {
                        "id": product_id,
                        "name": productName,
                        "list_name": productName,
                        "brand": product_supplier,
                        "category": categoryName,
                        "list_position": 1,
                        "quantity": self.getProductQty(),
                        "price": productPrice
                    }
                ],
                "coupon": ""
            });
        });
    },
    checkoutProgress: function () {
        $(this.selectors.checkout_progress).on('click', function () {
            gtag('event', 'checkout_progress', {
                "items": items_products,
                "coupon": "SUMMER_DISCOUNT"
            });
        });
    },
    purchaseGtag: function (id_order,summ,currency,tax,shipping,items) {
        gtag('event', 'purchase', {
            "transaction_id": id_order,
            "affiliation": "E-Paravany.sk",
            "value": summ,
            "currency":currency,
            "tax": tax,
            "shipping": shipping,
            "items": items
        });
    },
    getProductQty: function () {
        return $(this.selectors.qty).val();
    }
};
$(document).ready(function () {
    GtagManager.init();
});