"use strict";(function(n,t,i,r){function at(){vt();d.init();ei();var n=CommonFunction.getBranchId();n&&ri();u.on("click.menu-item","button.menu-item",rt);u.on("click.add-item","button.btn-add-item",et);u.on("click.add-item-img",".food-item .food-image img",et);u.on("click.category-link","a.category-link",hi);u.on("click.category-return","a.category-return",ci);d.$el.on("click.menuCategory","button.menu-item",rt);g.on("change",ai);lt.on("click",vi)}function vt(){fi();pt();a();yt();u.find(".category-food").data("InventoryItemCategoryID",AppContants.TopSellId);n(".menu-item.top-sell").data("data",{InventoryItemCategoryID:AppContants.TopSellId,ParentID:null,ItemCategoryCode:"BANCHAY",ItemCategoryName:resourcesHome.TopSell,Description:resourcesHome.TopSell,SortOrder:-1})}function yt(){}function a(){f&&f.ListInventoryItem&&f.ListInventoryItem.length?ti():ii()}function pt(){function u(f){return f&&(n++,f.condition()?(f.modal.result(function(){t=r;r=i[n+1];u(t)}),f.modal.show()):(t=r,r=i[n+1],u(t))),0}var i=[{modal:gi,condition:ni},{modal:wi,condition:kt},{modal:bi,condition:dt},{modal:ki,condition:wt},{modal:di,condition:bt}],n=0,t=i[n],r=i[n+1];u(t)}function wt(){return t}function bt(){return i}function kt(){var n=!1,f=config.branchs,t=CommonFunction.getCurrentBranch(),e=Number(CukStorage.get(LocalStorageKey.DeliveryType))==EnumDeliveryType.Ship,o=!config.showChooseBranch,r=gt(),i=f.filter(function(n){return n.ListDeliveryType.indexOf(EnumDeliveryType.Ship)>-1}),u=t.LocationID.toLowerCase()===AppContants.LocationVNId.toLowerCase();return e&&i&&(o?t.ListDeliveryType.indexOf(EnumDeliveryType.Ship)==-1?CukStorage.set(LocalStorageKey.DeliveryType,t.ListDeliveryType[0]):u&&!r&&(n=!0):i.length>1?n=!0:u&&!r?n=!0:CommonFunction.gotoBranchSite(i[0].BranchID)),n}function dt(){var t=!1,i=CukStorage.get(LocalStorageKey.DeliveryType),r=i==EnumDeliveryType.Store,u=!config.showChooseBranch,n=CommonFunction.getCurrentBranch();return r&&(u?n.ListDeliveryType&&n.ListDeliveryType.indexOf(EnumDeliveryType.Store)==-1&&CukStorage.set(LocalStorageKey.DeliveryType,n.ListDeliveryType[0]):t=!0),t}function gt(){var t=!1,n=CukStorage.get(LocalStorageKey.Location),i=CommonFunction.getCurrentBranch(),r=i.LocationID.toLowerCase()===AppContants.LocationVNId.toLowerCase();return n&&(!r||n.ProvinceId&&n.DistrictId)||(t=!0),t}function ni(){var n=!1,u=config.branchs,f=config.currentBranch,t=!config.showChooseBranch?nt([f]):nt(u),i,r;return t.length===1?(CukStorage.set(LocalStorageKey.DeliveryType,t[0]),n=!1):(i=CukStorage.get(LocalStorageKey.DeliveryType),r=CukStorage.get(LocalStorageKey.ClosedSelectDeliveryType),i!=null||r||(n=!0)),n}function nt(n){var t=[];return n&&n.length>0&&n.forEach(function(n){n.ListDeliveryType&&n.ListDeliveryType.forEach(function(n){t.indexOf(n)===-1&&t.push(n)})}),t}function v(){h.length>0&&h.show()}function s(){h.length>0&&h.hide()}function ti(){var t=n("#mobile-dock"),i=n("#btn-menu-category");i.css("bottom","80px");t.removeClass("d-none");n("body").addClass("mobile-dock")}function ii(){var t=n("#mobile-dock"),i=n("#btn-menu-category");t.addClass("d-none");i.css("bottom","25px");n("body").removeClass("mobile-dock")}function ri(){ui(function(t){var r,e;if(t&&t.length){var u=2,f=0,i=[];for(r=0;r<t.length;r++)if(i.length<u)i.push(t[r]);else break;i.length&&(e=c(),i.forEach(function(t){t&&t.InventoryItemCategoryID&&y(t.InventoryItemCategoryID,function(){if(f+=1,f==u){n(document).off("scroll.getNext").on("scroll.getNext",b);n(document).trigger("scroll.getNext")}},1,e)}))}})}function c(){var n=5,t=window.innerWidth;return t>EnumBreakPoint.xs&&(n=4),t>EnumBreakPoint.sm&&(n=3),t>EnumBreakPoint.lg&&(n=4),t>EnumBreakPoint.xl&&(n=5),n}function ui(t){var i=CommonFunction.getBranchId(),r=CommonFunction.stringFormat(ApiUrl.GetAllInventoryItemCategory,i);Http.get(r).then(function(i){var r,u;i&&i.Success&&(o=i.Data||[],o.length&&(r={InventoryItemCategoryID:AppContants.GuidEmpty,ParentID:null,ItemCategoryCode:"KHAC",ItemCategoryName:resourcesHome.OrtherCategory,Description:resourcesHome.OrtherCategoryDescription,SortOrder:i.Data.length},o.push(r),n("#menu-category .menu-item:not(.top-sell)").remove(),n(".menu-category-list .menu-item:not(.top-sell)").remove(),u=c(),o.forEach(function(t){var r=n("#btnMenuTemplate").tmpl(t),i,e,f,o;for(r.data("data",t),n("#menu-category").append(r),n(".menu-category-list").append(r),i=n("#categoryFood").tmpl(t),i.data("InventoryItemCategoryID",t.InventoryItemCategoryID),e=i.find(".category-main"),f=0;f<u;f++)o=n("#inventoryItemSkeleton").tmpl(),e.append(o);n("#app-home-main").append(i)})),t&&t(o))})}function y(t,i,r,u,f){if(t){r=r>0?r:1;u=u?u:10;f=f?f:"";var s=CommonFunction.getBranchId(),h=ApiUrl.GetPageInventoryItemsByCategory,c=CommonFunction.stringFormat(h,r,u,s,t,f),o=e(t);o.data("loadingDetail",!0);Http.get(c).then(function(r){var e,f;r&&r.Success&&(e=o.find(".category-main"),e.html(""),f=n(),r.Data.forEach(function(t){var i=n("#inventoryItem").tmpl(t);i.data("data",t);f=f.add(i)}),e.append(f),r&&r.Total<=u?w(t):p(t),i&&i(r));o.data("loadedDetail",!0)}).catch(function(n){i&&i(null,n)})}else i&&i(null,err)}function p(t){var u=e(t),i=u.find(".category-title"),r;i.length&&(i.find("a.category-link").remove(),r=n("<a><\/a>",{href:"#","class":"category-link"}).html(resourcesHome.ViewAll),i.append(r))}function w(n){var i=e(n),t=i.find("a.category-link");t.length&&t.remove()}function tt(t){var u=e(t),i=u.find(".category-title"),r;i.length&&(i.find("a.category-return").remove(),r=n("<a><\/a>",{href:"#","class":"category-return"}).html(resourcesCommon.Back),i.append(r))}function it(n){var i=e(n),t=i.find("a.category-return");t.length&&t.remove()}function fi(){var n=CukStorage.get(LocalStorageKey.CustomerTel);n&&CommonFunction.isValidPhone(n)&&ct.val(n)}function ei(){oi()}function oi(){ht.owlCarousel({loop:!0,autoplay:!0,autoplayHoverPause:!0,slideBy:"page",margin:20,items:5,nav:!0,responsiveRefreshRate:100,responsive:{0:{items:2,margin:10},576:{items:2},768:{items:3},992:{items:4},1200:{items:5}}})}function si(){var n=new nr;n.open()}function rt(t){var i=n(t.currentTarget),r=i.data("data"),u;r&&r.InventoryItemCategoryID&&(u=r.InventoryItemCategoryID,i=k(u),g.val(""),st(),i.hasClass("active")?ut(i):ft(i))}function ut(t){var o=t.data("data"),e=o.InventoryItemCategoryID,i,r,f;t.removeClass("active");n(document).on("scroll.getNext",b);p(e);it(e);i=u.find(".category-food");i.length&&(i.slideDown(),r=c(),r+=1,f=i.find(".category-main"),f.length&&f.find(".food-item:nth-child(n+"+r+")").remove())}function ft(t){var o=t.data("data"),f=o.InventoryItemCategoryID,r,i,u;n(document).off("scroll.getNext");t.addClass("active");t.siblings().removeClass("active");window.scrollTo({top:0,behavior:"smooth"});w(f);tt(f);r=t.data("data");r&&r.InventoryItemCategoryID&&(l=r.InventoryItemCategoryID,i=e(l),i&&i.length>0&&(i.slideDown(),i.siblings().hide(),u=i.find(".category-main"),u.length&&(u.html(""),v(),y(l,function(n,t){s();t&&Message.error(resourcesCommon.Error,resourcesCommon.ErrorMessage)},1,100))))}function et(t){var u,r,i,f,e,o;try{u=n(t.currentTarget);r=u.parents(".food-item");r.length&&(i=r.data("data"),i.IsOutOfStock||(f=r.data("loadDetail"),f?ot(i):i&&i.InventoryItemID?(e=i.InventoryItemID,o=CommonFunction.stringFormat(ApiUrl.GetInventoryItemDetailByID,e),v(),Http.get(o).then(function(t){s();t&&t.Success?(i=n.extend(i,t.Data),r.data("data",i),r.data("loadDetail",!0),ot(i)):Message.error(resourcesCommon.Error,resourcesCommon.ErrorMessage)}).catch(function(n){s();CommonFunction.handelException(n);Message.error(resourcesCommon.Error,resourcesHome.ErrorPickItemMessage)})):Message.error(resourcesCommon.Error,resourcesHome.ErrorPickItemMessage)))}catch(h){CommonFunction.handelException(h)}}function hi(t){try{t.preventDefault();var r=n(t.currentTarget),u=r.parents(".category-food"),i=u.data("InventoryItemCategoryID"),f=k(i);ft(f);tt(i);w(i)}catch(e){CommonFunction.handelException(e)}}function ci(t){try{t.preventDefault();var r=n(t.currentTarget),u=r.parents(".category-food"),i=u.data("InventoryItemCategoryID"),f=k(i);ut(f);it(i);p(i)}catch(e){CommonFunction.handelException(e)}}function b(){var i,t;try{i=n("#app-home-main").find(".category-food");i.length&&(t=[],n.each(i,function(i,r){n(r).visible(!0)?n(r).data("loadedDetail")||n(r).data("loadingDetail")||n(r).hasClass("top-sell")?n(r).data("loadingDetail")&&!n(r).data("loadedDetail")?n(r).addClass("animation"):n(r).removeClass("animation"):(n(r).addClass("animation"),t.push(r)):n(r).removeClass("animation")}),t.length>0&&li(t))}catch(r){CommonFunction.handelException(r)}}function ot(t){var r,u,i,f;if(t){r=t.InventoryItemType;u=n("#addInventoryItemModal");switch(r){case EnumInventoryItemType.Food:case EnumInventoryItemType.Drink:case EnumInventoryItemType.Other:case EnumInventoryItemType.DrinkMerge:i=n("#foodModalContent").tmpl(t);break;case EnumInventoryItemType.Combo:case EnumInventoryItemType.ComboCustom:i=n("#comboModalContent").tmpl(t);break;case EnumInventoryItemType.DrinkByGroup:case EnumInventoryItemType.FoodByGroup:i=n("#itemGroupModalContent").tmpl(t);break;case EnumInventoryItemType.FoodByMaterial:i=n("#materialModalContent").tmpl(t);break;default:console.log(r);i=n("#foodModalContent").tmpl(t)}u.find(".modal-body-content").html("").append(i);f=new pi(t);f.open()}}function li(t){if(t&&t.length){var i=c();t.forEach(function(t){var r=n(t).data(),u=r.InventoryItemCategoryID;y(u,function(){n(document).trigger("scroll.getNext")},1,i)})}}function e(t){var i,r=u.find(".category-food");return t&&n.each(r,function(r,u){var f=n(u),e=f.data();if(e&&e.InventoryItemCategoryID==t)return i=f,!1}),i}function k(t){var i=n(),r=n("button.menu-item");return t&&(i=r.filter(function(){return n(this).data("data")&&n(this).data("data").InventoryItemCategoryID==t})),i}function ai(t){var r,i;try{if(r=n(t.currentTarget),i=r.val().trim(),i){yi();n(document).off("scroll.getNext");n("#app-home-search .text-search").html(i);var u=ApiUrl.GetPageInventoryItemsByCategory,f=CommonFunction.getBranchId(),e=CommonFunction.stringFormat(u,1,1e3,f,"",i);v();Http.get(e).then(function(t){var r,i;s();t&&t.Success&&(r=n("#app-home-search .category-main"),r.html(""),i=n(),t.Data.forEach(function(t){var r=n("#inventoryItem").tmpl(t);r.data("data",t);i=i.add(r)}),r.append(i))}).catch(function(n){s();CommonFunction.handelException(n);Message.error(resourcesCommon.Error,resourcesCommon.ErrorMessage)})}else{st();n(document).on("scroll.getNext",b)}}catch(o){CommonFunction.handelException(o)}}function vi(){try{si()}catch(n){CommonFunction.handelException(n)}}function yi(){n("#app-home-main").hide();n("#app-home-search").show()}function st(){n("#app-home-main").show();n("#app-home-search").hide();n("#app-home-search").find(".category-main").html("")}function pi(t){function p(){if(i.find(".modal-footer .main-number.master-number").remove(),this.inventoryItem.InventoryItemType!=EnumInventoryItemType.DrinkByGroup&&this.inventoryItem.InventoryItemType!=EnumInventoryItemType.FoodByGroup){var t=n("#sltNumberFooter").tmpl();i.find(".modal-footer .container").prepend(t)}}function w(){this.inventoryItem.InventoryItemType==EnumInventoryItemType.FoodByMaterial?i.find(".cuk-select-number.master-number").numberSelect({minValue:0,decimal:!0}):i.find(".cuk-select-number.master-number").numberSelect({minValue:1});i.find(".cuk-select-number.detail-number").numberSelect({minValue:0})}function b(){k.call(this);r(this.inventoryItem);o(this.inventoryItem)}function o(n){var i=!1,t,r;n.InventoryItemType==EnumInventoryItemType.FoodByGroup||n.InventoryItemType==EnumInventoryItemType.DrinkByGroup?(t=n.InventoryItemByMaterial,t&&t.length?(r=t.some(function(n){return n&&n.BuyQuantity>0}),r||(i=!0)):i=!0):n.InventoryItemType==EnumInventoryItemType.FoodByMaterial?n.BuyQuantity<=0?i=!0:(t=n.InventoryItemByMaterial,t&&t.length?(r=t.some(function(n){return n&&n.BuyQuantity>0}),r||(i=!0)):i=!0):n.BuyQuantity<=0&&(i=!0);u.attr("disabled",i)}function k(){var n=this.inventoryItem;n.UnitPriceAddtion=n.UnitPrice||0;(n.InventoryItemType!=EnumInventoryItemType.DrinkByGroup||n.InventoryItemType!=EnumInventoryItemType.DrinkByGroup)&&(n.BuyQuantity=1);(n.InventoryItemType==EnumInventoryItemType.Combo||n.InventoryItemType==EnumInventoryItemType.ComboCustom)&&s(n)}function r(n){var t=0,r=[];n&&(r.push(n),t=CommonFunction.calculateTotalItemAmount(r),i.find(".item-amount").html(Formatter.amountFormat(t)))}function d(){var r=this,n;try{n=ot.call(this);i.modal("hide");n.InventoryItemType==EnumInventoryItemType.DrinkByGroup||n.InventoryItemType==EnumInventoryItemType.FoodByGroup?nt(n):g(n)}catch(t){CommonFunction.handelException(t)}}function g(t){if(t){var i=ApiUrl.AddCart+"?branchID="+CommonFunction.getBranchId();Http.post(i,t).then(function(i){var r,e,u,h,o,s;i&&i.Success?(f=i.Data,r=f.ListInventoryItem,e=CommonFunction.calculateTotalItemAmount(r),CommonFunction.showMessageAddCart(t),u=n(".number-products"),h=n("#mobile-dock .item-amount").html(Formatter.amountFormat(e)),u.length&&u.html(r.length),a()):(o=t.InventoryItemName,s=CommonFunction.stringFormat(resourcesHome.ErrorAddItemMessage,o),Message.error(resourcesCommon.Error,s))}).catch(function(){var n=t.InventoryItemName,i=CommonFunction.stringFormat(resourcesHome.ErrorAddItemMessage,n);Message.error(resourcesCommon.Error,i)})}}function nt(t){if(t&&t.InventoryItemByMaterial&&t.InventoryItemByMaterial.length){var i=t.InventoryItemByMaterial.filter(function(n){return n.BuyQuantity>0}),r=ApiUrl.AddCart+"?branchID="+CommonFunction.getBranchId();Http.post(r,t).then(function(t){var u,r,e,o;t&&t.Success?(f=t.Data,u=f.ListInventoryItem,CommonFunction.showMessageAddCart(i),r=n(".app-header .number-products"),r.length&&r.html(u.length),a()):(e=itemInfor.InventoryItemName,o=CommonFunction.stringFormat(resourcesHome.ErrorAddItemMessage,e),Message.error(resourcesCommon.Error,o))}).catch(function(){var n=itemInfor.InventoryItemName,t=CommonFunction.stringFormat(resourcesHome.ErrorAddItemMessage,n);Message.error(resourcesCommon.Error,t)})}}function tt(t){var f=this,r,i;try{r=n(t.currentTarget);i=r.parents(".combo-custom-item").find(".textarea-container");i.length&&i.slideToggle()}catch(u){CommonFunction.handelException(u)}}function it(t){try{var i=n(t.currentTarget),r=i.parents(".cukcuk-checkbox").next(".cuk-select-number"),u=i.is(":checked");u?r.css("visibility","visible"):r.css("visibility","hidden")}catch(f){CommonFunction.handelException(f)}}function rt(t){var i,u;try{i=n(t.currentTarget);i.length&&(u=i.numberSelect("value"),e.find("input").val(u),this.inventoryItem.BuyQuantity=u,this.inventoryItem&&this.inventoryItem.InventoryItemType==EnumInventoryItemType.Combo&&s(this.inventoryItem),r(this.inventoryItem))}catch(f){CommonFunction.handelException(f)}}function s(n){n&&n.InventoryItemByMaterial&&n.InventoryItemByMaterial.length&&n.InventoryItemByMaterial.forEach(function(t,r){t.BuyQuantity=t.Quantity*n.BuyQuantity;i.find(".combo-item-quantity").eq(r).html(t.BuyQuantity)})}function ut(t){var i,e,u,o;try{var f=n(t.currentTarget),s=f.find("input[type]").attr("name"),h=this.inventoryItem;if(f.length&&s){var a=f.numberSelect("value"),c=h.InventoryItemAdditionsCategory,l=!1;for(i=0;i<c.length;i++){for(e=c[i].InventoryItemAdditions,u=0;u<e.length;u++)if(o=e[u],o.InventoryItemAdditionID==s){o.BuyQuantity=a;l=!0;break}if(l)break}r(h)}}catch(v){CommonFunction.handelException(v)}}function ft(t){var h,i,u;try{var f=n(t.currentTarget),s=f.find("input[type]").attr("name"),e=this.inventoryItem;if(f.length&&s){if(h=f.numberSelect("value"),i=e.InventoryItemByMaterial,i&&i.length)for(u=0;u<i.length;u++)if(i[u].InventoryItemMaterialID==s){i[u].BuyQuantity=h;break}r(e);o(e)}}catch(c){CommonFunction.handelException(c)}}function et(t){var v,o,s,u,h,f,c;try{var i=n(t.currentTarget),l=i.attr("name"),a=this.inventoryItem,y=i.parents(".favorite-item-detail"),e=y.find(".cuk-select-number");if(i.length&&l){for(v=i.is(":checked"),v?e.numberSelect("value",1):e.numberSelect("value",0),o=a.InventoryItemAdditionsCategory,s=!1,u=0;u<o.length;u++){for(h=o[u].InventoryItemAdditions,f=0;f<h.length;f++)if(c=h[f],c.InventoryItemAdditionID==l){c.BuyQuantity=e.numberSelect("value");s=!0;break}if(s)break}r(a)}}catch(p){CommonFunction.handelException(p)}}function ot(){var n,u,f,t,r;return this.inventoryItem&&(n=ObjectClone(this.inventoryItem),n.UnitPriceAddtion=n.UnitPriceDelivery||0,u=i.find('.master-number input[name="foodQuantity"]'),f=i.find("textarea.note-master"),u.length&&(n.BuyQuantity=Number(u.val())),f.length&&(n.Note=f.val().trim()),t=n.InventoryItemAdditionsCategory,t&&t.length&&t.forEach(function(r,u){var f=r.InventoryItemAdditions;f&&f.length&&f.forEach(function(r,f){var o=i.find('input[name="'+r.InventoryItemAdditionID+'"][type="checkbox"]'),s,e,h;o&&o.is(":checked")?(s=i.find('input[name="'+r.InventoryItemAdditionID+'"][type="number"]'),e=Number(s.val())||0,t[u].InventoryItemAdditions[f].BuyQuantity=e,e&&r.UnitPrice&&(h=e*r.UnitPrice,n.UnitPriceAddtion+=h)):t[u].InventoryItemAdditions[f].BuyQuantity=0})}),r=n.InventoryItemByMaterial,r&&r.length&&n.InventoryItemType!=EnumInventoryItemType.Combo&&r.forEach(function(n,t){var u=i.find('input[type="number"][name="'+n.InventoryItemMaterialID+'"]'),f=i.find('textarea[name="'+n.InventoryItemMaterialID+'"]');u.length&&(r[t].BuyQuantity=Number(u.val()));f.length&&(r[t].Note=f.val().trim())})),n}var i;this.inventoryItem=ObjectClone(t);this.type=t.InventoryItemType;i=n("#addInventoryItemModal");p.call(this);var u=i.find(".btn-add-cart"),h=i.find(".btn-bill"),c=i.find('.favorite-item-detail input[type="checkbox"]'),e=i.find(".cuk-select-number.master-number"),l=i.find(".cuk-select-number.item-addtion"),v=i.find(".cuk-select-number.child-number"),y=i.find("input.ckb-item-addition");this.init=function(){w.call(this);b.call(this);u.off("click").on("click",d.bind(this));h.off("click").on("click",tt.bind(this));c.off("change").on("change",it.bind(this));e.off("change.numberSelect").on("change.numberSelect",rt.bind(this));l.off("change.numberSelect").on("change.numberSelect",ut.bind(this));v.off("change.numberSelect").on("change.numberSelect",ft.bind(this));y.off("change").on("change",et.bind(this))};this.init();this.setButotnAddCartDisabled=function(n){n?butotnAddCart.attr("disabled",!0):butotnAddCart.attr("disabled",!1)};this.close=function(){i.modal("hide")};this.open=function(){i.modal("show")}}function nr(){function c(){t.modal("hide")}function l(){t.modal("show")}function a(){e.show()}function s(){e.hide()}function v(){n.validator.addMethod("regex",function(n,t,i){var r=new RegExp(i);return this.optional(t)||r.test(n)});f.validate({rules:{"customer-tel":{required:!0,regex:AppContants.RegexValidatePhone}},messages:{"customer-tel":{required:resourcesCommon.PleaseInputTel,regex:resourcesCommon.InvalidTel}}})}function y(){r();p()}function p(){var n=CukStorage.get(LocalStorageKey.CustomerTel);n&&CommonFunction.isValidPhone(n)&&(o.val(n),h(n))}function r(){var t=n("#purchaseTutorialTemplate").tmpl({message:resourcesHome.InputTelToSearchOrder});i.html(t)}function w(t){var r=n("#purchaseTutorialTemplate").tmpl({message:CommonFunction.stringFormat(resourcesHome.NotOrderForTel,t)});i.html(r)}function b(){try{var n=o.val().trim();h(n)}catch(t){CommonFunction.handelException(t)}}function h(t){if(f.valid()){CukStorage.set(LocalStorageKey.CustomerTel,t);var u=ApiUrl.GetOrderOnlineHistoryOnday,e=CommonFunction.stringFormat(u,encodeURIComponent(t),CommonFunction.getBranchId);i.html("");a();Http.get(e).then(function(u){var e,f;s();u&&u.Success?(e=JSON.parse(u.Data),e.length?(f=n(),e.forEach(function(t){var i=k(t),r=n("#purchaseItemTemplate").tmpl(i);f=f.add(r)}),i.html(""),i.append(f)):w(t)):(Message.error(resourcesCommon.Error,resourcesCommon.ErrorMessage),r())}).catch(function(n){s();CommonFunction.handelException(n);Message.error(resourcesCommon.Error,resourcesCommon.ErrorMessage);r()})}else r()}function k(n){var t={},e;if(n){t=ObjectClone(n);var r=n.OrderDate,o=n.ConfirmStatus,s=n.OrderOnlineType,f=n.ListOrderOnlineDetail;if(r&&new Date(r)!=="Invalid Date"){var i=new Date(r),h=u(i.getHours(),2,"0"),c=u(i.getMinutes(),2,"0"),l=u(i.getDate(),2,"0"),a=u(i.getMonth()+1,2,"0"),v=i.getFullYear();t.OrderDateDisplay=CommonFunction.stringFormat("{0}:{1} - {2}/{3}/{4}",h,c,l,a,v)}if(o!=null)switch(o){case EnumConfirmStatusOrderOnline.Cancel:t.ConfirmStatusDisplay=resourcesCommon.OrderCancel;break;case EnumConfirmStatusOrderOnline.Confirm:t.ConfirmStatusDisplay=resourcesCommon.OrderConfirm;break;case EnumConfirmStatusOrderOnline.DeliveryInProcessing:t.ConfirmStatusDisplay=resourcesCommon.DeliveryInProcessing;break;case EnumConfirmStatusOrderOnline.DoneDelivery:t.ConfirmStatusDisplay=resourcesCommon.DoneDelivery;break;case EnumConfirmStatusOrderOnline.UnConfirm:t.ConfirmStatusDisplay=resourcesCommon.UnConfirm;break;case EnumConfirmStatusOrderOnline.WaitDelivery:t.ConfirmStatusDisplay=resourcesCommon.WaitDelivery;break;case EnumConfirmStatusOrderOnline.CompleteCook:t.ConfirmStatusDisplay=resourcesCommon.CompleteCook}if(f&&f.length&&(e=[],f.forEach(function(n){n.Quantity&&n.ItemName&&e.push(n.Quantity+"x "+n.ItemName)}),t.ListOrderOnlineDetailDisplay=e.join(", ")),s!=null)switch(s){case EnumDeliveryType.Ship:t.OrderOnlineTypeDisplay=resourcesCommon.DeliveryShip;break;case EnumDeliveryType.Store:t.OrderOnlineTypeDisplay=resourcesCommon.DeliveryStore}}return t}function u(n,t,i){return t=t>>0,i=String(typeof i!="undefined"?i:" "),n=String(n),n.length>t?String(n):(t=t-n.length,t>i.length&&(i+=i.repeat(t/i.length)),i.slice(0,t)+String(n))}var t=n("#viewPurchaseHistoryModal"),f=n("#frm-phone-history"),e=t.find(".modal-loading"),i=t.find(".list-purchase"),o=t.find(".search-input-tel");this.init=function(){v();y.call(this);f.off("submit").on("submit",b)};this.init();this.close=function(){c()};this.open=function(){l()}}var d;n(document).ready(function(){at()});var u=n("#app-home"),f=ObjectClone(r),o=[],l="",ht=u.find(".top-sell .owl-carousel"),ct=n('.app-header input[name="tel"]'),g=n("#inputSearch"),h=n("#app-loading"),lt=n("#dropdownCustomer");d=function(){function f(){i.off("click").on("click",e.bind(this));r.off("click.menuCategory").on("click.menuCategory",u.bind(this))}function e(){try{o()}catch(n){CommonFunction.handelException(n)}}function o(){i.slideUp(200);t.slideDown(200);r.show();n(document).off("scroll.menuCategory").on("scroll.menuCategory",u.bind(this))}function u(){try{i.slideDown(200);t.slideUp(200);r.hide();n(document).off("scroll.menuCategory")}catch(u){CommonFunction.handelException(u)}}var i=n("#btn-menu-category"),t=n("#menu-category"),r=t.parents(".cukcuk-overlay");return{init:f,$el:t}}();var wi=function(){function a(){i.modal("show");p()}function v(){i.modal("hide");f()}function y(n){n&&(f=n)}function p(){w();i.off("hidden.bs.modal").on("hidden.bs.modal",f);l.on("click",tt);u.on("change",nt);r.on("change",g)}function w(){b();k();c();d();h()}function b(){var i=config.branchs,u=Number(CukStorage.get(LocalStorageKey.DeliveryType)),f=i.filter(function(n){return n.ListDeliveryType.indexOf(u)>-1}),t=n();f.forEach(function(i){var f=i.LocationID,r=[i.Street,i.Address,i.PostalCode,i.District,i.ProvinceOrCity].filter(Boolean).join(", "),u=n('<option value="'+i.BranchID+'">'+i.BranchName+" ("+r+")<\/option>");t=t.add(u)});r.html(t)}function h(){o(EnumKindLocation.Province,AppContants.LocationVNId);var n=u.val();o(EnumKindLocation.District,n)}function k(){var n=config.branchs,u;n&&n.length&&(n.length==1?(t=n[0],i.find(".branch-content").html('<div class="font-bold-weight text-primary">'+t.BranchName+" ("+t.Address+")<\/div>")):(u=CommonFunction.getBranchId()||r.val(),t=n.filter(function(n){return n.BranchID==u})[0]||null,r.val(u)))}function d(){var t=CommonFunction.getCurrentBranch(),n=t.LocationID.toLowerCase()===AppContants.LocationVNId.toLowerCase();e.validate({onfocusout:function(n){this.element(n)},rules:{province:{required:n},district:{required:n}},messages:{province:{required:resourcesCommon.PleaseSelectProvince},district:{required:resourcesCommon.PleaseSelectDistrict}}})}function c(){var n;if(t)if(n=i.find(".address-content"),t.ListProvinceOrCitySupport&&t.ListDistrictSupport&&t.ListProvinceOrCitySupport.length==1&&t.ListDistrictSupport.length==1){var r=t.ListProvinceOrCitySupport[0],u=t.ListDistrictSupport[0],f=r.LocationName+", "+u.LocationName;n.find(".form-select").hide();n.find(".address-infor").html(CommonFunction.stringFormat(resourcesHome.OnlyScopeShipping,f))}else n.find(".address-infor").html(""),n.find(".form-select").show()}function g(){try{var i=config.branchs,n=r.val();n&&(t=i.filter(function(t){return t.BranchID==n})[0]||null);h();c()}catch(u){CommonFunction.handelException(u)}}function nt(){try{var n=u.val();n&&o(EnumKindLocation.District,n)}catch(t){CommonFunction.handelException(t)}}function tt(){try{if(e.length&&e.valid()){var t=r.val(),i=u.val(),f=s.val(),n=CukStorage.get(LocalStorageKey.Location)||{};n.ProvinceId=i;n.DistrictId=f;n.CommuneId=null;CukStorage.set(LocalStorageKey.Location,n);CommonFunction.gotoBranchSite(t)}}catch(o){CommonFunction.handelException(o)}}function o(i,r){var f,e,o;t.ListProvinceOrCitySupport=t.ListProvinceOrCitySupport||[];t.ListDistrictSupport=t.ListDistrictSupport||[];switch(i){case EnumKindLocation.Province:f=u;e=t.ListProvinceOrCitySupport.filter(function(n){return n.LocationID.indexOf(r)==0});break;case EnumKindLocation.District:f=s;e=t.ListDistrictSupport.filter(function(n){return n.LocationID.indexOf(r)==0})}f&&(f.html(""),e&&e.length&&(o=n(),e.forEach(function(t){var i=n('<option value="'+t.LocationID+'">'+t.LocationName+"<\/option>");o=o.add(i)}),f.append(o),e.length==1?f.attr("disabled",!0):f.attr("disabled",!1)))}var i=n("#selectBranchShippingModal"),f=function(){return void 0},e=i.find(".form-branch"),l=i.find(".btn-agree"),r=i.find(".sltBranch"),u=i.find(".sltProvince"),s=i.find(".sltDictrict"),t;return{show:a,close:v,result:y}}(),bi=function(){function e(){t.modal("show");h()}function o(){t.modal("hide");i()}function s(n){n&&(i=n)}function h(){c();t.off("hidden.bs.modal").on("hidden.bs.modal",i);f.on("click",v)}function c(){l();a()}function l(){var i=config.branchs,r=Number(CukStorage.get(LocalStorageKey.DeliveryType)),f=i.filter(function(n){return n.ListDeliveryType.indexOf(r)>-1}),t=n();f.forEach(function(i){var f=i.LocationID,r=[i.Street,i.Address,i.PostalCode,i.District,i.ProvinceOrCity].filter(Boolean).join(", "),u=n('<option value="'+i.BranchID+'">'+i.BranchName+" ("+r+")<\/option>");t=t.add(u)});u.html(t)}function a(){var n=config.branchs;n&&n.length&&n.length==1&&t.find(".branch-content").html('<div class="font-bold-weight text-primary">'+_branch.BranchName+"<\/div>")}function v(){try{if(r.length&&r.valid()){var n=u.val();CommonFunction.gotoBranchSite(n)}}catch(t){CommonFunction.handelException(t)}}var t=n("#selectBranchRecivedModal"),i=function(){return void 0},r=t.find(".form-branch"),f=t.find(".btn-agree"),u=t.find(".sltBranch");return{show:e,close:o,result:s}}(),ki=function(){function i(){var t="",t=r();n.confirm({title:resourcesCommon.Notify,content:CommonFunction.stringFormat(resourcesHome.MessageNotOpening,t),closeIcon:!1,buttons:!1,backgroundDismiss:!0})}function r(){var f="",t=CommonFunction.getCurrentBranch(),c=t.TimeOpenOption,e,r,i,o,n,u,h,s;if(t)if(c==EnumOrderOnlineTimeOpenOption.Custom){for(e=[],r=2;r<9;r++)if(i=t["ListTimeOpen"+r],i&&i.length>0){o=[];n=resourcesCommon.Monday;switch(r){case 2:n=resourcesCommon.Monday;break;case 3:n=resourcesCommon.Tuesday;break;case 4:n=resourcesCommon.Wednesday;break;case 5:n=resourcesCommon.Thursday;break;case 6:n=resourcesCommon.Friday;break;case 7:n=resourcesCommon.Saturday;break;case 8:n=resourcesCommon.Sunday}for(u=0;u<i.length;u++)h=CommonFunction.stringFormat(resourcesCommon.FromTo,i[u].StartTime,i[u].EndTime),o.push(h);e.push(CommonFunction.stringFormat("<li><b>{0}<\/b>: {1}<\/li>",n,o.join(" "+resourcesCommon.And+" ")))}f="<ul class='list-working-time'>"+e.join("")+"<\/ul>"}else t.TimeOpens&&t.TimeOpens.length&&(s=[],t.TimeOpens.forEach(function(n){s.push(n.StartTime+" - "+n.EndTime)}),f=s.join("; "));return f}function f(){u.modal("hide");t()}function e(n){n&&(t=n)}var t;return{show:i,close:f,result:e}}(),di=function(){function i(){n.confirm({title:resourcesCommon.Notify,content:resourcesHome.MessageRetaurantPending,closeIcon:!1,buttons:!1,backgroundDismiss:!0})}function r(){u.modal("hide");t()}function f(n){n&&(t=n)}var t;return{show:i,close:r,result:f}}(),gi=function(){function f(){t.modal("show");o()}function r(){t.modal("hide")}function e(n){n&&(i=n)}function o(){s();u.off("click").on("click",c);t.off("hidden.bs.modal").on("hidden.bs.modal",h)}function s(){}function h(){var n=CukStorage.get(LocalStorageKey.DeliveryType);n==null&&CukStorage.set(LocalStorageKey.DeliveryType,EnumDeliveryType.Ship);i()}function c(){try{var i=n(this),t=i.val();t!=null&&CukStorage.set(LocalStorageKey.DeliveryType,t);r()}catch(u){CommonFunction.handelException(u)}}var t=n("#selectDeliveryTypeModal"),u=t.find('input[name = "delivery-type"]'),i=function(){return void 0};return{show:f,close:r,result:e}}()})(jQuery,isShowBranchClosingModal,isShowBranchPendingBookingModal,orderData)