(()=>{var t,e;ck.setCookie=function(t,e,a){var n="";if("number"==typeof a){var i=new Date;i.setTime(i.getTime()+24*a*60*60*1e3),n="expires="+i.toUTCString()}document.cookie=t+"="+e+"; "+n+"; path=/"},ck.getCookie=function(t){for(var e=t+"=",a=document.cookie.split(";"),n=0;n<a.length;n++){for(var i=a[n];" "==i.charAt(0);)i=i.substring(1);if(0==i.indexOf(e))return i.substring(e.length,i.length)}return""},ck.addUrlParam=function(t,e,a,n){n=!!n;var i=new RegExp("(\\?|\\&)"+e+"=.*?(?=(&|$))"),o="",r="";return-1!==t.indexOf("#")&&(o=t.split("#"),t=o[0],r=o[1]),i.test(t)?t=t.replace(i,"$1"+e+"="+a):/\?.+$/.test(t)?t+=n?encodeURIComponent("&"+e+"="+a):"&"+e+"="+a:(t+="?"+e+"=",t+=n?encodeURIComponent(a):a),""!==r&&(t+="#"+r),t},$((function(){$(document).on("touchend click",".showGalleryView",(function(){$("body").removeClass("textOnlyList"),$("body").addClass("listShowCart listShowDetails"),$(".expandAllCards").removeClass("toggled"),$(".zoomedWrapper").removeClass("zoomedWrapper").find(".cardLink").removeClass("zoomed").find(".catalogItemMag").remove(".catalogItemMag"),$(".zoomItem").removeClass("zoomItem");var t=window.location.href;t=ck.addUrlParam(t,"view","gallery"),document.location=t,ck.setCookie("viewType","listShowCart listShowDetails",365)})),$(document).on("touchend click",".showDetailView",(function(){$("body").removeClass("listShowCart listShowDetails textOnlyList"),$(".expandAllCards").removeClass("toggled"),$(".zoomedWrapper").removeClass("zoomedWrapper").find(".cardLink").removeClass("zoomed").find(".catalogItemMag").remove(".catalogItemMag"),ck.setCookie("viewType","",365);var t=window.location.href;t=ck.addUrlParam(t,"view","detail"),document.location=t})),$(document).on("touchend click",".showTextView",(function(){$("body").removeClass("listShowCart listShowDetails"),$(".expandAllCards").removeClass("toggled"),$(".zoomedWrapper").removeClass("zoomedWrapper").find(".cardLink").removeClass("zoomed").find(".catalogItemMag").remove(".catalogItemMag"),$(".zoomItem").removeClass("zoomItem"),$("body").addClass("textOnlyList"),ck.setCookie("viewType","textOnlyList",365);var t=window.location.href;t=ck.addUrlParam(t,"view","text"),document.location=t}))})),(()=>{var t=t||{};$((function(){t.trackSettingByCookie(".perPage","limit"),t.trackSettingByCookie("#sortBy","sortBy")})),t.trackSettingByCookie=function(e,a){$(document).on("change",e,(function(){var e=$(this).val(),n=a+"="+e+";path=/",i=window.location.href;document.cookie=n,i=t.removeUrlParam(i,"page"),window.location.href=i}))},t.removeUrlParam=function(t,e){var a=t.split("?");if(a.length>=2){for(var n=a.shift(),i=a.join("?"),o=encodeURIComponent(e)+"=",r=i.split(/[&;]/g),s=r.length;s-- >0;)-1!==r[s].lastIndexOf(o,0)&&r.splice(s,1);t=r.length>0?n+"?"+r.join("&"):n}return t},t.addUrlParam=function(t,e,a,n){n=!!n;var i=new RegExp("(\\?|\\&)"+e+"=.*?(?=(&|$))"),o="",r="";return-1!==t.indexOf("#")&&(o=t.split("#"),t=o[0],r=o[1]),i.test(t)?t=t.replace(i,"$1"+e+"="+a):/\?.+$/.test(t)?t+=n?encodeURIComponent("&"+e+"="+a):"&"+e+"="+a:(t+="?"+e+"=",t+=n?encodeURIComponent(a):a),""!==r&&(t+="#"+r),t}})(),$((function(){var t={cardStyles:["NM","EX","VG","G"]};window.ckCatalog=window.ckCatalog||{},$(document).on("touchend click",".cardTypeList > li:not(.active)",(function(){var e=_.intersection(this.classList,t.cardStyles);e.length>0&&(e="."+e[0]);var a=$(this).parent(),n=a.siblings(".addToCartByType");n.find(".active").removeClass("active"),n.find(e).addClass("active"),a.find("li.active").removeClass("active"),a.find(e).addClass("active")})),$(document).on("show.bs.dropdown",".addToCartForm .dropdown",(function(t){var e=$(t.relatedTarget).parents(".addToCartForm"),a=parseInt(e.find("input[name=qty]").val());if(e.find(".picked").removeClass("picked"),a>=0){var n="li:nth-child("+(a+1)+")";e.find(n).addClass("picked")}})),$(document).on("touchend click",".addToCartForm .qtyList > li",(function(e){var a=parseInt($(this).text());isNaN(a)&&(a=0),t.updateSelectedQty(this,a)})),$(document).on("click",".addToCartForm:not(.maxxed) .addOneButton, .addToCartForm:not(.maxxed) .addItemToCart",(function(){var e=parseInt($(this).parents("form").find(".qty").val())||0;e++,t.updateSelectedQty(this,e)})),$(document).on("click",".addToCartFormBulk .addItemToCartBulk",(function(){t.processBulkInput(this)})),$(document).on("keydown",".addToCartFormBulk .qty",(function(e){13==e.keyCode&&(e.preventDefault(),t.processBulkInput(this))})),t.processBulkInput=function(e){var a=parseInt($(e).parents("form").find(".qty").val())||0,n=parseInt($(e).parents("form").find(".maxQty").val())||0;if($(e).parents("form").find(".warning").remove(),a>n){var i='<div class="warning">Max quantity is '+n+".</div>";$(e).parents("form").append(i)}else t.updateSelectedQty(e,a)},$(document).on("click",".removeAll",(function(){t.updateSelectedQty(this,0)})),$(document).on("cartUpdated.ck",(function(e){var a=window.ckCatalog.cart(),n=a.items;t.populateFormQty(a),Object.keys(n).forEach((function(t){var e="."+t;if($(e).length>0){var a=n[t].qty||0,i=parseInt($(e).find("input[name=maxQty]").val());$(e).find("input[name=qty]").val(a),a>=i&&$(e).addClass("maxxed")}}))})),t.cartSet=_.debounce((function(e){t.submitUpdate(e)}),500),t.updateSelectedQty=function(e,a){$(document).trigger("cartStartUpdate.ck");var n=$(e).parents("form"),i={};i.category=n.find("input[name=category]").val(),i.model=n.find("input[name=model]").val(),i.name=n.find("input[name=name]").val(),i.slug=n.find("input[name=slug]").val(),i.title=n.find("input[name=title]").val(),i.variation=n.find("input[name=variation]").val()||"",i.currentCount=parseInt(n.find(".qty").val())||0,i.id=n.find(".product_id").val(),i.style=n.find(".style").val(),i.qty=parseInt(a||0),i.mode=$("body").hasClass("purchasing")?"sell-cart":"";var o=n.find("input[name=price_sale]").val()||"";i.price=o.length>0?o:n.find("input[name=price]").val(),i.callback=function(t,e){if(void 0!==e){e=Math.max(0,e);var o=n.parent();n.find(".maxQty").val(e),n.find(".qty").val(e),o.find(".styleQty").text(e),o.find(".qtyList").children().filter((function(t){return t>e})).remove()}var r=parseInt(n.find(".maxQty").val())||0;n.find("input[name=qty]").val(a),a>=r&&n.addClass("maxxed"),t?(i.cart=t,$(document).trigger("updateCart.ck",[i])):$(document).trigger("cartUpdated.ck",[window.ckCatalog.cart()])},t.cartSet(i)},t.getReturnedQty=function(t,e){var a=e[_.findKey(e,(function(e){return e.product_id==t.id&&e.style==t.style}))]||{};return parseInt(a.qty||0)},t.submitUpdate=function(t){var e,a=t.style||"",n=parseInt(t.qty),i="",o="sellcart"===t.mode||$("body").hasClass("purchasing")?"sell-cart":"buy-cart",r={product_id:t.id,style:a,quantity:n};i="sell-cart"===o?"/api/sellcart/add":"/api/cart/add",this.makeRequest(i,"POST",r).then((function(a){try{e=JSON.parse(a.responseText)}catch(e){$(document).trigger("notify.ck",{message:"There was a problem adding &quot;"+t.title+" - "+t.style+"&quot; to the cart. Please refresh the page, and try again.",severity:"error"})}"function"==typeof t.callback&&t.callback(e)}),(function(e){var a,i="There was a problem adding &quot;"+t.title+" - "+t.style+"&quot; to the cart. Please refresh the page, and try again.";if(e&&e.context&&e.context.exception&&"MaxQuantityExceeded"===e.context.exception){var o=e.context.available;void 0!==o&&(a=o,o<=0&&(o=0),i="Couldn't add "+n+" x &quot;"+t.name+"&quot; ("+t.style+") to the cart; amount available has reduced to "+o+".")}$(document).trigger("notify.ck",{message:i,severity:"error"}),"function"==typeof t.callback&&t.callback(void 0,a)}))},t.makeRequest=function(t,e,a){var n=new XMLHttpRequest;return new Promise((function(i,o){n.onreadystatechange=function(){if(4===n.readyState)if(n.status>=200&&n.status<300)i(n);else{var t;try{t=JSON.parse(n.responseText)}catch(e){t=null}o({status:n.status,statusText:n.statusText,context:t})}},n.open(e||"GET",t,!0),n.setRequestHeader("Content-Type","application/json;charset=UTF-8"),n.setRequestHeader("Accept","application/json;charset=UTF-8"),n.send(JSON.stringify(a))}))},t.populateFormQty=function(t){var e=t.hasOwnProperty("fullItems")&&t.fullItems?t.fullItems:t.items;$itemForms=$(".addToCartForm");var a=function(t){var a=e[t];$itemForms.each((function(t,e){a.product_id==$(e).find(".product_id").val()&&a.style===$(e).find(".style").val()&&($(e).find("input[name=qty]").val(a.qty),parseInt(a.qty)>0?(_text='<span class="inCartDesc">'+a.qty+" in Cart</span>",$(e).find(".removeAll").addClass("avail")):($("body").hasClass("purchasing")?_text="<span>Qty to Sell</span>":_text="<span>Add to Cart</span>",$(e).find(".removeAll").removeClass("avail")),$(e).find(".addToCartButton").html(_text))}))};for(var n in e)a(n)}})),(()=>{function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}var e;window.ckCatalog=window.ckCatalog||{},window.ckCatalog.cart=((e={cartData:{}}).cartData.items={},e.getCart=function(t){var a="sell-cart"===t?"/api/sellcart":"/api/cart";a=a+"?v="+(new Date).getTime().toString(24);var n=new XMLHttpRequest;n.onreadystatechange=function(){if(4==this.readyState&&200==this.status){try{cartData=JSON.parse(this.responseText)}catch(t){$(document).trigger("notify.ck",{message:"There was a problem loading your cart. Please refresh the page before adding items to your cart.",severity:"warn"})}e.updateCart(cartData)}},n.open("GET",a,!0),n.send()},e.updateCart=function(a){for(var n=(a.cart||a).lineitems||[],i={},o=0;o<n.length;o++){var r=n[o];r.product_id==a.id&&0==a.qty?(r.touched=!0,r.qty=0):(r.touched=r.product_id==a.id,i[r.id+("string"==typeof r.style&&r.style.length>0?"-"+r.style:"")]=r),void 0!==t(a.qty)&&0===a.qty&&(e.cartData.fullItems=_.map(e.cartData.items,(function(t){return a.id==t.product_id&&(t.touched=!0,t.qty=0),t})))}e.cartData.items=i,$(document).trigger("cartUpdated.ck",[e.cartData]),delete e.cartData.fullItems},$((function(){$(document).on("updateCart.ck",(function(t,a){e.updateCart(a)}));var t=$("body").hasClass("purchasing")?"sell-cart":"buy-cart";e.getCart(t)})),function(){return $.extend(!0,{},e.cartData)})})(),_.templateSettings.interpolate=/{{([\s\S]+?)}}/g,t={},e=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}),t.cartType=$("body").hasClass("purchasing")?"sell":"buy",t.buildSideCart=function(e){var a=["game","product"],n=["mtg_card","mtg_foil","mtg_intl"],i="/cart",o="/checkout",r="View Cart";e.productListData={};var s=e.items;"sell"!==t.cartType&&(s=_.sortBy(s,(function(t){return[t.title,t.product.model,t.edition,t.name]}))),Object.keys(s).forEach((function(t){if($.inArray(s[t].product.model,a)>=0){var n={};n.id=s[t].product_id||s[t].id,n.qty=s[t].qty,n.name=s[t].name,n.price=parseFloat(s[t].price).toFixed(2),n.style=s[t].style,n.touched=s[t].touched,n.uri=s[t].product.uri,void 0!==s[t].ship_date&&s[t].ship_date.length>1&&(n.ship_date=s[t].ship_date),e.productListData[t]=n}})),e.cardListData={},Object.keys(s).forEach((function(t){if($.inArray(s[t].product.model,n)>=0){var a={};a.id=s[t].product_id||s[t].id,a.model=s[t].product.model,a.qty=s[t].qty,a.name=s[t].title,a.price=parseFloat(s[t].price).toFixed(2),a.style=s[t].style,a.edition=s[t].edition,s[t].variation=s[t].variation,a.touched=s[t].touched,a.uri=s[t].product.uri,void 0!==s[t].ship_date&&s[t].ship_date.length>1&&(a.ship_date=s[t].ship_date),a.qty>0&&(e.cardListData[t]=a)}})),"sell"==t.cartType&&(i="/sellcart",o="/scheckout?dest=/scheckout",r="View Sell Cart"),e.cartlinks='<div class="cartLinks"><a href="'+i+'" data-dd-action-name="Sidecart View Cart">'+r+'</a> | <a href="'+o+'" data-dd-action-name="Sidecart Checkout">Checkout</a></div>',e.subtotal=t.calculateSubTotal(s),e.itemCount="("+t.calculateCount(s)+" items)",e.productList=t.buildProductListForSideCart(e.productListData),e.cardList=t.buildCardListForSideCart(e.cardListData),e.hasitems=Object.keys(e.productListData).length>0||Object.keys(e.cardListData).length>0?"hasitems":"",e.checkoutUrl=o;var c=t.sideCartCompileTemplate({cartData:e});$("#sideCart").html(c)},t.calculateSubTotal=function(t){var a=0;return Object.keys(t).forEach((function(e){a+=parseInt(t[e].qty)*parseFloat(t[e].price)})),e.format(a)},t.calculateCount=function(t){var e=0;return Object.keys(t).forEach((function(a){e+=parseInt(t[a].qty)})),e},t.sideCartCompileTemplate=_.template('<div class="sideCart {{cartData.hasitems}}">        <h5><span class="buyCartTitle">Shopping Cart</span><span class="sellCartTitle">Items I Am Selling</span></h5>        <div class="itemCount">{{cartData.itemCount}}</div>        <div class="subtotal">Subtotal: {{cartData.subtotal}} USD</div>        <div class="processingSpinner sideCartSpinner"></div>        <div class="cartLinks">{{cartData.cartlinks}}</div>        <table class="sideCartList">        {{cartData.productList}}        {{cartData.cardList}}        </table>        <a href="{{cartData.checkoutUrl}}" class="checkoutButton" data-dd-action-name="Secure Checkout"><span class="glyphicon glyphicon-lock"></span><span class="secure">SECURE </span><span>CHECKOUT</span><span class="glyphicon glyphicon-triangle-right"></span></a>    </div>'),t.buildProductListForSideCart=function(a){var n,i,o,r,s,c,d=$("<div></div>");return Object.keys(a).forEach((function(l){var u=a[l];u.qty>0&&(c=u.ship_date||"",s="",c.length>1&&(s='<div class="preorder"><span class="glyphicon glyphicon-info-sign"></span> Available '+c+'<span class="fullRestrictions"><span class="glyphicon glyphicon-info-sign"></span> <b>Available '+c+"</b><br>This product will be available on "+c+".  <br><b>Please place in-stock items or items released earlier on a separate order if you want them shipped sooner.</b> </span></div>"),i=Number(u.price),i=e.format(i.toFixed(2)),o=u.touched?"touched":"",u.id,r="&nbsp"+(u.style||""),n="sell"==t.cartType?'<tr valign=top class="productDescription '+o+'"><td align=center>'+u.qty+"</td><td align=left>"+u.name+r+s+"</td><td align=right>"+i+"</td></tr>\n":'<tr valign=top class="productDescription '+o+'"><td align=center>'+u.qty+'</td><td align=left><a href="/'+u.uri+'">'+u.name+r+"</a>"+s+"</td><td align=right>"+i+"</td></tr>\n",d.append(n))})),d.html()},t.buildCardListForSideCart=function(a){var n,o,r,s,c,d,l=[],u={},p={},m="",f=$("<div></div>");for(Object.keys(a).forEach((function(e){var n=a[e];if(n.qty>0){var i="sell"==t.cartType?n.edition:n.name,o=encodeURIComponent(i);void 0===u[o]&&((p={}).name=i,p.items=[],u[o]=p),u[o].items.push(n)}})),Object.keys(u).forEach((function(t){l.push(u[t])})),i=0;i<a.length;i++)if(a[i].qty>0){var h=a[i].name,y=encodeURIComponent(h);void 0===u[y]&&((p={}).name=h,p.items=[],u[y]=p),u[y].items.push(a[i])}return Object.keys(l).forEach((function(a){var u=l[a];o='<tr class="cardTitle"><td colspan="3">'+u.name+"</td></tr>",f.append(o);var p=u.items;for(i=0;i<p.length;i++)if(p[i].qty>0){r=Number(p[i].price),r=e.format(r.toFixed(2)),d=p[i].ship_date||"",c="",d.length>1&&(c='<div class="preorder"> Available '+d+'<span class="fullRestrictions"> <b>Available '+d+"</b><br>This product will be available on "+d+".  <br><b>Please place in-stock items or items released earlier on a separate order if you want them shipped sooner.</b> </span></div>"),n="",s="",p[i].variation&&p[i].variation.length>0&&(s=" - "+p[i].variation),p[i].id,"mtg_foil"===p[i].model&&(n='<span class="foil">FOIL</span>'),m=p[i].touched?"touched":"";var h=void 0;"sell"==t.cartType?h=p[i].name+s:(h=p[i].edition,p[i].style&&(h+=" ("+p[i].style+")")),h+=n,o='<tr valign="top"  class="productDescription '+m+'"><td align=center>'+p[i].qty+'</td><td align=left><a href="/'+p[i].uri+'">'+h+"</a>"+c+"</td><td align=right>"+r+"</td></tr>\n",f.append(o)}})),f.html()},$(document).on("cartStartUpdate.ck",(function(){$("#sideCart .subtotal, #sideCart .itemCount").css({opacity:.1}),setTimeout((function(){parseFloat($("#sideCart .subtotal").css("opacity"))<1&&$("#sideCart .processingSpinner").addClass("activate")}),300)})),$(document).on("cartUpdated.ck",(function(e){t.buildSideCart(window.ckCatalog.cart()),$("#sideCart .subtotal, #sideCart .itemCount").css({opacity:1}),setTimeout((function(){$("#sideCart .processingSpinner").removeClass("activate")}),300)})),function(t){t((function(){var e=0;t(".ckExpand:not(:hidden) input, .ckExpand:not(:hidden) select").each((function(a,n){e++,t(n).attr("tabindex",+e)})),n()}));var e=_.throttle((function(e){var a=t(e.target).parents(".ckExpand");t(e.target).hasClass("ckTooltip")?t(".ckTooltip").css({display:"none"}):t(e.target).hasClass("ckHelp")||a.toggleClass("open")}),300,{leading:!1,trailing:!0}),a=_.throttle((function(e){if(t("body").outerWidth()<=1200){var a=t(window).height()-t(".header").height();t("body #search.sidesearch").css({height:a})}else t("body #search.sidesearch").css({height:"auto"})})),n=function(){t(".includeColors.cardColor input:checked").length>0?t("#colorContainer").addClass("colorIsSet"):(t("#colorContainer").removeClass("colorIsSet"),t(".includeCount input").each((function(e,a){t(a).prop("checked",!1)})))};t(window).on("resize",(function(){a()})),a(),t(document).on("touchend click",'#search.sidesearch .ckExpand:not(".alwaysOpen") .title',(function(t){e(t)})),t(document).on("focus",".ckExpand input, .ckExpand select",(function(e){t(this).parents(".ckExpand").addClass("open")})),t(document).on("touchstart","#search",(function(e){t(e.target).hasClass("ckHelp")||t(".ckTooltip").css({display:"none"})})),t(document).on("click",".sliderTabToggle",(function(){t(this).parent().toggleClass("open")})),t(document).on("click","#sideSearchExpandAll",(function(e){e.preventDefault(),"all"===t(this).data("expand")?(t(".sidesearch .filterHeader.ckExpand:not(.alwaysOpen)").removeClass("open"),t(this).data("expand","").text("Expand All")):(t(".sidesearch .filterHeader.ckExpand").addClass("open"),t(this).data("expand","all").text("Collapse All (-)"))})),t(document).on("input","#filterTypeInput",(function(e){this.value.length>0?t("#filterTypeValue").prop("checked",!0):t("#filterTypeValue").prop("checked",!1)})),t(document).on("change keyup","#search *",(function(e){var a=t(this),n=a.parents(".filterHeader");a.hasClass("editionToggle")||n.hasClass("editionToggle")||a.hasClass("formatToggle")||n.hasClass("formatToggle")?t("#search").submit():(a.addClass("edited"),setTimeout((function(){a.find(".sideSearchApply").css("opacity",1)}),0))})),t(document).on("change",".includeColors input",(function(t){n()}))}(jQuery),$((function(){$(document).on("touchend click",".catalogItem .searchIcon",(function(t){t.preventDefault();var e=$(t.target).parents(".productItemWrapper");e.hasClass("zoomItem")?(e.removeClass("zoomItem"),e.find(".cardLink").removeClass("zoomed")):(e.addClass("zoomItem"),e.find(".cardLink").addClass("zoomed"))}))}))})();
//# sourceMappingURL=catalogView.js.map