"use strict";function _defineProperty(e,l,r){return l in e?Object.defineProperty(e,l,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[l]=r,e}var MuellerAlert;window.Mueller=window.Mueller||{},jQuery(document).ready(function(){}),void 0!==Liferay.Util.getOpener().muellerAlert&&null!=Liferay.Util.getOpener().muellerAlert&&(window.muellerAlert=Liferay.Util.getOpener().muellerAlert),void 0!==window.muellerAlert&&null!=window.muellerAlert||(window.muellerAlert=MuellerAlert={init:function(){this.getAlertBanner(),this.getAlertDialog()},getAlertBanner:function(){this.callToServer(window.Mueller.alertBannerURL)},showAlertBanner:function(e){if(void 0===e||null==e||e.length<1)$("#muellerAlertBanner").hide(),$("#alertStagingMessage").show();else{$("#muellerAlertBanner").show();var l,r="",t="",n=0;for(l in e){var i=0===n?"active":"";r+='<li data-target="#muellerAlertBanner" data-slide-to="'+n+'" artileId='+l+' class="'+i+'"></li>',t+='<div data-target="#muellerAlertBanner" data-slide-to="'+n+'" artileId='+l+' class="carousel-item '+i+'">\n                                        '+e[l]+"\n                                    </div>",n++}jQuery("<ol/>").addClass("carousel-indicators").html(r);var a=jQuery("<div/>").addClass("carousel-inner").html(t),a=(jQuery("#muellerAlertBanner").append(a),"<div class='alert-banner-readmore'>\n            <a href='"+window.Mueller.alertBannerDisplayPage+'\' class=\'alert-banner-readmore-link\'>\n                <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24">\n                    <path d="M22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2A10,10 0 0,1 22,12M10,18L16,12L10,6L8.6,7.4L13.2,12L8.6,16.6L10,18Z" />\n                </svg>\n            </a>\n            </div>');window.Mueller.showAlertBannerDisplayPage&&jQuery("#muellerAlertBanner").append(a)}},getAlertDialog:function(){var e=this.getCookie("mueller_alert_timeout");null!=e&&""!==e||this.callToServer(window.Mueller.alertDialogURL)},showAlertDialog:function(e){if(!(void 0===e||null==e||e.length<1)){var l,r="",t=0;for(l in e)r+="<div id='alert-dialog-item-"+l+"' artileId="+l+" class='alert-dialog-item'>\n                                "+e[l]+"\n                                </div>",t++,1<Object.keys(e).length&&t<Object.keys(e).length&&(r+="<hr />");var n="<div class='alert-dialog-readmore'>\n                            <a href='"+window.Mueller.alertDialogDisplayPage+'\' \n                            class=\'alert-dialog-readmore-link\'>View more <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" /></a></div>';jQuery("#muellerAlertDialog .modal-body").html(r),window.Mueller.showAlertDialogDisplayPage&&jQuery("#muellerAlertDialog .modal-body").after(n),jQuery("#muellerAlertDialog").modal()}},closeAlert:function(){$("#muellerAlertDialog").modal("hide")},parseJSON:function(e){try{return JSON.parse(e)}catch(e){return""}},showMessage:function(e,l){"undefined"!=typeof l&&null!=l&&"error"===(l=l.toLowerCase())&&(l="danger"),jQuery("#muellerAlertAlert").addClass("alert alert-"+l),jQuery("#muellerAlertAlert").html(""+e)},callToServer:function(e){var l;jQuery.ajax((_defineProperty(l={type:"GET",url:e,cache:!1,contentType:"text/html; charset=utf-8",dataType:"text"},"url",e),_defineProperty(l,"success",function(e){var l,r=window.muellerAlert.parseJSON(e),e=r.status,t=r.cmd;if("success"==e)"alertdialog"==t?(window.muellerAlert.showAlertDialog(r.data),l=(new Date).getTime(),window.muellerAlert.setCookie("mueller_alert_timeout",l,window.Mueller.alertTimeOutHour)):"alertbanner"==t&&window.muellerAlert.showAlertBanner(r.data);else if("error"==e){var n,i="";for(n in r.error)i=i+"<p>"+r.error[n]+"</p>";window.muellerAlert.showMessage(i,e)}}),l))},setCookie:function(e,l,r){(isNaN(parseInt(r))||parseInt(r)<=0)&&(r=.01);var t=new Date,r=(t.setTime(t.getTime()+60*r*60*1e3),"; expires="+t.toUTCString());document.cookie=e+"="+(l||"")+r+"; path=/"},getCookie:function(e){for(var l,r=e+"=",t=document.cookie.split(";"),n=0;n<t.length;n++){for(l=t[n];" "===l.charAt(0);)l=l.substring(1,l.length);if(0===l.indexOf(r))return l.substring(r.length,l.length)}return null},eraseCookie:function(e){document.cookie=e+"=;expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/"},doAlertExternal:function(e,l){void 0!==e&&null!=e&&""!=e&&window.muellerAlert.setCookie("mueller-returnFunction",e),void 0!==l&&null!=l&&window.muellerAlert.setCookie("mueller-returnFunctionParam",l),window.muellerAlert.viewAlert()},executeFunctionByName:function(e,l){if(void 0!==e&&null!=e&&""!=e){for(var r=[],t=("undefined"!=typeof returnFunctionParam&&null!=returnFunctionParam&&(r=Array.prototype.slice.call(arguments,2)),e.split(".")),e=t.pop(),n=0;n<t.length;n++)l=l[t[n]];return l[e].apply(l,r)}}},window.muellerAlert.init());
'use strict';

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/* global Liferay, AUI */
/* eslint-disable */
var MuellerChecklist;
window.Mueller = window.Mueller || Liferay.Util.getOpener().Mueller || {};
window.Mueller.ChecklistType = {
	product: 'product',
	color: 'color',
	education: 'education',
	question: 'question'
};
window.Mueller.checklistCookieName = 'mueller-checklist-id';
window.Mueller.checklistButtonClicked = false;

//Fix multiple call from popup referensing a diffrent object;
if (typeof Liferay.Util.getOpener().muellerChecklist !== 'undefined' && Liferay.Util.getOpener().muellerChecklist != null) {
	window.muellerChecklist = Liferay.Util.getOpener().muellerChecklist;
}

//Fix issue of not loading checklist javascript when product is opened from a link with target=_blank or as a popup;
if (jQuery('#' + window.Mueller.checklistNamespace + 'viewChecklist').length > 0) {
	window.muellerChecklist = null;
	delete window.muellerChecklist;
}

if (typeof window.muellerChecklist === 'undefined' || window.muellerChecklist != null) {
	//Initiate neccessary form bindings and set client view
	jQuery(document).ready(function () {
		if (window.location.href.indexOf('checklist=1') > 0) {
			// no load on terms page & password reminder page
			if ($('#referer').length > 0 && $('#referer').val().indexOf('checklist=1') > 1) {
				return;
			}

			if (document.title.toLowerCase().indexOf('terms of use') >= 0 || document.title.toLowerCase().indexOf('new password') >= 0 || document.title.toLowerCase().indexOf('password reminder') >= 0 || document.title.toLowerCase().indexOf('verify email address') >= 0) {
				return;
			}

			window.muellerChecklist.viewChecklist();
		}

		jQuery('body').prepend('<div id="muellerPreloader"><img id="loader-img" alt="" src="' + window.Mueller.checklistPortletPath + '/image/loader_a.gif" width="100" height="100" align="center" /></div>');
		window.Mueller.preloader = $('#muellerPreloader').hide();

		jQuery(window).resize(function () {
			jQuery('#checklistDialog .modal-body').height(jQuery(window).height());
		});

		jQuery('#checklistDialog').on('hidden.bs.modal', function () {
			jQuery('#checklistDialog').empty();
		});

		jQuery('.main-header__eyebrow .view-checklist-cart').remove();
		if (jQuery('.main-header__eyebrow ul').length > 0) {
			jQuery('.main-header__eyebrow ul').append('<li><a class="view-checklist-cart disabled"><span class="item-count badge"></span><i class="view-checklist-icon zmdi zmdi-hc-fw zmdi-assignment-check"></i></a></li>');
		}

		jQuery('.mobile-header-toolbar .view-checklist-cart').parent().remove();
		if (jQuery('.mobile-header-toolbar ul').length > 0) {
			jQuery('<li><a class="view-checklist-cart disabled"><span class="item-count badge"></span><i class="icon view-checklist-icon zmdi zmdi-hc-fw zmdi-assignment-check"></i></a></li>').insertAfter($('.mobile-header-toolbar .icon-search').closest('li'));
		}

		window.muellerChecklist = MuellerChecklist;
		window.muellerChecklist.init();
	}).ajaxStart(function () {
		if (window.Mueller.checklistButtonClicked) {
			$(window.Mueller.preloader).show();
		}
		window.Mueller.checklistButtonClicked = false;
	}).ajaxStop(function () {
		$(window.Mueller.preloader).hide();
		$('.log').text('Triggered ajaxComplete handler.');
	}).ajaxError(function () {
		$(window.Mueller.preloader).hide();
		$('.log').text('Triggered ajaxError handler.');
	});

	// Save For Later/Remove button on product pages
	$(document).on('click', '#checklistBtn', function (evt) {
		evt.preventDefault();
		if (evt.handled === true) {
			return true;
		}

        window.Mueller.checklistButtonClicked = true;
        if ($(this).hasClass('primary')) {
            window.muellerChecklist.addChecklist(window.Mueller.productId, window.Mueller.ChecklistType.product, window.Mueller.productId, window.Mueller.productName);
        } else {
            $(this).addClass('tertiary').removeClass('primary');
            window.muellerChecklist.removeChecklist(window.Mueller.productId, window.Mueller.ChecklistType.product, window.Mueller.productId);
        }
        evt.handled = true;
    });

    $(document).on('click', '#checklist-details-wrapper .checklist-action a, #view-checklist-product', function (e) {
        window.Mueller.checklistButtonClicked = true;
        $('.checklist-action div').removeClass('action-active');
		setProductTabActive();
        $('.checklist-product').hide();
        $('.checklist-summary').hide();
        $('#view-checklist-summary').show();

		var checklistProductDiv;
		if( $(this).attr('id') === 'view-checklist-product' ) {
			checklistProductDiv = $('#checklist-details-wrapper .checklist-action a:first').parent();
		}
		else{
			checklistProductDiv = $(this).parent();
		}

        if( checklistProductDiv.hasClass('action-product') || $(this).attr('id') === 'view-checklist-product' ) {
			var productId = checklistProductDiv.attr('data-productId');
			$('#checklist-product-' + productId).show();
			checklistProductDiv.addClass('action-active');
        }
	});

	$(document).on('click', '#verify-email-address-checklist', function (e) {
		if (Liferay.ThemeDisplay.isSignedIn) {
			console.log('Email ', window.Mueller.userEmailAddress);
			var url = window.location.protocol + '//' + window.location.host + '/o/services/mups' + '/user';
			var obj = { emailAddress: window.Mueller.userEmailAddress };
			$.ajax({
				url: url + '/verify-email-address',
				type: 'post',
				headers: {
					'Accept': 'application/json',
					'Content-Type': 'application/json'
				},
				data: JSON.stringify(obj),
				dataType: 'json',
				success: function success(data) {
					if (data.status == 'success') {
						bootbox.alert(data.errorMessage);
					} else if (data.status == 'error') {
						bootbox.alert(data.errorMessage);
					} else {
						bootbox.alert('Error occurred while verifying your email address');
					}
				}, error: function error(data) {
					bootbox.alert('Error occurred while verifying your email address');
				}
			});
		} else {
			bootbox.alert('Please login to your account');
		}
	});

    $(document).on('click', '.checklist-section-content .item-delete', function () {
        var $parentElm = $(this).parent();
        var itemName = $parentElm.siblings('.checklist-section-product-name:first').text();
        var productId = $parentElm.attr('data-productId');

        if (window.confirm('Remove ' + itemName + ' from checklist?')) {
            Liferay.Util.getOpener().muellerChecklist.removeChecklist(productId, window.Mueller.ChecklistType.product, productId);

            $('.action-product[data-productid=' + productId + ']').remove();
            $('#checklist-product-' + productId).remove();
            $('#product-summary-item-' + productId).remove();

			if ($('.action-product').length > 0) {
				$('.action-product:first a:first').click();
			} else {
				$('.action-summary a').click();
				$('.checklist-buttons button.btn').attr('disabled', 'disabled');
				window.muellerChecklist.closeChecklist();
			}
		}
	});

	$(document).on('click', '#view-checklist-summary', function () {
		setSubmitTabActive();
	});

	$(document).on('click', '#view-checklist-share', function () {
		setShareTabActive();
	});

	function setProductTabActive() {
		$('.checklist-action div').removeClass('action-active');
		$('#view-checklist-product').addClass('active-tab');
		$('#view-checklist-summary').removeClass('active-tab');
		$('#view-checklist-share').removeClass('active-tab');
		$('.checklist-summary').hide();
		$('.checklist-share').hide();
		$('.checklist-product').show();
	}

	function setSubmitTabActive() {
		$('.checklist-action div').removeClass('action-active');
		$('#view-checklist-summary').addClass('active-tab');
		$('#view-checklist-product').removeClass('active-tab');
		$('#view-checklist-share').removeClass('active-tab');
		$('.checklist-share').hide();
		$('.checklist-product').hide();
		$('.checklist-summary').show();
	}

	function setShareTabActive() {
		$('.checklist-action div').removeClass('action-active');
		$('#view-checklist-share').addClass('active-tab');
		$('#view-checklist-summary').removeClass('active-tab');
		$('#view-checklist-product').removeClass('active-tab');
		$('.checklist-summary').hide();
		$('.checklist-product').hide();
		$('.checklist-share').show();
	}

    jQuery('#checklist-details-wrapper .checklist-summary .product-summary-item').click(function () /* e */{
        var productId;

		jQuery('.checklist-action div').removeClass('action-active');
		jQuery('.checklist-product').hide();
		jQuery('.checklist-summary').hide();

        productId = jQuery(this).attr('data-productId');

        jQuery('#checklist-product-' + productId).show();
        jQuery('.checklist-action .action-product[data-productId="' + productId + '"]').addClass('action-active');
    });

    jQuery(document).on('click', '#checklist-details-wrapper .save-remove-education', function () /* e */{
        var $target = $(this);
        var $dataDiv = $target.parents('div.checklist-section-item');
        var productId = $dataDiv.attr('data-productId');
        var checklistId = $dataDiv.attr('data-checklistId');
        var checklistType = $dataDiv.attr('data-checklistType');

        if ($target.hasClass('icon-remove-education')) {
            $target.parents('.checklist-section-item').removeClass('selected-content');
            $target.find('i').removeClass('icon-star').addClass('icon-star-empty');
            $target.attr('title', 'Add to list');
            window.muellerChecklist.removeChecklist(productId, checklistType, checklistId);
        } else if ($target.hasClass('icon-save-education')) {
            $target.parents('.checklist-section-item').addClass('selected-content');
            $target.find('i').removeClass('icon-star-empty').addClass('icon-star');
            $target.attr('title', 'Remove from list');
            window.muellerChecklist.addChecklist(productId, checklistType, checklistId);
        }

		$target.toggleClass('icon-remove-education').toggleClass('icon-save-education');
	});

    jQuery(document).on('click', '#checklist-details-wrapper .checklist-product input[type=checkbox]', function () /* e */{
        var dataDiv = jQuery(this).parents('div.checklist-section-item');
        var productId = jQuery(dataDiv).attr('data-productId');
        var checklistId = jQuery(dataDiv).attr('data-checklistId');
        var checklistType = jQuery(dataDiv).attr('data-checklistType');

        if (jQuery(this).is(':checked')) {
            jQuery(this).parents('.checklist-section-item').addClass('selected-content');
            window.muellerChecklist.addChecklist(productId, checklistType, checklistId);
        } else {
            jQuery(this).parents('.checklist-section-item').removeClass('selected-content');
            window.muellerChecklist.removeChecklist(productId, checklistType, checklistId);
        }
    });

	jQuery(document).on('click', '.save-edu-to-checklist', function () /* e */{
		var thisCaption = jQuery(this).text();
		var eduId = jQuery(this).attr('data-articleid');

        if (thisCaption === 'REMOVE FROM CHECKLIST') {
			window.muellerChecklist.removeChecklist(window.Mueller.productId, window.Mueller.ChecklistType.education, eduId);
		} else {
			window.muellerChecklist.addChecklist(window.Mueller.productId, window.Mueller.ChecklistType.education, eduId);
		}
    });

    jQuery('#checklist-details-wrapper  .add-checklist').click(function (e) {
        var checklistId = jQuery('#checklistId').val();
        var checklistType = jQuery('#checklistType').val();
        var productId = jQuery('#productId').val();

        e.preventDefault();

        window.muellerChecklist.addChecklist(productId, checklistType, checklistId);
    });

    jQuery('#checklist-details-wrapper  .remove-checklist').click(function (e) {
        var checklistId = jQuery('#checklistId').val();
        var checklistType = jQuery('#checklistType').val();
        var productId = jQuery('#productId').val();

        e.preventDefault();

        window.muellerChecklist.removeChecklist(productId, checklistType, checklistId);
    });

	jQuery('.save-checklist').click(function () /* e */{
		window.Mueller.checklistButtonClicked = true;
		window.muellerChecklist.saveChecklist();
	});

	jQuery('.clear-checklist').click(function () /* e */{
		window.muellerChecklist.clearChecklist();
	});

	jQuery('.view-checklist').click(function (e) {
		e.preventDefault();
		window.Mueller.checklistButtonClicked = true;
		if (!jQuery(this).hasClass('disabled')) {
			window.muellerChecklist.viewChecklist();
		}
	});

	$(document).on('click', '.view-checklist-cart', function (e) {
		e.preventDefault();
		window.Mueller.checklistButtonClicked = true;
		if (!jQuery(this).hasClass('disabled')) {
			window.muellerChecklist.viewChecklist();
		}
	});

	//define mueller checklist object
	MuellerChecklist = {
		init: function init() {
			jQuery('.view-checklist').addClass('disabled');
			window.Mueller.checklistId = 0;
			this.updateClientView();
			this.getChecklist();
		},
		viewChecklist: function viewChecklist() {
			if (!Liferay.ThemeDisplay.isSignedIn()) {
				var checklistAction = { cmd: 'viewchecklist' };
				window.Mueller.checklistAction = checklistAction;
				window.muellerChecklist.signInRequired();
				return;
			}

			var timestamp = new Date().getTime();
			var viewChecklistURL = window.Mueller.checklistViewURL + '&timestamp=' + timestamp;

            jQuery('#checklistDialog').show();
            jQuery('#checklistDialog').load(viewChecklistURL, function (responseTxt, statusTxt, xhr) {
                if (statusTxt == 'success') {
                    jQuery('#checklistDialog').modal();
                    jQuery('#checklistDialog .modal-body').height(jQuery(window).height());
                    $('.modal-backdrop').show();
					$('html').css('overflow-y', 'hidden');
                }
                if (statusTxt == 'error') {
                    console.log('Error: ' + xhr.status + ': ' + xhr.statusText);
                }
            });
        },
        showConfirm: function showConfirm(confirmHtml) {
            AUI().use('aui-dialog', 'aui-io', 'aui-io-request', 'aui-base', function (A) {
                var dialog = new A.Modal({
                    title: 'Checklist Confirmation',
                    bodyContent: A.one('#confirmChecklist').html(confirmHtml),
                    headerContent: 'AUI Modal Heading',
                    destroyOnHide: true,
                    centered: true,
                    modal: true,
                    height: 600,
                    width: 800,
                    render: '#my-content-div',
                    close: true
                });
                dialog.render();
            });
        },
        closeChecklist: function closeChecklist() {
            $('#checklistDialog').empty();
            $('#checklistDialog').hide();
            $('.modal-backdrop').empty();
            $('.modal-backdrop').hide();
			$('html').css('overflow-y', 'auto');
        },
        addChecklist: function addChecklist(productId, dataType, dataId) {

            if (!Liferay.ThemeDisplay.isSignedIn()) {
                var checklistAction = { cmd: 'addtochecklist', productId: productId, dataType: dataType, dataId: dataId };
                window.Mueller.checklistAction = checklistAction;
                window.muellerChecklist.signInRequired();
                return;
            }
            var saveData;

            if (typeof productId === 'undefined' || typeof dataType === 'undefined' || typeof dataId === 'undefined') {
                return;
            }

			saveData = { productId: productId, dataType: dataType, dataId: dataId };
			saveData = this.transportModel('', 'addtochecklist', saveData);
			saveData = this.transportData(saveData);
			this.callServer(saveData);
        },
        removeChecklist: function removeChecklist(productId, dataType, dataId) {
            if (!Liferay.ThemeDisplay.isSignedIn()) {
                var checklistAction = { cmd: 'removefromchecklist', productId: productId, dataType: dataType, dataId: dataId };
                window.Mueller.checklistAction = checklistAction;
                window.muellerChecklist.signInRequired();
                return;
            }

			var saveData;

            if (typeof productId === 'undefined' || typeof dataType === 'undefined' || typeof dataId === 'undefined') {
                return;
            }

            saveData = { productId: productId, dataType: dataType, dataId: dataId };
            saveData = this.transportModel('', 'removefromchecklist', saveData);
            saveData = this.transportData(saveData);
            this.callServer(saveData);
        },
        isItemInChecklist: function isItemInChecklist(productId, dataType, dataId) {
            if (typeof productId === 'undefined' || typeof dataType === 'undefined' || typeof dataId === 'undefined') {
                return false;
            }
            if (typeof window.Mueller.checklistData === 'undefined') {
                return false;
            }

            var productChecklist = window.Mueller.checklistData[productId];
            if (typeof productChecklist === 'undefined' || productChecklist == null) {
                return false;
            }

			var dataTypeChecklist = productChecklist[dataType];
			if (typeof dataTypeChecklist === 'undefined' || dataTypeChecklist == null) {
				return false;
			}

            var thisItem = dataTypeChecklist[dataId];
            if (typeof thisItem === 'undefined' || thisItem == null) {
                return false;
            }
            return true;
        },
        isProductInChecklist: function isProductInChecklist(productId) {

            if (typeof productId === 'undefined' || productId === '') {
                return false;
            }
            if (typeof window.Mueller.checklistData === 'undefined' || window.Mueller.checklistData == null) {
                return false;
            }
            var productChecklist = window.Mueller.checklistData[productId];
            if (typeof productChecklist === 'undefined' || productChecklist == null) {
                return false;
            }
            return true;
        },

		getChecklist: function getChecklist() {

			// eslint-disable-line consistent-return
			if (typeof window.Mueller.checklistData !== 'undefined') {
				return window.Mueller.checklistData;
			}

			var saveData = this.transportModel('', 'getchecklist');
			saveData = this.transportData(saveData);
			this.callServer(saveData);
		},
		updateClientView: function updateClientView() {

			if (jQuery.isEmptyObject(window.Mueller.checklistData)) {
				jQuery('.view-checklist').text(window.Mueller.checklistViewButtonCaption);
				jQuery('.view-checklist').addClass('disabled');
				jQuery('.view-checklist').text('' + window.Mueller.checklistViewButtonCaption);

				jQuery('.view-checklist-cart').addClass('disabled');
				jQuery('.view-checklist-cart .item-count').text('');

				return;
			}

			jQuery('.view-checklist').text(window.Mueller.checklistViewButtonCaption + ' [' + Object.keys(window.Mueller.checklistData).length + ']');
			jQuery('.view-checklist').removeClass('disabled');

			jQuery('.view-checklist-cart .item-count').text('' + Object.keys(window.Mueller.checklistData).length);
			jQuery('.view-checklist-cart').removeClass('disabled');

			jQuery('.view-checklist-cart .view-checklist-icon').addClass('cart-run');
			jQuery('.view-checklist-cart .item-count').addClass('shake');
			jQuery('.view-checklist-cart').addClass('glow');

			setTimeout(function () {
				jQuery('.view-checklist-cart .view-checklist-icon').removeClass('cart-run');
				jQuery('.view-checklist-cart .item-count').removeClass('shake');
				jQuery('.view-checklist-cart').removeClass('glow');
			}, 800);
		},
		clearChecklist: function clearChecklist() {
			window.Mueller.checklistData = null;
			delete window.Mueller.checklistData;
			window.Mueller.checklistId = 0;
		},
		saveChecklist: function saveChecklist(saveData) {
			this.callServer(saveData);
		},
		parseJSON: function parseJSON(jsonString) {
			try {
				return JSON.parse(jsonString);
			} catch (err) {
				return '';
			}
		},
		transportModel: function transportModel(token, cmd, data) {
			var timestamp = new Date().getTime();
			var tData = {
				token: token,
				cmd: cmd,
				data: data,
				checklistId: window.Mueller.checklistId,
				timestamp: timestamp
			};
			return tData;
		},
		transportData: function transportData(data) {
			return window.Mueller.checklistNamespace + 'transportData=' + JSON.stringify(data);
		},
		reloadMainPage: function reloadMainPage() {
			window.location.reload();
		},
		showMessage: function showMessage(message, title, messageType) {
			if (typeof title === 'undefined' || title === null || title == '') { 
				title = 'Checklist Information';
			}
			if (typeof messageType === 'undefined' || messageType === null || messageType == '') {
				messageType = 'info';
			}
			if (typeof messageType !== 'undefined' && messageType != null) {
				messageType = messageType.toLowerCase();
				
				if (messageType === 'error') {
					messageType = 'danger';
				}
			}

			jQuery('#checklistInfoAlert').addClass('alert alert-' + messageType);
			jQuery('#checklistInfoAlert').html('' + message);
		},
		signInRequired: function signInRequired() {
			if (typeof window.Mueller.checklistAction !== 'undefined' && window.Mueller.checklistAction != '') {
				window.muellerChecklist.setCookie('mueller-checklist-action', JSON.stringify(window.Mueller.checklistAction));
			}
			window.location.href = location.protocol + '//' + location.host + '/login?redirect=' + encodeURIComponent(location.href);
		},
		callServer: function callServer(data, url) {
			jQuery('#checklistInfoAlert').empty().removeClass();

			if (typeof url === 'undefined' || url === '') {
				url = encodeURI(window.Mueller.checklistResourceURL); // eslint-disable-line no-param-reassign
				data = encodeURI(data);
			}
			jQuery.ajax({
				type: 'GET',
				url: url,
				data: data,
				cache: false,
				contentType: 'text/html; charset=utf-8',
				dataType: 'text',
				success: function success(response) {
					var responseJSON = window.muellerChecklist.parseJSON(response);

					if (typeof responseJSON !== 'undefined') {
						var rtChecklistData = window.muellerChecklist.parseJSON(responseJSON.checklistData);

						if (typeof rtChecklistData !== 'undefined') {
							window.Mueller.checklistData = rtChecklistData.products;
						}

						if (isNaN(responseJSON.checklistId)) {
							window.Mueller.checklistId = 0;
						} else {
							window.Mueller.checklistId = parseInt(responseJSON.checklistId);
						}
						var errorMessage = responseJSON.error;

						if (responseJSON.cmd === 'savechecklist' || responseJSON.cmd === 'deletechecklist') {
							window.muellerChecklist.clearChecklist();
							window.muellerChecklist.closeChecklist();
							if (typeof errorMessage !== 'undefined' & errorMessage != '') {
								window.muellerChecklist.showMessage(errorMessage);
							}
							if (responseJSON.cmd === 'savechecklist') {
								bootbox.alert('Checklist was saved successfully');
							}
						} else if (responseJSON.cmd === 'invalidchecklist') {
							window.muellerChecklist.clearChecklist();
							window.muellerChecklist.closeChecklist();
						} else if (responseJSON.cmd === 'getchecklist') {
							var checklistActionString = window.muellerChecklist.getCookie('mueller-checklist-action');

                            if (typeof checklistActionString !== 'undefined' && checklistActionString != null && checklistActionString != '') {
                                var checklistAction = window.muellerChecklist.parseJSON(checklistActionString);
                                if (checklistAction != null && checklistAction.cmd == 'addtochecklist') {
                                    window.muellerChecklist.addChecklist(checklistAction.productId, checklistAction.dataType, checklistAction.dataId);
                                } else if (checklistAction != null && checklistAction.cmd == 'removefromchecklist') {
                                    window.muellerChecklist.addChecklist(checklistAction.productId, checklistAction.dataType, checklistAction.dataId);
                                } else if (checklistAction != null && checklistAction.cmd == 'viewchecklist') {
                                    window.muellerChecklist.viewChecklist();
                                }
                                checklistAction = null;
                            }
                            checklistActionString = '';
                            window.muellerChecklist.eraseCookie('mueller-checklist-action');
                        }

						window.muellerChecklist.updateClientView();
						window.muellerChecklist.setProductPage();
					} else {
						window.muellerChecklist.closeChecklist();
					}
				},
				error: function error() /* response, ajaxOptions, thrownError */{
					jQuery('.checklist-saving').hide();
				},
				failure: function failure() /* response */{
					jQuery('.checklist-saving').hide();
				}
			});
		},
		callToServerAsyn: function callToServerAsyn(data, url) {
			var _jQuery$ajax;

			jQuery('#checklistInfoAlert').empty().removeClass();

			if (typeof url === 'undefined' || url === '') {
				url = window.Mueller.checklistResourceURL; // eslint-disable-line no-param-reassign
			}

			var rStatus = '';
			jQuery.ajax((_jQuery$ajax = {
				type: 'GET',
				url: url,
				data: data,
				cache: false,
				contentType: 'text/html; charset=utf-8',
				dataType: 'text'
			}, _defineProperty(_jQuery$ajax, 'url', url), _defineProperty(_jQuery$ajax, 'success', function success(response) {
				var responseJSON = window.muellerChecklist.parseJSON(response);
				rStatus = responseJSON['status'];
				if (rStatus == 'success') {
					if (typeof window.Mueller.checklistAction !== 'undefined' && window.Mueller.checklistAction != '') {
						window.muellerChecklist.setCookie('mueller-checklist-action', JSON.stringify(window.Mueller.checklistAction));
					}

					window.Mueller.checklistAction = null;
					delete window.Mueller.checklistAction;
					window.muellerChecklist.reloadMainPage();
				}
				if (rStatus == 'error') {
					var errorMessage = '';
					for (var key in responseJSON['error']) {
						errorMessage = errorMessage + '<p>' + responseJSON['error'][key] + '</p>';
					}
					window.muellerChecklist.showMessage(errorMessage, rStatus, rStatus);
				}
			}), _defineProperty(_jQuery$ajax, 'async', false), _jQuery$ajax));

            return rStatus;
        },
        setProductPage: function setProductPage() /* educationItems */{
            if (this.isProductInChecklist(window.Mueller.productId)) {
                jQuery('#checklistBtn').text(window.Mueller.checklistRemoveButtonCaption).addClass('tertiary').removeClass('primary');
            } else {
                jQuery('#checklistBtn').text(window.Mueller.checklistSaveButtonCaption).removeClass('tertiary').addClass('primary');
            }

            jQuery('.save-edu-to-checklist').each(function () {
                var eduId = jQuery(this).attr('data-articleid');
                var itemInChecklist = window.muellerChecklist.isItemInChecklist(window.Mueller.productId, window.Mueller.ChecklistType.education, eduId);
                if (itemInChecklist) {
                    jQuery(this).text('REMOVE FROM CHECKLIST');
                    jQuery('.educationContentTitle[custom-id="' + eduId + '"]').addClass('in-checklist');
                } else {
                    jQuery(this).text('SAVE FOR LATER');
                    jQuery('.educationContentTitle[custom-id="' + eduId + '"]').removeClass('in-checklist');
                }
            });
        },
        setCookie: function setCookie(name, value, hours) {
            if (isNaN(parseInt(hours)) || parseInt(hours) <= 0) {
                hours = 0.2;
            }
            var cookieExpDate = new Date();
            cookieExpDate.setTime(cookieExpDate.getTime() + hours * 60 * 60 * 1000);
            var expires = '; expires=' + cookieExpDate.toUTCString();
            document.cookie = name + '=' + (value || '') + expires + '; path=/';
        },
        getCookie: function getCookie(name) {
            var nameEQ = name + '=';
            var ca = document.cookie.split(';');
            var c;
            for (var i = 0; i < ca.length; i++) {
                c = ca[i];
                while (c.charAt(0) === ' ') {
                    c = c.substring(1, c.length);
                }if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
            }
            return null;
        },
        eraseCookie: function eraseCookie(name) {
            document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
        },

		printCheckist: function printChecklist(checklistId) {
			var _jQuery$ajax2;

			var rStatus = '';

			if (checklistId == 0) {
				return;
			}

			var url = window.Mueller.checklistResourceURL + '&' + window.Mueller.checklistNamespace + 'printChecklistId=' + checklistId;

			jQuery.ajax((_jQuery$ajax2 = {
				type: 'GET',
				url: url,
				cache: false,
				contentType: 'text/html; charset=utf-8',
				dataType: 'text'
			}, 
			_defineProperty(_jQuery$ajax2, 'url', url), 
			_defineProperty(_jQuery$ajax2, 'success', function success(response) {
				var responseJSON = window.muellerChecklist.parseJSON(response);
				rStatus = responseJSON['print'];
			}), 
			_defineProperty(_jQuery$ajax2, 'async', false), _jQuery$ajax2));

			if (rStatus == 'success') {
				return window.Mueller.printMyCheckListRenderURL + '&' + window.Mueller.checklistNamespace + 'checklistId=' + checklistId + '&' + window.Mueller.checklistNamespace + 'printMyChecklist=' + true;
			}
		},
		shareCheckList: function shareCheckList(formData) {
			var url = window.location.protocol + '//' + window.location.host + '/o/services/mups' + '/checklistapi/sharechecklist';
			
			jQuery.ajax({
				type: 'POST',
				url: url,
				data: JSON.stringify(formData),
				cache: false,
				contentType: 'application/json; charset=utf-8',
				dataType: 'text',
				success: function success(response) {
					var content = JSON.parse(response);
					bootbox.alert('Checklist was shared successfully');

					if(content.data.messageType != 'success') {
						console.log('Expected messageType "success" not found in response: ' + JSON.stringify(content));
					}
				},
				error: function error(response) {
					bootbox.alert('Error while sharing checklist');
					console.log(JSON.parse(response));
				}
			});
		}
	};
}

jQuery(($) => {
    function filterEducationEntries() {
        const $input = $(this);
        const $ul = $('#education-list');
        const $li = $ul.find('> li');
        const filter = $input.val();

        function queryMatchesContent(q, a) {
            const queryRegEx = new RegExp(filter, 'i');
            return [q, a].join(' ').match(queryRegEx);
        }

        for (let i = 0; i < $li.length; i++) {
            const listItem = $li[i];
            const question = listItem.querySelector('.education-entry-title').innerText || '';
            const answer = listItem.querySelector('.education-entry-content').innerText || '';

            if (queryMatchesContent(question, answer)) {
                listItem.style.display = '';
            } else {
                listItem.style.display = 'none';
            }
        }
    }

    $('#education-search-input').on('input', filterEducationEntries);
});

