var Lang;(function(n){var t;(function(t){function r(){return{restrict:"E",replace:!0,templateUrl:"/Content/lang/mini-cart/MiniCart.Desktop.Trigger.TMPL.html",scope:!1,controller:"langMiniCartController"}}function u(){return{restrict:"E",replace:!0,templateUrl:"/Content/lang/mini-cart/MiniCart.Desktop.Target.TMPL.html",scope:!1,controller:"langMiniCartController"}}function f(){return{restrict:"E",replace:!0,templateUrl:"/Content/lang/mini-cart/MiniCart.Mobile.Trigger.TMPL.html",scope:!1,controller:"langMiniCartController"}}function e(){return{restrict:"E",replace:!0,templateUrl:"/Content/lang/mini-cart/MiniCart.Mobile.Target.TMPL.html",scope:!1,controller:"langMiniCartController"}}function o(){return{restrict:"E",replace:!0,templateUrl:"/Content/lang/mini-cart/MiniCart.Legacy.TMPL.html",scope:!1,controller:"langMiniCartController"}}function s(){return{restrict:"A",link:function(n,t,i){t.on("click",function(){var t=i.langMiniCartToggleCart.toLocaleLowerCase(),n=angular.element("#mini-cart"),r=angular.element("#mini-cart-desktop");t==="true"?(n.addClass("active open"),r.addClass("open")):t==="false"?(n.removeClass("active open"),r.removeClass("open"),$.event.trigger("lang:mobile-popout-close")):n.dropdown("toggle")})}}}var i=function(){function t(n,t,i,r,u,f){var e=this;this.$scope=n;this.langSecurity=t;this.langMiniCartService=i;this.$window=r;this.$timeout=u;this.langDialogueService=f;this.loaded=!1;r.addEventListener("load",function(){u(function(){e.loaded=!0},100,!1)});this.$scope.CartItems=[];n.$watchCollection(function(){return i.GetItems()},function(n,t,i){var r,u;i.CartItems=n;e.loaded&&(r=angular.element("#mini-cart-desktop"),r.addClass("open"),u=angular.element("#mini-cart"),u.addClass("active open"))});n.minicart=this}return t.prototype.HasUser=function(){return this.langSecurity.Session!==null?!0:!1},t.prototype.IsGuest=function(){return this.langSecurity.HasUser()?this.langSecurity.UserInRole(n.Security.Roles.Guest):!1},t.prototype.IsMember=function(){return this.langSecurity.HasUser()?this.langSecurity.UserInRole(n.Security.Roles.Member):!1},t.prototype.CartHasItems=function(){return this.$scope.CartItems.length>0},t.prototype.RemoveItemClick=function(n){this.langMiniCartService.RemoveItem(n)},t.prototype.EmptyCartClick=function(){var t=this;this.langMiniCartService.EmptyCart().then(function(){t.$scope.$emit(n.Config.CartItemRemovedEvent);t.$scope.$broadcast(n.Config.CartItemRemovedEvent)})},t.prototype.CheckoutClick=function(){var r=this,i=function(){r.$window.location.href="/cart"},t;this.langSecurity.UserInRole(n.Security.Roles.Member)?i():(this.langSecurity.SuccessEventCue=[],t=new n.Security.SuccessEvent,t.EventType=n.Security.SuccessEventType.Checkout,t.Data={callback:i},this.langSecurity.SuccessEventCue.push(t),this.langDialogueService.OpenLoginToBuy())},t.prototype.LogoutClick=function(){this.langSecurity.Logout()},t.$inject=["$scope","langSecurity","langMiniCartService","$window","$timeout","langDialogueService"],t}();t.Controller=i;t.DesktopViewTrigger=r;t.DesktopViewTarget=u;t.MobileViewTrigger=f;t.MobileViewTarget=e;t.MiniCartView=o;t.ToggleCart=s})(t=n.MiniCart||(n.MiniCart={}))})(Lang||(Lang={}));Lang.App.controller("langMiniCartController",Lang.MiniCart.Controller);Lang.App.directive("langMiniCartDesktopViewTrigger",[Lang.MiniCart.DesktopViewTrigger]);Lang.App.directive("langMiniCartDesktopViewTarget",[Lang.MiniCart.DesktopViewTarget]);Lang.App.directive("langMiniCartMobileViewTrigger",[Lang.MiniCart.MobileViewTrigger]);Lang.App.directive("langMiniCartMobileViewTarget",[Lang.MiniCart.MobileViewTarget]);Lang.App.directive("langMiniCartView",[Lang.MiniCart.MiniCartView]);Lang.App.directive("langMiniCartToggleCart",[Lang.MiniCart.ToggleCart]),function(n){var t;(function(t){var u=function(){function t(t,i,r,u,f,e,o){var s=this,h,c;this.$rootScope=t;this.$http=i;this.$q=r;this.$window=u;this.langSecurity=f;this.langDialogueService=e;this.MiniCartResource=o;this.Items=[];amplify.subscribe(n.Config.AddToBasket,function(n,t){s.AddItem(n.BasketId,n.Quantity).then(function(){t&&t()})});amplify.subscribe("PostToCart",function(n,t){n!=null?s.$http.post("/api/CartItems/",n).then(function(){s.GetMiniCart().then(function(){t&&t()})}):s.$http.post("/api/ShippingOrders/websendalltocart/",n).then(function(){s.GetMiniCart().then(function(){t&&t()})})});h=function(){return s.langSecurity.HasUser()};c=function(){return s.langSecurity.HasSession()};this.$rootScope.$watchGroup([h,c],function(n,t){(n[0]==!0&&t[0]==!1||n[1]==!0)&&s.GetMiniCart()});this.$rootScope.$on(n.Config.RefreshCartEvent,function(){s.GetMiniCart()})}return t.prototype.GetItems=function(){return this.Items},t.prototype.GetMiniCart=function(){var t=this,n=this.$q.defer();return this.MiniCartResource.Get(function(i){t.Items=i.Items?i.Items:[];n.resolve(i)},function(i){t.Items=[];n.reject(i)}),n.promise},t.prototype.GetFullCart=function(){var n=this.$q.defer();return this.$http.get("/api/minicart/summary/").then(function(t){n.resolve(t.data)},function(t){n.reject(t)}),n.promise},t.prototype.AddItem=function(n,t){var r=this,i=this.$q.defer(),u=JSON.stringify({BasketId:n,Quantity:t});return this.MiniCartResource.AddItem(u,function(n){r.Items=n.Items?n.Items:[];i.resolve(n)},function(n){n.status==409&&r.langDialogueService.OpenModal("Item Out Of Stock","It appears that this item has already been purchased.");i.reject(n)}),i.promise},t.prototype.UpdateItem=function(n,t,i){var r=this.$q.defer(),u={cartId:n,cartItemId:t,qty:i};return this.MiniCartResource.UpdateItem(u,function(n){console.log(n);r.resolve(n)},function(n){console.log(n);r.reject(n)}),r.promise},t.prototype.RemoveItem=function(t){var r=this,i;return t===null&&n.Exception.Raise("You have to supply an item id"),i=this.$q.defer(),this.MiniCartResource.RemoveItem({cartItemId:t},function(n){r.Items=n.Items?n.Items:[];i.resolve(n)},function(n){r.Items=[];i.reject(n)}),i.promise},t.prototype.EmptyCart=function(){var t=this,n=this.$q.defer();return this.MiniCartResource.Empty(function(i){t.Items=i.Items?i.Items:[];n.resolve(i)},function(t){n.reject(t)}),n.promise},t.prototype.ApplyVoucher=function(n,t){var i=this.$q.defer(),r={cartId:n,voucherCode:t};return this.$http.post("/api/minicart/ApplyVoucher/",r).then(function(n){i.resolve(n.data)},function(n){i.reject(n)}),i.promise},t.prototype.RemoveVoucher=function(n){var t=this.$q.defer();return this.$http.delete("/api/minicart/RemoveVoucher/"+n).then(function(n){t.resolve(n.data)},function(n){t.reject(n)}),t.promise},t.prototype.BidOnLot=function(t){var i=this,r=this.$q.defer(),u="/api/Auctions/"+t.AuctionId+"/Lots/"+t.LotNumber+"/Bids",f=JSON.stringify({BidTypeId:3,IsAutoBid:!0,PriceBid:t.BidMine||0,StockId:t.StockId,ContactId:this.langSecurity.Session.ContactId});return this.$http({url:u,method:"POST",data:f}).success(function(){i.$rootScope.$broadcast(n.Config.RibbonEvent);r.resolve()}).error(function(n){if(n.LogicErrors.length>0){var t=Langtons.Global.Utils.getDialogContentFromBidErrors(n.LogicErrors);i.langDialogueService.OpenModal(t.dlgTitle,t.dlgBody)}else i.langDialogueService.OpenModal(Langtons.Global.Configuration.DEFAULT_BID_ERROR_DLG_TITLE,Langtons.Global.Configuration.DEFAULT_BID_ERROR_DLG_BODY);r.reject()}),r.promise},t.$inject=["$rootScope","$http","$q","$window","langSecurity","langDialogueService","MiniCartResource"],t}(),i,r;t.Service=u;i=function(){function n(){}return n}();t.Cart=i;r=function(){function n(){}return n}();t.CartItem=r})(t=n.MiniCart||(n.MiniCart={}))}(Lang||(Lang={}));Lang.App.service("langMiniCartService",Lang.MiniCart.Service);Lang.App.factory("MiniCartResource",["$resource",function(n){return n("/api/minicart/:cartItemId",null,{Get:{method:"GET"},RemoveItem:{method:"DELETE"},Empty:{method:"DELETE"},AddItem:{method:"POST"},UpdateItem:{method:"PATCH"}})}]),function(n){var t;(function(t){var i=function(){function t(n,t,i,r,u){this.$scope=n;this.langMiniCartService=t;this.langDialogueService=i;this.$window=r;this.langSecurity=u;this.FinishedLoad=!1;this.IsQtyLoading=!1;this.Voucher={Code:"",HasError:!1,ErrorMessage:"",Applied:!1};this.$scope.Cart=this;this.ConfigureWatches();this.LoadData()}return t.prototype.ConfigureWatches=function(){var n=this;this.$scope.$watch("Cart.langSecurity.HasUser()",function(t,i){t==!0&&i==!1&&n.LoadData()})},t.prototype.LoadData=function(){var n=this;this.langMiniCartService.GetFullCart().then(function(t){n.FinishedLoad=!0;console.log("this.FinishedLoad",n.FinishedLoad);n.RawData=t},function(){n.FinishedLoad=!0;n.langDialogueService.OpenModal("Error getting cart","There was a problem in getting your cart please try later.",function(){n.$window.location.assign("/")})})},t.prototype.ItemQuantityUpdated=function(n){var t=this;this.IsQtyLoading=!0;this.langMiniCartService.UpdateItem(this.RawData.CartId,n.CartItemId,n.QtyPurchased).then(function(n){t.RawData=n;t.IsQtyLoading=!1},function(n){t.IsQtyLoading=!1;n.status==409?t.langDialogueService.OpenModal("Item Out Of Stock","It appears that this item has already been purchased.",function(){t.LoadData()}):n.status==412&&(console.log(n.data),t.langDialogueService.OpenModal("Error",n.data[0],function(){t.LoadData()}))})},t.prototype.RemoveItemClick=function(t){var i=this;this.FinishedLoad=!1;this.langMiniCartService.RemoveItem(t).then(function(n){i.FinishedLoad=!0;i.RawData=n},function(t){t.status==412?i.langDialogueService.OpenModal("Voucher error","Did not meet minimum requirements for the voucher.",function(){i.LoadData()}):n.Exception.Raise("Could not remove item from cart"+t)})},t.prototype.ApplyVoucherClick=function(){var n=this;this.Voucher.Code!=""&&(this.Voucher.HasError=!1,this.langMiniCartService.ApplyVoucher(this.RawData.CartId,this.Voucher.Code).then(function(t){n.RawData=t;n.Voucher.ErrorMessage=""},function(t){n.Voucher.HasError=!0;n.Voucher.ErrorMessage=t.data.Message}))},t.prototype.RemoveVoucherClick=function(){var n=this;this.langMiniCartService.RemoveVoucher(this.RawData.CartId).then(function(t){n.RawData=t},function(){})},t.$inject=["$scope","langMiniCartService","langDialogueService","$window","langSecurity"],t}();t.Controller=i})(t=n.Cart||(n.Cart={}))}(Lang||(Lang={}));Lang.App.controller("langCartCtrl",Lang.Cart.Controller),function(n){var t;(function(t){var i=function(){function t(n,t){this.$http=n;this.$q=t}return t.prototype.GetItems=function(){var n=this.$q.defer();return this.$http({url:"/api/ShoppingCart/MyItems",method:"GET"}).success(function(t){n.resolve({data:t})}).error(function(){n.reject()}),n.promise},t.prototype.GetCheckout=function(){var n=this.$q.defer();return this.$http.get("/api/checkout/").then(function(t){n.resolve(t.data)},function(t){n.reject(t)}),n.promise},t.prototype.UpdateItem=function(n){var t=this.$q.defer();return this.$http({url:"api/ShoppingCart/PatchCartItem",method:"PATCH",contentType:"application/json",data:n}).success(function(n){t.resolve({data:n})}).error(function(){t.reject()}),t.promise},t.prototype.RemoveItem=function(n){var t=this.$q.defer(),i="/api/minicart/"+n.Id;return this.$http({url:i,method:"DELETE",dataType:"json",contentType:"application/json",data:n}).success(function(n){t.resolve({data:n})}).error(function(){t.reject()}),t.promise},t.prototype.ApplyVoucher=function(t){if(!t)throw new n.Exception("Argument not supplied exception");var i=this.$q.defer(),r={method:"PATCH",url:"/api/ShoppingCart/RedeemVoucherCode/",data:JSON.stringify({Code:t,Discount:0})};return this.$http(r).then(function(n){i.resolve(n.data)},function(n){i.reject(n)}),i.promise},t.$inject=["$http","$q"],t}();t.Service=i})(t=n.Cart||(n.Cart={}))}(Lang||(Lang={}));Lang.App.service("langCartService",Lang.Cart.Service),function(n){var t;(function(t){var i=function(){function t(t,i){var r=this;this.$scope=t;this.langStatusRibbonService=i;this.$scope.Ribbon=this;this.$scope.$on(n.Config.StatsUpdated,function(){r.RawData=r.langStatusRibbonService.Stats})}return t.prototype.ShowRibbon=function(){var n=!1;return this.RawData&&(this.RawData.Watching&&this.RawData.Watching>0&&(n=!0),this.RawData.Bidding&&this.RawData.Bidding>0&&(n=!0),this.RawData.SellingAll&&this.RawData.SellingAll>0&&(n=!0)),n},t.$inject=["$scope","langStatusRibbonService"],t}();t.RibbonController=i})(t=n.StatusRibbon||(n.StatusRibbon={}))}(Lang||(Lang={}));Lang.App.controller("langRibbonController",Lang.StatusRibbon.RibbonController),function(n){var t;(function(t){var i=function(){function t(t,i,r,u){var f=this,e;this.$http=t;this.$q=i;this.$rootScope=r;this.langSecurity=u;this.Stats=null;this.$rootScope.$on(n.Config.RibbonEvent,function(){f.GetStatus()});e=function(){return f.langSecurity.HasUser()};this.$rootScope.$watch(e,function(n){n==!0&&f.GetStatus()})}return t.prototype.GetStatus=function(){var i=this,t=this.$q.defer();return this.$http.get("/api/members/getstats").then(function(r){i.Stats=r.data;i.$rootScope.$broadcast(n.Config.StatsUpdated);t.resolve(r)},function(n){t.reject(n)}),t.promise},t.$inject=["$http","$q","$rootScope","langSecurity"],t}();t.Service=i})(t=n.StatusRibbon||(n.StatusRibbon={}))}(Lang||(Lang={}));Lang.App.service("langStatusRibbonService",Lang.StatusRibbon.Service)