@ikas/storefront 6.1.0-beta.61 → 6.1.0-beta.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as r}from'./../ext/tslib/tslib.es6.js';import{makeAutoObservable as o}from"mobx";import"../models/data/blog/category/index.js";import"../models/data/blog/content/index.js";import"../models/data/blog/meta-data/index.js";import"../models/data/blog/tag/index.js";import"../models/data/blog/index.js";import{IkasBrand as i}from"../models/data/brand/index.js";import"@ikas/storefront-models";import"../models/data/campaign-offer/index.js";import"../models/data/cart/campaign-offer/index.js";import{IkasCart as s}from"../models/data/cart/index.js";import"../models/data/category/path-item/index.js";import{IkasCategory as a}from"../models/data/category/index.js";import{IkasCheckout as n}from"../models/data/checkout/index.js";import"../models/data/checkout-settings/index.js";import"../models/data/city/index.js";import"../models/data/country/index.js";import"../models/data/customer/address/region/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/address/ikas-localized-customer-address.js";import"../models/data/customer/attribute/index.js";import"../models/data/customer/review/summary/index.js";import"../models/data/customer/review/index.js";import"../models/data/customer/index.js";import"../models/data/customer-form-data-input/index.js";import"../models/data/district/index.js";import"../models/data/favorite-product/index.js";import"../models/data/filter-category/index.js";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/order/address/region/index.js";import"../models/data/order/address/index.js";import"../models/data/order/line-item/option/value/index.js";import"../models/data/order/line-item/variant/value/index.js";import"../models/data/order/line-item/variant/index.js";import"../models/data/order/line-item/index.js";import"../models/data/order/order-transaction-with-prices/index.js";import"../models/data/order/package/index.js";import"../models/data/order/transaction/index.js";import"../models/data/order/index.js";import"../models/data/payment-gateway/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product/filter/index.js";import"../models/data/product/campaign-offer/index.js";import"../models/data/product/option-set/option/index.js";import"../models/data/product/option-set/index.js";import"../models/data/product/stock-location/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product/variant/index.js";import"../models/data/variant-type/index.js";import{IkasProduct as c}from"../models/data/product/index.js";import"../models/data/raffle/index.js";import"../models/data/shipping-zone/state/city/district/region/index.js";import"../models/data/state/index.js";import"../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../models/data/storefront-popup/storefront-popup-page-filter/index.js";import{IkasStorefrontPopup as d}from"../models/data/storefront-popup/index.js";import"../models/data/theme-json/index.js";import"../models/data/theme-json/component/index.js";import"../models/data/theme-json/custom-data/index.js";import"../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/brand-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/customer-review-summary-list/index.js";import"../models/ui/validator/index.js";import"../models/ui/validator/rules/index.js";import"../models/ui/validator/form/login.js";import"../models/ui/validator/form/address.js";import"../models/ui/validator/form/ikas-address.js";import"../models/ui/validator/form/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import{FacebookPixel as m}from"./facebookPixel.js";import{GoogleTagManager as u}from"./googleTagManager.js";import{IkasEventType as l}from"./events.js";import p from"lodash/cloneDeep";import{tryForEach as b}from"../utils/helper.js";import f from"./ikasV3.js";import{GoogleAnalytics as g}from"./googleAnalytics.js";import{TiktokPixel as h}from"./tiktokPixel.js";import{IkasBaseStore as j}from"../store/base.js";import"../store/customer/index.js";import"../store/cart/index.js";var v=function(){function v(){o(this)}return v.getCustomerInfo=function(){return t(this,void 0,void 0,(function(){var t,o;return e(this,(function(e){switch(e.label){case 0:return[4,(t=j.getInstance()).customerStore.waitUntilInitialized()];case 1:return e.sent(),(o=t.customerStore.customer)?[2,r(r({},o.basicInfo),{consentGranted:t.customerStore.customerConsentGranted})]:[2,null]}}))}))},v.pageView=function(r){return t(this,void 0,void 0,(function(){var t,o,i,s;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),f.checkJourneyId(),t=window.location.href,[4,v.getCustomerInfo()];case 1:return o=e.sent(),i=Date.now().toString(),u.pageView(t),m.pageView(t,i),f.pageView(r,i),h.pageView(t),b(v.subscribers,(function(e){e.callback({type:l.PAGE_VIEW,data:{url:t,pageType:r,customer:o}})})),[3,3];case 2:return s=e.sent(),console.error(s),[3,3];case 3:return[2]}}))}))},v.productView=function(r){return t(this,void 0,void 0,(function(){var t,o;return e(this,(function(e){try{t=Date.now().toString(),m.productView(r,t),u.productView(r),f.productView(r,t),g.productView(r),h.productView(r),v.subscribers.length&&(o=new c(p(r)),b(v.subscribers,(function(t){t.callback({type:l.PRODUCT_VIEW,data:{productDetail:o}})})))}catch(t){console.error(t)}return[2]}))}))},v.addToCart=function(t,e,r,o,i){try{if(m.addToCart(t,e,r),u.addToCart(t,e,i),f.addToCart(t,e,o,r),g.addToCart(t,e),h.addToCart(t,e),v.subscribers.length){var a=p(t),n=new s(p(o));b(v.subscribers,(function(t){t.callback({type:l.ADD_TO_CART,data:{item:a,quantity:e,cart:n}})}))}}catch(t){console.error(t)}},v.removeFromCart=function(t,e,r){try{if(u.removeFromCart(t,e),g.removeFromCart(t,e),v.subscribers.length){var o=p(t),i=new s(p(r));b(v.subscribers,(function(t){t.callback({type:l.REMOVE_FROM_CART,data:{item:o,quantity:e,cart:i}})}))}}catch(t){console.error(t)}},v.beginCheckout=function(t){try{var e=localStorage.getItem("gtmBeginCheckout");if(e&&t.id===e)return;localStorage.setItem("gtmBeginCheckout",t.id);var r=Date.now().toString();if(m.beginCheckout(t,r),u.beginCheckout(t),f.beginCheckout(t,r),g.beginCheckout(t),h.beginCheckout(t),v.subscribers.length){var o=new n(p(t));b(v.subscribers,(function(t){t.callback({type:l.BEGIN_CHECKOUT,data:{checkout:o}})}))}}catch(t){console.error(t)}},v.purchase=function(t,e){try{if(localStorage.removeItem("gtmBeginCheckout"),m.purchase(t,e.id||""),u.purchase(t,t.orderNumber||""),f.orderSuccess(t,e.id||""),g.purchase(t,t.orderNumber||""),h.purchase(t),v.subscribers.length){var r=new n(p(t)),o=p(e);b(v.subscribers,(function(t){t.callback({type:l.COMPLETE_CHECKOUT,data:{checkout:r,transaction:o}})}))}}catch(t){console.error(t)}},v.checkoutStep=function(t,e){try{if(u.checkoutStep(t,e),f.checkoutStep(t,e),g.checkoutStep(t,e),v.subscribers.length){var r=new n(p(t));b(v.subscribers,(function(t){t.callback({type:l.CHECKOUT_STEP,data:{checkout:r,step:e}})}))}}catch(t){console.error(t)}},v.disableHTML=function(){try{u.disableHTML()}catch(t){console.error(t)}},v.addToWishlist=function(t,e){try{var r=Date.now().toString();m.addToWishlist(t,r),h.addToWishlist(t),f.addToWishlist(t,r),v.subscribers.length&&b(v.subscribers,(function(r){r.callback({type:e?l.REMOVE_FROM_WISHLIST:l.ADD_TO_WISHLIST,data:{productId:t}})}))}catch(t){console.error(t)}},v.search=function(t,e){try{var r=Date.now().toString();m.search(t,r),u.search(t),h.search(t),g.search(t),f.search(t,r,e),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.SEARCH,data:{searchKeyword:t}})}))}catch(t){console.error(t)}},v.completeRegistration=function(t,e){try{var o=Date.now().toString();e||(m.completeRegistration(o),u.completeRegistration(t),h.completeRegistration()),f.customerRegister(o),v.subscribers.length&&b(v.subscribers,(function(o){o.callback({type:l.CUSTOMER_REGISTER,data:r({email:t.email,firstName:t.firstName,lastName:t.lastName,notificationsAccepted:t.subscriptionStatus},e?{attributes:t.attributes}:{})})}))}catch(t){console.error(t)}},v.createEmailSubscripition=function(t){try{v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.EMAIL_SUBSCRIPTION,data:{email:t}})}))}catch(t){console.error(t)}},v.customerLogin=function(){return t(this,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,v.getCustomerInfo()];case 1:return(t=e.sent())&&t.email?(u.customerLogin(t),f.customerLogin(),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.CUSTOMER_LOGIN,data:{customer:t}})})),[3,3]):[2];case 2:return r=e.sent(),console.error(r),[3,3];case 3:return[2]}}))}))},v.customerLogout=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){try{u.customerLogout(),v.subscribers.length&&b(v.subscribers,(function(t){t.callback({type:l.CUSTOMER_LOGOUT,data:{}})}))}catch(t){console.error(t)}return[2]}))}))},v.customerVisit=function(){return t(this,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,v.getCustomerInfo()];case 1:return(t=e.sent())&&t.email?(u.customerVisit(t),f.customerVisit(),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.CUSTOMER_VISIT,data:{customer:t}})})),[3,3]):[2];case 2:return r=e.sent(),console.error(r),[3,3];case 3:return[2]}}))}))},v.viewCart=function(t){try{if(t){var e=Date.now().toString();if(m.viewCart(t,e),f.viewCart(t,e),g.viewCart(t),u.viewCart(t),v.subscribers.length){var r=new s(p(t));b(v.subscribers,(function(t){t.callback({type:l.VIEW_CART,data:{cart:r}})}))}}}catch(t){console.error(t)}},v.viewCategory=function(t,e){try{var r=Date.now().toString();if(m.viewCategory(t,r),u.viewCategory(e,t),f.viewCategory(e,t,r),h.viewCategory(e),v.subscribers.length){var o=new a(p(e));b(v.subscribers,(function(e){e.callback({type:l.VIEW_CATEGORY,data:{categoryPath:t,category:o}})}))}}catch(t){console.error(t)}},v.viewBrand=function(t){try{if(f.viewBrand(t),v.subscribers.length){var e=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.VIEW_BRAND,data:{brand:e}})}))}}catch(t){console.error(t)}},v.viewStorefrontPopup=function(t){try{if(f.viewPopup(t.id),v.subscribers.length){var e=new d(p(t));b(v.subscribers,(function(t){t.callback({type:l.POPUP_VIEW,data:{popup:e}})}))}}catch(t){console.error(t)}},v.viewSearchResults=function(t,e){try{if(v.subscribers.length){var r=p(e).map((function(t){return new c(t)}));b(v.subscribers,(function(e){e.callback({type:l.VIEW_SEARCH_RESULTS,data:{searchKeyword:t,productDetails:r}})}))}}catch(t){console.error(t)}},v.viewListing=function(t){try{if(v.subscribers.length){var e=p(t).map((function(t){return new c(t)}));b(v.subscribers,(function(t){t.callback({type:l.VIEW_LISTING,data:{productDetails:e}})}))}}catch(t){console.error(t)}},v.contactForm=function(t){try{var e=Date.now().toString();if(m.contactForm(e),h.contactForm(),f.contactForm(e),v.subscribers.length){var r=p(t);b(v.subscribers,(function(t){t.callback({type:l.CONTACT_FORM,data:{form:r}})}))}}catch(t){console.error(t)}},v.subscribers=[],v}();export{v as Analytics};
1
+ import{__awaiter as t,__generator as e,__assign as r}from'./../ext/tslib/tslib.es6.js';import{makeAutoObservable as o}from"mobx";import"../models/data/blog/category/index.js";import"../models/data/blog/content/index.js";import"../models/data/blog/meta-data/index.js";import"../models/data/blog/tag/index.js";import"../models/data/blog/index.js";import{IkasBrand as s}from"../models/data/brand/index.js";import"@ikas/storefront-models";import"../models/data/campaign-offer/index.js";import"../models/data/cart/campaign-offer/index.js";import{IkasCart as i}from"../models/data/cart/index.js";import"../models/data/category/path-item/index.js";import{IkasCategory as a}from"../models/data/category/index.js";import{IkasCheckout as n}from"../models/data/checkout/index.js";import"../models/data/checkout-settings/index.js";import"../models/data/city/index.js";import"../models/data/country/index.js";import"../models/data/customer/address/region/index.js";import"../models/data/customer/address/index.js";import"../models/data/customer/address/ikas-localized-customer-address.js";import"../models/data/customer/attribute/index.js";import"../models/data/customer/review/summary/index.js";import"../models/data/customer/review/index.js";import"../models/data/customer/index.js";import"../models/data/customer-form-data-input/index.js";import"../models/data/district/index.js";import"../models/data/favorite-product/index.js";import"../models/data/filter-category/index.js";import"../models/data/html-meta-data/index.js";import"../models/data/image/index.js";import"../models/data/order/address/region/index.js";import"../models/data/order/address/index.js";import"../models/data/order/line-item/option/value/index.js";import"../models/data/order/line-item/variant/value/index.js";import"../models/data/order/line-item/variant/index.js";import"../models/data/order/line-item/index.js";import"../models/data/order/order-transaction-with-prices/index.js";import"../models/data/order/package/index.js";import"../models/data/order/transaction/index.js";import"../models/data/order/index.js";import"../models/data/payment-gateway/index.js";import"../models/data/product/attribute-value/index.js";import"../models/data/product/filter/index.js";import"../models/data/product/campaign-offer/index.js";import"../models/data/product/option-set/option/index.js";import"../models/data/product/option-set/index.js";import"../models/data/product/stock-location/index.js";import"../models/data/product/variant/price/index.js";import"../models/data/product/variant/index.js";import"../models/data/variant-type/index.js";import{IkasProduct as c}from"../models/data/product/index.js";import"../models/data/raffle/index.js";import"../models/data/shipping-zone/state/city/district/region/index.js";import"../models/data/state/index.js";import"../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../models/data/storefront-popup/storefront-popup-page-filter/index.js";import{IkasStorefrontPopup as d}from"../models/data/storefront-popup/index.js";import"../models/data/theme-json/index.js";import"../models/data/theme-json/component/index.js";import"../models/data/theme-json/custom-data/index.js";import"../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../models/ui/blog-list/index.js";import"../models/ui/blog-category-list/index.js";import"../models/ui/brand-list/index.js";import"../models/ui/category-list/index.js";import"../models/ui/product-list/index.js";import"../models/ui/product-attribute-detail/index.js";import"../models/ui/product-attribute-list/index.js";import"../models/ui/customer-review-list/index.js";import"../models/ui/customer-review-summary-list/index.js";import"../models/ui/validator/index.js";import"../models/ui/validator/rules/index.js";import"../models/ui/validator/form/login.js";import"../models/ui/validator/form/address.js";import"../models/ui/validator/form/ikas-address.js";import"../models/ui/validator/form/register.js";import"../models/ui/validator/form/contact-form.js";import"../models/ui/validator/form/forgot-password.js";import"../models/ui/validator/form/recover-password.js";import"../models/ui/validator/form/account-info.js";import"../models/ui/validator/form/raffle-form.js";import"../models/ui/validator/form/customer-review.js";import"../models/ui/raffle-list/index.js";import{FacebookPixel as m}from"./facebookPixel.js";import{GoogleTagManager as u}from"./googleTagManager.js";import{IkasEventType as l}from"./events.js";import p from"lodash/cloneDeep";import{tryForEach as b}from"../utils/helper.js";import f from"./ikasV3.js";import{GoogleAnalytics as g}from"./googleAnalytics.js";import{TiktokPixel as h}from"./tiktokPixel.js";import{IkasBaseStore as j}from"../store/base.js";import"../store/customer/index.js";import"../store/cart/index.js";var v=function(){function v(){o(this)}return v.getCustomerInfo=function(){return t(this,void 0,void 0,(function(){var t,o;return e(this,(function(e){switch(e.label){case 0:return[4,(t=j.getInstance()).customerStore.waitUntilInitialized()];case 1:return e.sent(),(o=t.customerStore.customer)?[2,r(r({},o.basicInfo),{consentGranted:t.customerStore.customerConsentGranted})]:[2,null]}}))}))},v.pageView=function(r){return t(this,void 0,void 0,(function(){var t,o,s,i;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,4,,5]),[4,f.checkJourneyId()];case 1:return e.sent(),t=window.location.href,[4,v.getCustomerInfo()];case 2:return o=e.sent(),s=Date.now().toString(),u.pageView(t),m.pageView(t,s),[4,f.pageView(r,s)];case 3:return e.sent(),h.pageView(t),b(v.subscribers,(function(e){e.callback({type:l.PAGE_VIEW,data:{url:t,pageType:r,customer:o}})})),[3,5];case 4:return i=e.sent(),console.error(i),[3,5];case 5:return[2]}}))}))},v.productView=function(r){return t(this,void 0,void 0,(function(){var t,o,s;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=Date.now().toString(),m.productView(r,t),u.productView(r),[4,f.productView(r,t)];case 1:return e.sent(),g.productView(r),h.productView(r),v.subscribers.length&&(o=new c(p(r)),b(v.subscribers,(function(t){t.callback({type:l.PRODUCT_VIEW,data:{productDetail:o}})}))),[3,3];case 2:return s=e.sent(),console.error(s),[3,3];case 3:return[2]}}))}))},v.addToCart=function(t,e,r,o,s){try{if(m.addToCart(t,e,r),u.addToCart(t,e,s),f.addToCart(t,e,o,r),g.addToCart(t,e),h.addToCart(t,e),v.subscribers.length){var a=p(t),n=new i(p(o));b(v.subscribers,(function(t){t.callback({type:l.ADD_TO_CART,data:{item:a,quantity:e,cart:n}})}))}}catch(t){console.error(t)}},v.removeFromCart=function(t,e,r){try{if(u.removeFromCart(t,e),g.removeFromCart(t,e),v.subscribers.length){var o=p(t),s=new i(p(r));b(v.subscribers,(function(t){t.callback({type:l.REMOVE_FROM_CART,data:{item:o,quantity:e,cart:s}})}))}}catch(t){console.error(t)}},v.beginCheckout=function(t){try{var e=localStorage.getItem("gtmBeginCheckout");if(e&&t.id===e)return;localStorage.setItem("gtmBeginCheckout",t.id);var r=Date.now().toString();if(m.beginCheckout(t,r),u.beginCheckout(t),f.beginCheckout(t,r),g.beginCheckout(t),h.beginCheckout(t),v.subscribers.length){var o=new n(p(t));b(v.subscribers,(function(t){t.callback({type:l.BEGIN_CHECKOUT,data:{checkout:o}})}))}}catch(t){console.error(t)}},v.purchase=function(t,e){try{if(localStorage.removeItem("gtmBeginCheckout"),m.purchase(t,e.id||""),u.purchase(t,t.orderNumber||""),f.orderSuccess(t,e.id||""),g.purchase(t,t.orderNumber||""),h.purchase(t),v.subscribers.length){var r=new n(p(t)),o=p(e);b(v.subscribers,(function(t){t.callback({type:l.COMPLETE_CHECKOUT,data:{checkout:r,transaction:o}})}))}}catch(t){console.error(t)}},v.checkoutStep=function(t,e){try{if(u.checkoutStep(t,e),f.checkoutStep(t,e),g.checkoutStep(t,e),v.subscribers.length){var r=new n(p(t));b(v.subscribers,(function(t){t.callback({type:l.CHECKOUT_STEP,data:{checkout:r,step:e}})}))}}catch(t){console.error(t)}},v.disableHTML=function(){try{u.disableHTML()}catch(t){console.error(t)}},v.addToWishlist=function(t,e){try{var r=Date.now().toString();m.addToWishlist(t,r),h.addToWishlist(t),f.addToWishlist(t,r),v.subscribers.length&&b(v.subscribers,(function(r){r.callback({type:e?l.REMOVE_FROM_WISHLIST:l.ADD_TO_WISHLIST,data:{productId:t}})}))}catch(t){console.error(t)}},v.search=function(t,e){try{var r=Date.now().toString();m.search(t,r),u.search(t),h.search(t),g.search(t),f.search(t,r,e),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.SEARCH,data:{searchKeyword:t}})}))}catch(t){console.error(t)}},v.completeRegistration=function(t,e){try{var o=Date.now().toString();e||(m.completeRegistration(o),u.completeRegistration(t),h.completeRegistration()),f.customerRegister(o),v.subscribers.length&&b(v.subscribers,(function(o){o.callback({type:l.CUSTOMER_REGISTER,data:r({email:t.email,firstName:t.firstName,lastName:t.lastName,notificationsAccepted:t.subscriptionStatus},e?{attributes:t.attributes}:{})})}))}catch(t){console.error(t)}},v.createEmailSubscripition=function(t){try{v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.EMAIL_SUBSCRIPTION,data:{email:t}})}))}catch(t){console.error(t)}},v.customerLogin=function(){return t(this,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,v.getCustomerInfo()];case 1:return(t=e.sent())&&t.email?(u.customerLogin(t),[4,f.customerLogin()]):[2];case 2:return e.sent(),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.CUSTOMER_LOGIN,data:{customer:t}})})),[3,4];case 3:return r=e.sent(),console.error(r),[3,4];case 4:return[2]}}))}))},v.customerLogout=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){try{u.customerLogout(),v.subscribers.length&&b(v.subscribers,(function(t){t.callback({type:l.CUSTOMER_LOGOUT,data:{}})}))}catch(t){console.error(t)}return[2]}))}))},v.customerVisit=function(){return t(this,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,v.getCustomerInfo()];case 1:return(t=e.sent())&&t.email?(u.customerVisit(t),[4,f.customerVisit()]):[2];case 2:return e.sent(),v.subscribers.length&&b(v.subscribers,(function(e){e.callback({type:l.CUSTOMER_VISIT,data:{customer:t}})})),[3,4];case 3:return r=e.sent(),console.error(r),[3,4];case 4:return[2]}}))}))},v.viewCart=function(t){try{if(t){var e=Date.now().toString();if(m.viewCart(t,e),f.viewCart(t,e),g.viewCart(t),u.viewCart(t),v.subscribers.length){var r=new i(p(t));b(v.subscribers,(function(t){t.callback({type:l.VIEW_CART,data:{cart:r}})}))}}}catch(t){console.error(t)}},v.viewCategory=function(t,e){try{var r=Date.now().toString();if(m.viewCategory(t,r),u.viewCategory(e,t),f.viewCategory(e,t,r),h.viewCategory(e),v.subscribers.length){var o=new a(p(e));b(v.subscribers,(function(e){e.callback({type:l.VIEW_CATEGORY,data:{categoryPath:t,category:o}})}))}}catch(t){console.error(t)}},v.viewBrand=function(t){try{if(f.viewBrand(t),v.subscribers.length){var e=new s(p(t));b(v.subscribers,(function(t){t.callback({type:l.VIEW_BRAND,data:{brand:e}})}))}}catch(t){console.error(t)}},v.viewStorefrontPopup=function(t){try{if(f.viewPopup(t.id),v.subscribers.length){var e=new d(p(t));b(v.subscribers,(function(t){t.callback({type:l.POPUP_VIEW,data:{popup:e}})}))}}catch(t){console.error(t)}},v.viewSearchResults=function(t,e){try{if(v.subscribers.length){var r=p(e).map((function(t){return new c(t)}));b(v.subscribers,(function(e){e.callback({type:l.VIEW_SEARCH_RESULTS,data:{searchKeyword:t,productDetails:r}})}))}}catch(t){console.error(t)}},v.viewListing=function(t){try{if(v.subscribers.length){var e=p(t).map((function(t){return new c(t)}));b(v.subscribers,(function(t){t.callback({type:l.VIEW_LISTING,data:{productDetails:e}})}))}}catch(t){console.error(t)}},v.contactForm=function(t){try{var e=Date.now().toString();if(m.contactForm(e),h.contactForm(),f.contactForm(e),v.subscribers.length){var r=p(t);b(v.subscribers,(function(t){t.callback({type:l.CONTACT_FORM,data:{form:r}})}))}}catch(t){console.error(t)}},v.subscribers=[],v}();export{v as Analytics};
@@ -1 +1 @@
1
- import*as e from"react";import{observer as t}from"mobx-react-lite";import s from"../../style.module.scss.js";import r from"../select-box/index.js";import{AddressForm as d}from"../address-form/index.js";import{Checkbox as i}from"../checkbox/index.js";import{FormItem as o}from"../form-item/index.js";import{FormItemType as a}from"../form-item/model.js";import n from"./style.module.scss.js";import l from"../../styles/common.module.scss.js";import{Button as c}from"../button/index.js";import{IkasStorefrontConfig as m}from"@ikas/storefront-config";import{useTranslation as u}from"../../../../utils/i18n.js";import v from"../delivery-methods/index.js";import{CheckoutStep as p}from"../../model.js";var h=t((function(t){var d,i=t.vm,o=t.showBillingAddressOnShippingStep,a=u().t,h=e.useMemo((function(){return e.createElement("div",null,e.createElement(g,{vm:i}),e.createElement(k,{vm:i}))}),[i]),C=e.useMemo((function(){return e.createElement("div",null,e.createElement(E,{vm:i}))}),[i]),A=e.useState("-1"),f=A[0],y=A[1];e.useEffect((function(){i.vm.checkout.stockLocationId&&y(i.vm.checkout.stockLocationId)}),[]);var b=function(e){if(!e.address)return"";var t=[];return e.address.address&&t.push(e.address.address),e.address.postalCode&&t.push(e.address.postalCode),e.address.district&&e.address.district.name&&t.push(e.address.district.name),e.address.city&&e.address.city.name&&t.push(e.address.city.name),e.address.state&&e.address.state.name&&"Default"!==e.address.state.name&&t.push(e.address.state.name),e.address.country&&e.address.country.name&&t.push(e.address.country.name),t.join(", ")};return e.createElement(e.Fragment,null,!!m.getPickupStockLocationIds()&&!i.vm.isDigitalOnly&&i.vm.availableStockLocations.length>0&&i.vm.step!==p.PAYMENT&&!o&&e.createElement(e.Fragment,null,e.createElement("div",{className:l.FormSectionTitle},e.createElement("div",{className:l.Title},a("checkout-page:deliveryMethod"))),e.createElement(v,{deliveryMethod:i.vm.deliveryMethod,onClick:function(e){"address"===e&&y("-1"),i.vm.onDeliveryMethodChange(e)}})),e.createElement("div",{className:l.FormSectionTitle},"address"===i.vm.deliveryMethod?e.createElement("div",{className:l.Title},i.editingCustomerAddress?a("checkout-page:editAddress"):"billing"===i.addressType?a("checkout-page:billingAddress"):a("checkout-page:shippingAddress")):i.vm.step===p.PAYMENT||o?e.createElement("div",{className:l.Title},a("checkout-page:billingAddress")):e.createElement("div",{className:l.Title},a("checkout-page:pickUpLocation"),e.createElement("span",{className:n.ErrorMessage},i.vm.isErrorsVisible&&!i.vm.checkout.stockLocationId&&a("checkout-page:errorPickupLocationRequired"))),!!i.editingCustomerAddress&&e.createElement("div",{className:n.CancelEdit,onClick:i.onCancelEditAddressClick},a("checkout-page:actions.cancel"))),!!i.vm.store.customerStore.customer&&!i.editingCustomerAddress&&("address"===i.vm.deliveryMethod||i.vm.step===p.PAYMENT&&"in-store"===i.vm.deliveryMethod||o)&&e.createElement("div",{className:s.RowPB},null===(d=i.vm.customerAddresses)||void 0===d?void 0:d.map((function(t){return e.createElement(r,{key:t.id,label:t.title||"",isSelected:t.id===i.selectedAddressId,rightContent:e.createElement("div",{onClick:function(){return i.onEditAddressClick(t)}},a("checkout-page:actions.edit")),bottomContent:e.createElement("div",{className:n.AddressContent},e.createElement("div",{className:n.AddressText},t.firstName," ",t.lastName),e.createElement("div",{className:n.AddressText},t.addressText)),bottomContentVisible:!0,hasError:!t.isValidAddress,errorText:a("checkout-page:missingAddressFields"),onClick:function(){return t.id!==i.selectedAddressId&&i.onAddressSelect(t)}})})),e.createElement(r,{label:a("checkout-page:newAddress"),isSelected:"-1"===i.selectedAddressId,bottomContent:h,onClick:function(){return"-1"!==i.selectedAddressId&&i.onAddressSelect()}})),i.vm.store.customerStore.customer||i.vm.step!==p.INFO||"address"!==i.vm.deliveryMethod?(o&&!i.vm.store.customerStore.customer||i.vm.step===p.PAYMENT&&!i.vm.store.customerStore.customer)&&h:h,"in-store"===i.vm.deliveryMethod&&!o&&e.createElement("div",{className:s.RowPB},i.vm.stockLocations.map((function(t){return function(e){return e.address&&e.address.address&&e.address.city&&e.address.country&&i.vm.availableStockLocations.find((function(t){return t.id===e.id}))}(t)&&e.createElement(r,{key:t.id,label:t.name||"",isSelected:f===t.id,bottomContent:e.createElement("div",null,e.createElement("div",{className:n.AddressText},b(t)),t.deliveryTime&&e.createElement("div",{className:n.DeliveryTime},a("checkout-page:stockLocation.deliveryTime.".concat(t.deliveryTime)))),bottomContentVisible:!0,onClick:function(){i.vm.onStockLocationChange(t),y(t.id)}})}))),"in-store"===i.vm.deliveryMethod&&i.vm.step!==p.PAYMENT&&!o&&e.createElement(e.Fragment,null,e.createElement("div",{className:l.FormSectionTitle},e.createElement("div",{className:l.Title},a("checkout-page:recipientsInfo"))),C),!!i.editingCustomerAddress&&e.createElement(g,{vm:i}),!!i.editingCustomerAddress&&e.createElement("div",{className:n.EditAddressActions},e.createElement(c,{style:{width:"100%"},text:a("checkout-page:deleteAddress"),isLine:!0,isLoading:i.isDeleteAddressLoading,isDisabled:i.isEditAddressLoading,onClick:i.onDeleteAddressClick}),e.createElement(c,{style:{width:"100%",marginTop:i.vm.store.customerStore.customer?"0px":"32px"},text:a("checkout-page:actions.save"),isLoading:i.isEditAddressLoading,isDisabled:i.isDeleteAddressLoading,onClick:i.onSaveAddressClick})))})),g=t((function(t){var s,r=t.vm,i=(!!(null===(s=r.vm.checkout.customer)||void 0===s?void 0:s.isGuestCheckout)||!!r.vm.store.customerStore.customer)&&r.vm.isCorporateInvoiceVisible&&!!r.vm.checkoutSettings.showCompanyInfoInShippingAddress;return e.createElement(d,{address:r.editingCustomerAddress||r.address,isErrorsVisible:r.isEditAddressErrorsVisible||r.vm.isErrorsVisible,allowedCountryIds:r.vm.shippingCountryIds||void 0,allowCorporateInfo:"billing"===r.addressType?"in-store"===r.vm.deliveryMethod||!i:i,firstNameChangeCallback:r.firstNameChangeCallback,lastNameChangeCallback:r.lastNameChangeCallback,allowTitleChange:!!r.editingCustomerAddress,deliveryMethod:"address"})})),E=t((function(t){var s=t.vm;return e.createElement(d,{address:s.editingCustomerAddress||s.address,isErrorsVisible:s.isEditAddressErrorsVisible||s.vm.isErrorsVisible,firstNameChangeCallback:s.firstNameChangeCallback,lastNameChangeCallback:s.lastNameChangeCallback,deliveryMethod:"in-store"})})),k=t((function(t){var s=t.vm,r=u().t;return s.vm.store.customerStore.customer&&"-1"===s.selectedAddressId?e.createElement("div",{style:{marginTop:"12px"}},e.createElement(i,{value:s.vm.shouldSaveAddress,label:r("checkout-page:saveAddressCta"),onChange:s.vm.setShouldSaveAddress}),s.vm.shouldSaveAddress&&e.createElement("div",{style:{marginTop:"8px"}},e.createElement(o,{type:a.TEXT,label:r("checkout-page:addressTitle"),value:s.vm.addressTitle,onChange:s.vm.setAddressTitle}))):null}));export{g as CustomerAddressForm,E as RecipientForm,k as SaveAddressCheckboxAndTitle,h as default};
1
+ import*as e from"react";import{observer as t}from"mobx-react-lite";import s from"../../style.module.scss.js";import r from"../select-box/index.js";import{AddressForm as d}from"../address-form/index.js";import{Checkbox as i}from"../checkbox/index.js";import{FormItem as o}from"../form-item/index.js";import{FormItemType as a}from"../form-item/model.js";import n from"./style.module.scss.js";import l from"../../styles/common.module.scss.js";import{Button as c}from"../button/index.js";import{IkasStorefrontConfig as m}from"@ikas/storefront-config";import{useTranslation as u}from"../../../../utils/i18n.js";import v from"../delivery-methods/index.js";import{CheckoutStep as p}from"../../model.js";var h=t((function(t){var d,i=t.vm,o=t.showBillingAddressOnShippingStep,a=u().t,h=e.useMemo((function(){return e.createElement("div",null,e.createElement(g,{vm:i}),e.createElement(k,{vm:i}))}),[i]),C=e.useMemo((function(){return e.createElement("div",null,e.createElement(E,{vm:i}))}),[i]),A=e.useState("-1"),f=A[0],y=A[1];e.useEffect((function(){i.vm.checkout.stockLocationId&&y(i.vm.checkout.stockLocationId)}),[]);var b=function(e){if(!e.address)return"";var t=[];return e.address.address&&t.push(e.address.address),e.address.postalCode&&t.push(e.address.postalCode),e.address.district&&e.address.district.name&&t.push(e.address.district.name),e.address.city&&e.address.city.name&&t.push(e.address.city.name),e.address.state&&e.address.state.name&&"Default"!==e.address.state.name&&t.push(e.address.state.name),e.address.country&&e.address.country.name&&t.push(e.address.country.name),t.join(", ")};return e.createElement(e.Fragment,null,!!m.getPickupStockLocationIds()&&!i.vm.isDigitalOnly&&i.vm.availableStockLocations.length>0&&i.vm.step!==p.PAYMENT&&!o&&e.createElement(e.Fragment,null,e.createElement("div",{className:l.FormSectionTitle},e.createElement("div",{className:l.Title},a("checkout-page:deliveryMethod"))),e.createElement(v,{deliveryMethod:i.vm.deliveryMethod,onClick:function(e){"address"===e&&y("-1"),i.vm.onDeliveryMethodChange(e)}})),e.createElement("div",{className:l.FormSectionTitle},"address"===i.vm.deliveryMethod?e.createElement("div",{className:l.Title},i.editingCustomerAddress?a("checkout-page:editAddress"):"billing"===i.addressType?a("checkout-page:billingAddress"):a("checkout-page:shippingAddress")):i.vm.step===p.PAYMENT||o?e.createElement("div",{className:l.Title},a("checkout-page:billingAddress")):e.createElement("div",{className:l.Title},a("checkout-page:pickUpLocation"),e.createElement("span",{className:n.ErrorMessage},i.vm.isErrorsVisible&&!i.vm.checkout.stockLocationId&&a("checkout-page:errorPickupLocationRequired"))),!!i.editingCustomerAddress&&e.createElement("div",{className:n.CancelEdit,onClick:i.onCancelEditAddressClick},a("checkout-page:actions.cancel"))),!!i.vm.store.customerStore.customer&&!i.editingCustomerAddress&&("address"===i.vm.deliveryMethod||i.vm.step===p.PAYMENT&&"in-store"===i.vm.deliveryMethod||o)&&e.createElement("div",{className:s.RowPB},null===(d=i.vm.customerAddresses)||void 0===d?void 0:d.map((function(t){return e.createElement(r,{key:t.id,label:t.title||"",isSelected:t.id===i.selectedAddressId,rightContent:e.createElement("div",{onClick:function(){return i.onEditAddressClick(t)}},a("checkout-page:actions.edit")),bottomContent:e.createElement("div",{className:n.AddressContent},e.createElement("div",{className:n.AddressText},t.firstName," ",t.lastName),e.createElement("div",{className:n.AddressText},t.addressText)),bottomContentVisible:!0,hasError:!t.isValidAddress,errorText:a("checkout-page:missingAddressFields"),onClick:function(){return t.id!==i.selectedAddressId&&i.onAddressSelect(t)}})})),e.createElement(r,{label:a("checkout-page:newAddress"),isSelected:"-1"===i.selectedAddressId,bottomContent:h,onClick:function(){return"-1"!==i.selectedAddressId&&i.onAddressSelect()}})),i.vm.store.customerStore.customer||i.vm.step!==p.INFO||"address"!==i.vm.deliveryMethod?(o&&!i.vm.store.customerStore.customer||i.vm.step===p.PAYMENT&&!i.vm.store.customerStore.customer)&&h:h,"in-store"===i.vm.deliveryMethod&&!o&&e.createElement("div",{className:s.RowPB},i.vm.stockLocations.map((function(t){return function(e){return e.address&&e.address.address&&e.address.city&&e.address.country&&i.vm.availableStockLocations.find((function(t){return t.id===e.id}))}(t)&&e.createElement(r,{key:t.id,label:t.name||"",isSelected:f===t.id,bottomContent:e.createElement("div",null,e.createElement("div",{className:n.AddressText},b(t)),t.deliveryTime&&e.createElement("div",{className:n.DeliveryTime},a("checkout-page:stockLocation.deliveryTime.".concat(t.deliveryTime)))),bottomContentVisible:!0,onClick:function(){i.vm.onStockLocationChange(t),y(t.id)}})}))),"in-store"===i.vm.deliveryMethod&&i.vm.step!==p.PAYMENT&&!o&&e.createElement(e.Fragment,null,e.createElement("div",{className:l.FormSectionTitle},e.createElement("div",{className:l.Title},a("checkout-page:recipientsInfo"))),C),!!i.editingCustomerAddress&&e.createElement(g,{vm:i}),!!i.editingCustomerAddress&&e.createElement("div",{className:n.EditAddressActions},e.createElement(c,{style:{width:"100%"},text:a("checkout-page:deleteAddress"),isLine:!0,isLoading:i.isDeleteAddressLoading,isDisabled:i.isEditAddressLoading,onClick:i.onDeleteAddressClick}),e.createElement(c,{style:{width:"100%",marginTop:i.vm.store.customerStore.customer?"0px":"32px"},text:a("checkout-page:actions.save"),isLoading:i.isEditAddressLoading,isDisabled:i.isDeleteAddressLoading,onClick:i.onSaveAddressClick})))})),g=t((function(t){var s,r=t.vm,i=(!!(null===(s=r.vm.checkout.customer)||void 0===s?void 0:s.isGuestCheckout)||!!r.vm.store.customerStore.customer)&&r.vm.isCorporateInvoiceVisible&&!!r.vm.checkoutSettings.showCompanyInfoInShippingAddress;return e.createElement(d,{address:r.editingCustomerAddress||r.address,isErrorsVisible:r.isEditAddressErrorsVisible||r.vm.isErrorsVisible,allowedCountryIds:r.vm.shippingCountryIds||void 0,allowCorporateInfo:"billing"===r.addressType?"in-store"===r.vm.deliveryMethod||(r.vm.isDigitalOnly?i:!i):i,firstNameChangeCallback:r.firstNameChangeCallback,lastNameChangeCallback:r.lastNameChangeCallback,allowTitleChange:!!r.editingCustomerAddress,deliveryMethod:"address"})})),E=t((function(t){var s=t.vm;return e.createElement(d,{address:s.editingCustomerAddress||s.address,isErrorsVisible:s.isEditAddressErrorsVisible||s.vm.isErrorsVisible,firstNameChangeCallback:s.firstNameChangeCallback,lastNameChangeCallback:s.lastNameChangeCallback,deliveryMethod:"in-store"})})),k=t((function(t){var s=t.vm,r=u().t;return s.vm.store.customerStore.customer&&"-1"===s.selectedAddressId?e.createElement("div",{style:{marginTop:"12px"}},e.createElement(i,{value:s.vm.shouldSaveAddress,label:r("checkout-page:saveAddressCta"),onChange:s.vm.setShouldSaveAddress}),s.vm.shouldSaveAddress&&e.createElement("div",{style:{marginTop:"8px"}},e.createElement(o,{type:a.TEXT,label:r("checkout-page:addressTitle"),value:s.vm.addressTitle,onChange:s.vm.setAddressTitle}))):null}));export{g as CustomerAddressForm,E as RecipientForm,k as SaveAddressCheckboxAndTitle,h as default};
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as s}from"mobx";import n from"lodash/cloneDeep";import r from"lodash/sortBy";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as o,IkasCartCreatedBy as a,IkasCouponCodeRequirement as c,IkasCorporateInvoiceRequirement as d,IkasPaymentMethodType as u,IkasPaymentGatewayType as l,IkasOrderShippingMethod as h,IkasOrderPaymentStatus as p,IkasTransactionStatus as m,IkasCartCampaignOfferStatus as f,IkasCampaignOfferTargetPageType as g,IkasOrderLineItemStatus as v,IkasAmountType as y,IkasCampaignOfferProductApplicablePriceEnum as S}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import{IkasCheckout as k}from"../../models/data/checkout/index.js";import{IkasCheckoutSettings as b}from"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import{IkasCustomerAddress as P}from"../../models/data/customer/address/index.js";import{IkasLocalizedCustomerAddress as C}from"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import{IkasMerchantSettings as A}from"../../models/data/merchant-settings/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import{IkasOrderCustomer as I}from"../../models/data/order/customer/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import{IkasProductPrice as w}from"../../models/data/product/variant/price/index.js";import{IkasProductVariant as O}from"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import{IkasProduct as E}from"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import{LocalizedAddressModel as R}from"@ikas/localized-address";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/customer-review-summary-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/ikas-address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import N from"./components/credit-card-form/model.js";import j from"../../store/customer/api.js";import T from"../../store/checkout/index.js";import D from"../../store/cart/api.js";import M,{MFS_ELEMENT_ID as G,MFS_SCRIPT_URL as L}from"./modelMasterPass.js";import x from"../../store/product/index.js";import{TransactionCardAssociationEnum as _,SaveCartInput as V,CheckStocksLineInput as U}from"@ikas/storefront-api";import{IkasBaseStore as F}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import{IkasStorefrontConfig as B}from"@ikas/storefront-config";import{Analytics as K}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import Y from"../../models/data/order/address/ikas-localized-order-address.js";import Z from"../../store/location/index.js";import{getCookieValue as H}from"../../utils/helper.js";import q from"../../analytics/ikasV3.js";var W,Q,z=/^\d+$/,X="undefined"==typeof localStorage,J=function(){function z(a,d,C,A,z,J,te,ie,se,ne){var re=this;this.storefront=null,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.isPaymentMethodVisible=!0,this.step=W.INFO,this.customizationProps=null,this.cardData=null,this.paymentGateways=[],this.productFiles=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!0,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.stockLocations=[],this.availableStockLocations=[],this.deliveryMethod="address",this.stripeResponse=null,this.stripeError=null,this.klarnaResponse=null,this.isKlarnaPaymentCompleted=!1,this.klarnaError=null,this.adyenResponse=null,this.payPalClientIdResponse=null,this.paypalOrderResponse=null,this.isCampaignOfferLoaded=!0,this.shippingZones=null,this.policyModalTitle="",this.policyModalText="",this.error=null,this.couponError=null,this.showTestModal=!1,this.init=function(){return e(re,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this.countrySettings.waitUntilInitialized()];case 1:return e.sent(),[4,F.getInstance().customerStore.waitUntilInitialized()];case 2:return e.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.initStep()];case 3:return e.sent(),[2]}}))}))},this.initStep=function(){return e(re,void 0,void 0,(function(){var e,s,n,r,o,a,d;return t(this,(function(t){switch(t.label){case 0:if(B.getIsEditor())return this.step=W.INFO,this.isCheckoutLoaded=!0,[2];if(e=new URLSearchParams(window.location.search),s=e.get("step"),n=e.get("failed"),r=e.get("error"),s){if(this.step=s,this.step===W.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(W.INFO)];if(this.step!==W.PAYMENT||this.canProceedToPayment){if(this.step===W.SUCCESS&&!this.canProceedToPayment)return[2,this.changeStep(W.INFO)];if(![W.INFO,W.SUCCESS,W.SHIPPING,W.PAYMENT].includes(this.step))return[2,this.changeStep(W.INFO)]}else{if(!this.isInStoreDelivery)return this.isValidShippingSettings?[2,this.changeStep(W.INFO)]:[2,this.changeStep(W.SHIPPING)];this.deliveryMethod="in-store"}}return[4,this.createCampaignOffer()];case 1:return t.sent(),this.step!==W.SHIPPING&&this.step!==W.PAYMENT||this.isCouponCodeRequirementInvisible||(this.checkoutSettings=new b(i(i({},this.checkoutSettings),{couponCodeRequirement:c.DEFAULT}))),this.step!==W.INFO?[3,7]:this.isDigitalOnly?[3,4]:[4,this.getAvailableShippingZones()];case 2:return t.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getShippingCountries()];case 3:t.sent(),this.checkShippingCountries(),t.label=4;case 4:return[4,this.getStockLocations()];case 5:return t.sent(),[4,this.getAvailableStockLocations()];case 6:t.sent(),this.isInStoreDelivery&&(this.deliveryMethod="in-store"),t.label=7;case 7:return this.step!==W.SHIPPING||1!==(null===(a=this.checkout.availableShippingMethods)||void 0===a?void 0:a.length)||this.checkoutSettings.isGiftPackageEnabled||(this.step=W.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==W.SHIPPING||(null===(d=this.checkout.availableShippingMethods)||void 0===d?void 0:d.length)?this.step!==W.SUCCESS||this.checkout.orderPaymentStatus!==p.PAID?[3,9]:[4,this.listProductFile()]:(this.error={type:Q.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 8:t.sent(),t.label=9;case 9:return this.step!==W.PAYMENT&&this.step!==W.SUCCESS?[3,13]:[4,this.listPaymentGateways()];case 10:return t.sent(),this.isInStoreDelivery?(this.deliveryMethod="in-store",[4,this.getStockLocations()]):[3,12];case 11:t.sent(),t.label=12;case 12:if(!this.paymentGateways.length&&!this.isFree)return this.error={type:Q.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];t.label=13;case 13:return this.step===W.SUCCESS?[3,17]:this.checkout.isComplete?[2,this.changeStep(W.SUCCESS)]:[3,14];case 14:return[4,this.initialStockCheck()];case 15:t.sent(),t.label=16;case 16:return[3,19];case 17:return[4,this.getSuccessTransaction()];case 18:t.sent(),this.successTransaction&&(o=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(e){return e.id===o}))),t.label=19;case 19:return n&&(this.error={type:Q.PAYMENT_ERROR,data:r||null}),this.isCheckoutLoaded=!0,K.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getSuccessTransaction=function(){return e(re,void 0,void 0,(function(){var e,i,s;return t(this,(function(t){switch(t.label){case 0:return[4,j.listOrderTransactions({orderId:{eq:this.checkout.id}})];case 1:return e=t.sent(),this.successTransactions=e.isSuccess&&(null===(i=e.data)||void 0===i?void 0:i.length)?e.data:[],this.successTransaction=e.isSuccess&&(null===(s=e.data)||void 0===s?void 0:s.length)?e.data[e.data.length-1]:void 0,[2]}}))}))},this.saveCart=function(){return e(re,void 0,void 0,(function(){var e,i,s,n,r,a;return t(this,(function(t){switch(t.label){case 0:return e=new V(this.checkout),"in-store"!==this.deliveryMethod?[3,2]:[4,this.inStockDeliveryInputData(e)];case 1:e=t.sent(),t.label=2;case 2:return this.step!==W.INFO&&this.step!==W.SHIPPING||this.isDigitalOnly||this.isShowBillingAddressOnShippingStep||(e.billingAddress=null),this.isDigitalOnly&&(e.shippingAddress=null),e.customer&&(this.store.customerStore.customer?e.customer.notificationsAccepted=this.store.customerStore.customer.subscriptionStatus===o.SUBSCRIBED:this.checkout.customer&&(e.customer.notificationsAccepted=this.checkout.customer.notificationsAccepted||!1)),[4,D.saveCart({input:e})];case 3:if((null==(i=t.sent())?void 0:i.graphQLErrors)&&i.graphQLErrors.length)throw s=i.graphQLErrors[0],"CUSTOMER_LOGIN_REQUIRED"===(null===(n=s.extensions)||void 0===n?void 0:n.code)?{type:Q.CUSTOMER_LOGIN_REQUIRED_ERROR}:"CUSTOMER_ACCOUNT_DISABLED"===(null===(r=s.extensions)||void 0===r?void 0:r.code)?{type:Q.CUSTOMER_ACCOUNT_DISABLED_ERROR}:"ARGUMENT_VALIDATION_ERROR"===(null===(a=s.extensions)||void 0===a?void 0:a.code)?{type:Q.ARGUMENT_VALIDATION_ERROR,data:s.extensions.validationErrors}:{type:Q.API_ERROR,data:i.firstErrorMessage};return[2,i.data]}}))}))},this.inStockDeliveryInputData=function(i){return e(re,void 0,void 0,(function(){var e,s,n=this;return t(this,(function(t){return e=i,(s=this.stockLocations.find((function(e){return e.id===n.checkout.stockLocationId})))&&e.shippingAddress&&s.address&&(e.shippingAddress.country=s.address.country,e.shippingAddress.city=s.address.city,e.shippingAddress.state=s.address.state,e.shippingAddress.district=s.address.district,e.shippingAddress.postalCode=s.address.postalCode,e.shippingAddress.addressLine1=s.address.address||"",e.shippingAddress.addressLine2=null),[2,e]}))}))},this.checkStocks=function(){return e(re,void 0,void 0,(function(){var e,i,s,n,r,o,a,c,d,u,l,p;return t(this,(function(t){switch(t.label){case 0:return this.isManualOrder?[2]:(e=this.checkout.stockLocationId&&this.checkout.shippingMethod===h.CLICK_AND_COLLECT?[this.checkout.stockLocationId]:(null===(u=B.getStockLocationIds())||void 0===u?void 0:u.length)?B.getStockLocationIds():null,[4,T.checkCartStocks({cartId:this.checkout.id,stockLocationIdList:e})]);case 1:if(!(i=t.sent()).isSuccess)throw{type:Q.API_ERROR,data:i.firstErrorMessage};if(null==(s=null===(p=null===(l=i.data)||void 0===l?void 0:l.lines)||void 0===p?void 0:p.filter((function(e){return!e.isAvailable})))?void 0:s.length){for(n=[],r=function(e){var t=o.checkout.items.find((function(t){return t.variant.id===e.variantId}));t&&n.push({item:t,stockCount:e.stockCount})},o=this,a=0,c=s;a<c.length;a++)d=c[a],r(d);throw{type:Q.STOCK_ERROR,data:n}}return[2]}}))}))},this.setIsKlarnaPaymentCompleted=function(i){return e(re,void 0,void 0,(function(){return t(this,(function(e){return this.isKlarnaPaymentCompleted=i,[2]}))}))},this.removeUnavailableItems=function(i){return e(re,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:e=0,s=i,t.label=1;case 1:return e<s.length?(n=s[e],[4,F.getInstance().cartStore.changeItemQuantity(n.item,n.stockCount<0?0:n.stockCount)]):[3,4];case 2:t.sent(),t.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},this.getShippingCountries=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.getAvailableShippingCountries({salesChannelId:B.getSalesChannelId()})];case 1:return e=t.sent(),this.shippingCountryIds=e.data,[2]}}))}))},this.getStockLocations=function(){return e(re,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return B.getPickupStockLocationIds()?[4,T.listStockLocation({id:{in:B.getPickupStockLocationIds()}})]:[3,2];case 1:if(!(e=t.sent()).isSuccess||!(null===(i=e.data)||void 0===i?void 0:i.length))return this.error={type:Q.API_ERROR,data:e.firstErrorMessage},[2];this.stockLocations=e.data,t.label=2;case 2:return[2]}}))}))},this.getAvailableStockLocations=function(){return e(re,void 0,void 0,(function(){var e,i,s,n=this;return t(this,(function(t){switch(t.label){case 0:return B.getPickupStockLocationIds()?(e=this.checkout.items.map((function(e){return{quantity:e.quantity,variantId:e.variant.id,productId:e.variant.productId}})),[4,T.getAvailableStockLocations({lines:e.map((function(e){return new U(e)})),stockLocationIdList:B.getPickupStockLocationIds(),cartId:this.checkout.id})]):[3,2];case 1:if(!(i=t.sent()).isSuccess)return this.error={type:Q.API_ERROR},[2];s=B.getCurrentRouting(),this.availableStockLocations=(i.data||[]).filter((function(e){var t,i,r,o;return(null===(i=null===(t=e.address)||void 0===t?void 0:t.country)||void 0===i?void 0:i.id)&&e.address.country.iso2&&(null===(r=n.shippingCountryIds)||void 0===r?void 0:r.includes(e.address.country.id))&&(!(null===(o=null==s?void 0:s.countryCodes)||void 0===o?void 0:o.length)||s.countryCodes.includes(e.address.country.iso2))})),t.label=2;case 2:return[2]}}))}))},this.checkShippingCountries=function(){var e;(null===(e=re.shippingCountryIds)||void 0===e?void 0:e.length)||(re.error={type:Q.NO_SHIPPING_ERROR})},this.onDeliveryMethodChange=function(e){var t;re.deliveryMethod!==e&&("address"===e&&(re.checkout.stockLocationId=null,(null===(t=re.customerAddresses)||void 0===t?void 0:t.length)?re.onSelectedShippingAddressIdChange(re.customerAddresses[0].id||"-1"):(re.checkout.shippingAddress=new Y,re.checkout.shippingAddress.countrySettings=re.countrySettings,re.checkout.shippingAddress.checkoutSettings=re.checkoutSettings,re.checkout.shippingAddress.shippingZones=re.shippingZones)),re.deliveryMethod=e,re.isErrorsVisible=!1)},this.initialStockCheck=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.checkStocks()];case 1:return t.sent(),[3,3];case 2:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:Q.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return e(re,void 0,void 0,(function(){var e,i,s,n,o,a,c,d,u,l,h,p,m,f=this;return t(this,(function(t){switch(t.label){case 0:return e="local"===process.env.NEXT_PUBLIC_ENV,i=B.getPaymentGateways().map((function(e){return e.id})),[4,T.listPaymentGateway({cartId:this.checkout.id,id:e?void 0:{in:i},locale:B.getCurrentLocale(),transactionAmount:this.checkout.totalFinalPrice})];case 1:return(s=t.sent()).isSuccess?(null===(h=s.data)||void 0===h?void 0:h.length)||this.isFree?(this.error=void 0,n=s.data||[],this.step===W.PAYMENT&&(n=n.filter((function(e){var t;return!(null===(t=e.supportedCurrencies)||void 0===t?void 0:t.length)||e.supportedCurrencies.includes(f.checkout.currencyCode)})),(o=null===(p=this.checkout.shippingAddress)||void 0===p?void 0:p.country)&&o.iso2&&(n=n.filter((function(e){var t;return!(null===(t=e.availableCountries)||void 0===t?void 0:t.length)||e.availableCountries.includes(o.iso2||"")}))),a=null===(m=this.checkout.billingAddress)||void 0===m?void 0:m.country,!o&&a&&a.iso2&&(n=n.filter((function(e){var t;return!(null===(t=e.availableCountries)||void 0===t?void 0:t.length)||e.availableCountries.includes(a.iso2||"")})))),c=[],r(B.getPaymentGateways(),"order").forEach((function(e){var t=null==n?void 0:n.find((function(t){return t.id===e.id}));t&&c.push(t)})),this.paymentGateways=e?n:c,d=this.paymentGateways.findIndex((function(e){return"ADYEN_PLATFORM"===e.code})),this.checkout.selectedPaymentGateway&&this.paymentGateways.some((function(e){var t;return e.id===(null===(t=f.checkout.selectedPaymentGateway)||void 0===t?void 0:t.id)}))?[3,2]:(this.setPaymentGateway(-1!==d?d:0),[3,4])):(this.error={type:Q.NO_SHIPPING_ERROR},[2]):(this.error={type:Q.API_ERROR,data:s.firstErrorMessage},[2]);case 2:return this.step!==W.PAYMENT?[3,4]:[4,this.updatePaymentGateway(this.checkout.selectedPaymentGateway)];case 3:t.sent(),t.label=4;case 4:return this.step===W.PAYMENT&&(u=n.find((function(e){return!!e.masterPassClientId})))&&(this.checkout.masterPassPaymentGateway=u,(l=document.createElement("script")).id=G,l.src=L,l.onload=function(){f.mpVM.checkMasterPass({checkout:f.checkout,store:F.getInstance()})},document.head.appendChild(l)),[2]}}))}))},this.retrieveInstallmentInfo=function(i){return e(re,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:return[4,T.retrieveInstallmentInfo(i)];case 1:return e=t.sent(),s=e.data,null===(n=null==s?void 0:s.installmentPrices)||void 0===n||n.sort((function(e,t){return(e.installmentCount||-1)>(t.installmentCount||-1)?1:-1})),this.installmentInfo=s,[2]}}))}))},this.createCustomer=function(){var e;re.store.customerStore.customer?(null===(e=re.customerAddresses)||void 0===e||e.forEach((function(e){e.checkoutSettings=re.checkoutSettings,e.shippingZones=re.shippingZones})),re.checkout.customer=new I(i(i({},re.store.customerStore.customer),{notificationsAccepted:re.store.customerStore.customer.subscriptionStatus===o.SUBSCRIBED}))):re.checkout.customer=new I(re.checkout.customer||{})},this.setCheckoutShippingAddressSettings=function(){re.checkout.shippingAddress&&(re.checkout.shippingAddress.checkoutSettings=re.checkoutSettings,re.checkout.shippingAddress.shippingZones=re.shippingZones,re.checkout.shippingAddress.countrySettings=re.countrySettings,re.checkout.shippingAddress.getValidatedCustomerAddress())},this.setCheckoutBillingAddressSettings=function(){re.checkout.billingAddress&&(re.checkout.billingAddress.checkoutSettings=re.checkoutSettings,re.checkout.billingAddress.shippingZones=re.shippingZones,re.checkout.billingAddress.countrySettings=re.countrySettings,re.checkout.billingAddress.getValidatedCustomerAddress())},this.createShippingAddress=function(){if(!re.isDigitalOnly)if(re.isInStoreDelivery)re.setCheckoutShippingAddressSettings();else if(re.checkout.shippingAddress){if(re.store.customerStore.customer){var e=null==(t=re.customerAddresses)?void 0:t.find((function(e){var t;return e.id===(null===(t=re.checkout.shippingAddress)||void 0===t?void 0:t.id)}));if(e)return re.onSelectedShippingAddressIdChange(e.id||"-1"),void re.setCheckoutShippingAddressSettings()}re.checkout.shippingAddress=new Y(n(re.checkout.shippingAddress)||{}),re.setCheckoutShippingAddressSettings()}else if(re.store.customerStore.customer){var t=re.customerAddresses;re.onSelectedShippingAddressIdChange((null==t?void 0:t.length)?t[0].id:"-1")}else re.onSelectedShippingAddressIdChange("-1")},this.createBillingAddress=function(){if("undefined"!=typeof localStorage)if(re.useDifferentAddress=!!localStorage.getItem("sAddr"),re.checkout.billingAddress){if(re.store.customerStore.customer){var e=null==(t=re.customerAddresses)?void 0:t.find((function(e){var t;return e.id===(null===(t=re.checkout.billingAddress)||void 0===t?void 0:t.id)}));if(e)return re.onSelectedBillingAddressIdChange(e.id||"-1"),void re.setCheckoutBillingAddressSettings()}re.checkout.billingAddress=new Y(n(re.checkout.billingAddress)||{}),re.setCheckoutBillingAddressSettings()}else if(re.store.customerStore.customer){var t=re.customerAddresses;re.onSelectedBillingAddressIdChange((null==t?void 0:t.length)?t[0].id:"-1"),(null==t?void 0:t.length)||re.useDifferentAddress||!re.checkout.shippingAddress||re.isInStoreDelivery||(re.checkout.billingAddress=new Y(n(re.checkout.shippingAddress)),re.setCheckoutBillingAddressSettings())}else re.onSelectedBillingAddressIdChange("-1"),re.useDifferentAddress||!re.checkout.shippingAddress||re.isInStoreDelivery||(re.checkout.billingAddress=new Y(n(re.checkout.shippingAddress)),re.setCheckoutBillingAddressSettings())},this.onShippingMethodChange=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isChangingShippingMethod?[2]:(this.isChangingShippingMethod=!0,this.checkout.shippingSettingsId=i.shippingSettingsId,this.checkout.shippingZoneRateId=i.shippingZoneRateId,[4,this.saveCart()]);case 1:return(e=t.sent())&&(this.checkout=new k(e,this.countrySettings)),this.checkout.shippingAddress&&(this.checkout.shippingAddress.checkoutSettings=this.checkoutSettings,this.checkout.shippingAddress.shippingZones=this.shippingZones),this.isChangingShippingMethod=!1,[2]}}))}))},this.onStockLocationChange=function(i){return e(re,void 0,void 0,(function(){return t(this,(function(e){return this.checkout.stockLocationId=i.id,[2]}))}))},this.onCouponCodeApply=function(){return e(re,void 0,void 0,(function(){var e,s,n,r,o,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,8,,9]),[4,D.saveCartCouponCode({cartId:this.checkout.id,couponCode:this.checkout.couponCode||null})];case 1:return(e=t.sent()).isSuccess&&e.data?(s=e.data,n=null===(a=null===(o=this.cardData)||void 0===o?void 0:o.cardNumber)||void 0===a?void 0:a.split(" ").join(""),this.couponError=null,this.step===W.PAYMENT&&(null==n?void 0:n.length)&&n.length>=6&&this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:n.slice(0,6),paymentGatewayId:this.checkout.selectedPaymentGateway.id,price:s.totalFinalPrice,currencyCode:this.checkout.currencyCode}}),this.mpVM.selectedCard&&this.mpVM.selectedCard.Value1?[4,this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:this.mpVM.selectedCard.Value1.slice(0,6),paymentGatewayId:this.mpVM.selectedCard.paymentGatewayId,price:s.totalFinalPrice,currencyCode:this.checkout.currencyCode}})]:[3,3]):[3,7];case 2:t.sent(),t.label=3;case 3:return s?(r=this.checkout,this.checkout=new k(i(i({},s),{shippingAddress:this.checkout.shippingAddress,billingAddress:this.checkout.billingAddress,customer:this.checkout.customer,selectedPaymentGateway:this.checkout.selectedPaymentGateway}),this.countrySettings),this.step!==W.PAYMENT||this.checkout.totalFinalPrice===r.totalFinalPrice&&!this.checkout.giftCardLines?[3,5]:[4,this.listPaymentGateways()]):[3,7];case 4:t.sent(),t.label=5;case 5:return this.checkout.campaignOffers=s.campaignOffers,this.isCampaignOfferLoaded=!1,[4,this.createCampaignOffer()];case 6:t.sent(),this.isCampaignOfferLoaded=!0,t.label=7;case 7:return e.isSuccess||(this.couponError=e.errorCodes[0]),[3,9];case 8:return t.sent(),[3,9];case 9:return[2]}}))}))},this.removeGiftCardLine=function(s){return e(re,void 0,void 0,(function(){var e,n,r,o,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,8,,9]),[4,D.removeGiftCardFromCart({cartId:this.checkout.id,giftCardId:s})];case 1:return(e=t.sent()).isSuccess&&e.data?(n=e.data,r=null===(a=null===(o=this.cardData)||void 0===o?void 0:o.cardNumber)||void 0===a?void 0:a.split(" ").join(""),this.couponError=null,this.step===W.PAYMENT&&(null==r?void 0:r.length)&&r.length>=6&&this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:r.slice(0,6),paymentGatewayId:this.checkout.selectedPaymentGateway.id,price:n.totalFinalPrice,currencyCode:this.checkout.currencyCode}}),this.mpVM.selectedCard&&this.mpVM.selectedCard.Value1?[4,this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:this.mpVM.selectedCard.Value1.slice(0,6),paymentGatewayId:this.mpVM.selectedCard.paymentGatewayId,price:n.totalFinalPrice,currencyCode:this.checkout.currencyCode}})]:[3,3]):[3,7];case 2:t.sent(),t.label=3;case 3:return n?(this.checkout,this.checkout=new k(i(i({},n),{shippingAddress:this.checkout.shippingAddress,billingAddress:this.checkout.billingAddress,customer:this.checkout.customer,selectedPaymentGateway:this.checkout.selectedPaymentGateway}),this.countrySettings),this.step!==W.PAYMENT?[3,5]:[4,this.listPaymentGateways()]):[3,7];case 4:t.sent(),t.label=5;case 5:return this.checkout.campaignOffers=n.campaignOffers,this.isCampaignOfferLoaded=!1,[4,this.createCampaignOffer()];case 6:t.sent(),this.isCampaignOfferLoaded=!0,t.label=7;case 7:return[3,9];case 8:return t.sent(),[3,9];case 9:return[2]}}))}))},this.getAvailableShippingZones=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,Z.getAvailableShippingZones({salesChannelId:B.getSalesChannelId()})];case 1:return e=t.sent(),this.shippingZones=e.data||null,[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(e){var t;if(re.selectedShippingAddressId=e,"-1"===e)re.checkout.shippingAddress=new Y,re.checkout.shippingAddress.countrySettings=re.countrySettings;else{var i=null===(t=re.customerAddresses)||void 0===t?void 0:t.find((function(t){return t.id===e}));i&&(re.checkout.shippingAddress=new Y(i),re.checkout.shippingAddress.countrySettings=re.countrySettings)}re.checkout.shippingAddress&&(re.checkout.shippingAddress.checkoutSettings=re.checkoutSettings,re.checkout.shippingAddress.shippingZones=re.shippingZones)},this.onSelectedBillingAddressIdChange=function(e){var t;if(re.selectedBillingAddressId=e,"-1"===e)re.checkout.billingAddress=new Y,re.checkout.billingAddress.countrySettings=re.countrySettings;else{var i=null===(t=re.customerAddresses)||void 0===t?void 0:t.find((function(t){return t.id===e}));i&&(re.checkout.billingAddress=new Y(i),re.checkout.billingAddress.countrySettings=re.countrySettings)}re.checkout.billingAddress&&(re.checkout.billingAddress.checkoutSettings=re.checkoutSettings,re.checkout.billingAddress.shippingZones=re.shippingZones)},this.onTermsAndConditionsCheckedChange=function(e){re.isTermsAndConditionsChecked=e},this.onCardNumberChange=function(e){var t;if(re.cardData&&(!(e.length>re.cardData.cardNumber.length)||ee(e))){var i=(re.cardData.cardNumber||"").split(" ").join(""),s=e.split(" ").join("");s.length>16||(i.length<6&&s.length>=6&&!re.installmentInfo?re.getRetrieveInstallmentInfo(s):s.length<6&&i.length>s.length&&(re.cardData.installmentCount=1,re.installmentInfo=void 0),(null===(t=re.installmentInfo)||void 0===t?void 0:t.cardAssociation)===_.AMERICAN_EXPRESS?re.cardData.cardNumber=function(e){var t=[],i=e.slice(0,4),s=e.slice(4,10),n=e.slice(10,15);i&&t.push(i);s&&t.push(s);n&&t.push(n);return t}(s).join(" "):re.cardData.cardNumber=$(s,4).join(" "))}},this.getRetrieveInstallmentInfo=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:i.slice(0,6),paymentGatewayId:this.checkout.selectedPaymentGateway.id,price:this.checkout.totalFinalPrice,currencyCode:this.checkout.currencyCode}})];case 1:return t.sent(),(null===(e=this.cardData)||void 0===e?void 0:e.cardNumber)&&this.onCardNumberChange(this.cardData.cardNumber),[2]}}))}))},this.onCardHolderNameChange=function(e){re.cardData&&(re.cardData.cardHolderName=e)},this.onExpirationDateChange=function(e){var t;if(re.cardData&&(!(e.length>re.cardData.expirationDate.length)||ee(e))){if(0===(null===(t=re.cardData.expirationDate)||void 0===t?void 0:t.length)){var i=e.replace(".","/").split("/");if(2===i.length){var s=i[0].trim(),n=i[1].trim();if(4===s.length&&2===n.length){var r=parseInt(s.slice(2)),o=parseInt(n);if(!isNaN(r)&&!isNaN(o))return void(re.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&4===n.length){o=parseInt(s),r=parseInt(n.slice(2));if(!isNaN(r)&&!isNaN(o))return void(re.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&2===n.length){var a=parseInt(s),c=parseInt(n);o=a<=12?a:c,r=c>12?c:a;if(!isNaN(r)&&!isNaN(o))return void(re.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var d=e.split(" / ").join("");d.length>4||(re.cardData.expirationDate=$(d,2).join(" / "))}},this.onCvcChange=function(e){if(re.cardData&&(!(e.length>re.cardData.cvv.length)||ee(e))){if(re.installmentInfo){if(re.installmentInfo.cardAssociation===_.AMERICAN_EXPRESS&&e.length>4)return;if(re.installmentInfo.cardAssociation!==_.AMERICAN_EXPRESS&&e.length>3)return}else if(e.length>3)return;re.cardData.cvv=e}},this.saveAddress=function(s){return e(re,void 0,void 0,(function(){var e,r,o,a,c,d,u,l,h,p,m,f,g=this;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),this.shouldSaveAddress&&this.store.customerStore.customer?(e="shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress,(null===(h=this.customerAddresses)||void 0===h?void 0:h.find((function(t){return t.id===(null==e?void 0:e.id)})))?[2]:(r=null===(p=this.customerAddresses)||void 0===p?void 0:p.map((function(e){return e.id})),o=new P(i(i({},e),{title:this.addressTitle||this.t("checkout-page:newAddress")})),(a=n(this.store.customerStore.customer)).addresses||(a.addresses=[]),a.addresses.push(o),[4,this.store.customerStore.saveCustomer(a)])):[3,2];case 1:t.sent(),null===(m=this.customerAddresses)||void 0===m||m.forEach((function(e){e.checkoutSettings=g.checkoutSettings,e.shippingZones=g.shippingZones})),c=null===(f=this.customerAddresses)||void 0===f?void 0:f.map((function(e){return e.id})),d=null==c?void 0:c.filter((function(e){return!(null==r?void 0:r.includes(e))})),u=(null==d?void 0:d.length)?d[0]:void 0,"shipping"===s?(this.checkout.shippingAddress.id=u||"",this.selectedShippingAddressId=u||"-1"):(this.checkout.billingAddress.id=u||"",this.selectedBillingAddressId=u||"-1"),t.label=2;case 2:return[3,4];case 3:return l=t.sent(),console.error(l),[3,4];case 4:return[2]}}))}))},this.onGoToCartClick=function(){re.router.push("/cart")},this.onBackToShoppingClick=function(){re.router.push("/")},this.onGoToLoginClick=function(){re.router.push("/account/login")},this.onHandleBillingAddressOnShippingStep=function(){return e(re,void 0,void 0,(function(){return t(this,(function(e){return this.isShowBillingAddressOnShippingStep&&!this.useDifferentAddress&&("address"===this.deliveryMethod&&this.checkout.shippingAddress?this.checkout.billingAddress=new Y(i({},this.checkout.shippingAddress)):this.checkout.billingAddress=new Y(i({},this.checkout.billingAddress))),[2]}))}))},this.onProceedToShippingClick=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isShowBillingAddressOnShippingStep?[4,this.onHandleBillingAddressOnShippingStep()]:[3,2];case 1:t.sent(),t.label=2;case 2:if("address"===this.deliveryMethod){if(!this.canProceedToShipping)return this.isErrorsVisible=!0,[2]}else if(!this.canProceedToInStoreDelivery)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=3;case 3:return t.trys.push([3,10,,11]),this.isStepLoading=!0,"address"!==this.deliveryMethod?[3,5]:[4,this.saveAddress("shipping")];case 4:t.sent(),t.label=5;case 5:return this.isShowBillingAddressOnShippingStep?[4,this.saveAddress("billing")]:[3,7];case 6:t.sent(),t.label=7;case 7:return[4,this.checkStocks()];case 8:return t.sent(),[4,this.saveCart()];case 9:return t.sent(),this.isManualOrderWithShippingLines?[2,this.changeStep(W.PAYMENT)]:("address"===this.deliveryMethod?this.changeStep(W.SHIPPING):this.changeStep(W.PAYMENT),[3,11]);case 10:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:Q.UNKNOWN}),this.isStepLoading=!1,[3,11];case 11:return[2]}}))}))},this.onProceedToDigitalOnlyPaymentClick=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isShowBillingAddressOnShippingStep?[4,this.onHandleBillingAddressOnShippingStep()]:[3,2];case 1:t.sent(),t.label=2;case 2:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=3;case 3:return t.trys.push([3,6,,7]),this.isStepLoading=!0,[4,this.checkStocks()];case 4:return t.sent(),[4,this.saveCart()];case 5:return t.sent(),this.changeStep(W.PAYMENT),[3,7];case 6:return(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:Q.UNKNOWN}),this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.onProceedToPaymentClick=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=1;case 1:return t.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return t.sent(),[4,this.saveCart()];case 3:return t.sent(),this.error=void 0,this.changeStep(W.PAYMENT),[3,5];case 4:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:Q.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.checkPaypalButtonAvailable=function(){return!!re.canPerformPayment||(re.isErrorsVisible=!0,!1)},this.handlePaymentError=function(e,t){re.error={type:e,data:t}},this.onCompletePaymentClick=function(){return e(re,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return this.canPerformPayment?(this.useDifferentAddress||(this.checkout.billingAddress=this.checkout.shippingAddress),this.isFree||!this.isKlarna?[3,2]:[4,this.saveCart()]):(this.isErrorsVisible=!0,[2]);case 1:return t.sent(),this.setIsKlarnaPaymentCompleted(!0),[2];case 2:return t.trys.push([2,8,,9]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 3:return t.sent(),"address"===this.deliveryMethod&&this.useDifferentAddress?[4,this.saveAddress("billing")]:[3,5];case 4:t.sent(),t.label=5;case 5:return[4,this.saveCart()];case 6:return t.sent(),!this.isFree&&this.isCustomFlowStripe?((e=document.querySelector("#stripe-form-btn"))&&e.click(),[2]):!this.isFree&&this.isAdyen?(this.adyenDropinElement.submit(),this.adyenDropinElement.isValid||(this.isStepLoading=!1),[2]):!this.isFree&&this.isPayPal?[2]:[4,this.createSaleTransaction()];case 7:return t.sent(),[3,9];case 8:return void 0!==typeof(i=t.sent()).type?this.error=i:this.error={type:Q.UNKNOWN},this.isStepLoading=!1,[3,9];case 9:return[2]}}))}))},this.onCompleteDigitalOnlyPaymentClick=function(){return e(re,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return!this.canProceedToPayment||this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked?(this.isErrorsVisible=!0,[2]):this.isKlarna?[4,this.saveCart()]:[3,2];case 1:return t.sent(),this.setIsKlarnaPaymentCompleted(!0),[2];case 2:return t.trys.push([2,6,,7]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 3:return t.sent(),[4,this.saveCart()];case 4:return t.sent(),this.isCustomFlowStripe?((e=document.querySelector("#stripe-form-btn"))&&e.click(),[2]):this.isAdyen?(this.adyenDropinElement.submit(),this.adyenDropinElement.isValid||(this.isStepLoading=!1),[2]):this.isPayPal?[2]:[4,this.createSaleTransaction()];case 5:return t.sent(),[3,7];case 6:return(i=t.sent()).type?this.error=i:this.error={type:Q.UNKNOWN},this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.createSaleTransaction=function(){return e(re,void 0,void 0,(function(){var e,i,s,n,r,o,a,c,d,h,p,f,g,v,y,S,k,b,P;return t(this,(function(t){switch(t.label){case 0:return i=this.mpVM.selectedCard,!this.isFree&&i&&(null===(c=this.mpVM.selectedCard)||void 0===c?void 0:c.Name)?((n=this.mpVM.phoneNumber({store:this.store,checkout:this.checkout}))&&(e=n),void 0===(null===(d=this.cardData)||void 0===d?void 0:d.installmentCount)?[2]:[4,T.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:{phoneNumber:e,savedCardName:null===(h=this.mpVM.selectedCard)||void 0===h?void 0:h.Name},paymentGatewayId:null===(p=this.mpVM.selectedCard)||void 0===p?void 0:p.paymentGatewayId,paymentMethodDetail:{cardNumber:this.mpVM.selectedCard.Value1,cardHolderName:this.mpVM.selectedCard.Name,cvv:this.mpVM.selectedCard.Value2,expiredMonth:11,expiredYear:11,installmentCount:this.cardData.installmentCount,threeDSecure:!!(null===(f=this.cardData)||void 0===f?void 0:f.threeDSecure)},metadata:{_fbp:H("_fbp"),_fbc:H("_fbc")}}})]):[3,2];case 1:return s=t.sent(),[3,4];case 2:return this.checkout.selectedPaymentGateway||this.isFree?[4,T.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:this.isFree?void 0:i&&e?{phoneNumber:e,savedCardName:null===(g=this.mpVM.selectedCard)||void 0===g?void 0:g.Name}:void 0,paymentGatewayId:this.isFree?"9d41af41-4793-4879-a19c-e9a66c929726":null===(v=this.checkout.selectedPaymentGateway)||void 0===v?void 0:v.id,paymentMethodDetail:this.isFree||i?void 0:(null===(y=this.checkout.selectedPaymentGateway)||void 0===y?void 0:y.paymentMethodType)===u.CREDIT_CARD&&(null===(S=this.checkout.selectedPaymentGateway)||void 0===S?void 0:S.type)===l.INTERNAL&&this.cardData?this.cardData.toInput():void 0,metadata:{_fbp:H("_fbp"),_fbc:H("_fbc")}}})]:[2];case 3:s=t.sent(),t.label=4;case 4:return r=null===(k=null==s?void 0:s.data)||void 0===k?void 0:k.transactionStatus,o=r&&[m.SUCCESS,m.AUTHORIZED].includes(r),a=r===m.PENDING,o?[4,this.getSuccessTransaction()]:[3,7];case 5:return t.sent(),[4,this.onCheckoutTransactionSuccess((null===(b=null==s?void 0:s.data)||void 0===b?void 0:b.orderId)||void 0)];case 6:return t.sent(),[3,8];case 7:if(!a||!(null===(P=null==s?void 0:s.data)||void 0===P?void 0:P.returnSlug))throw{data:s.firstErrorMessage,type:Q.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+s.data.returnSlug,t.label=8;case 8:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(i){return e(re,void 0,void 0,(function(){var e,s;return t(this,(function(t){switch(t.label){case 0:return localStorage.removeItem("sAddr"),(null===(e=this.checkout.customer)||void 0===e?void 0:e.notificationsAccepted)?[4,this.store.customerStore.createEmailSubscription((null===(s=this.checkout.customer)||void 0===s?void 0:s.email)||"")]:[3,2];case 1:t.sent(),t.label=2;case 2:return q.refreshJourneyId(),this.changeStep(W.SUCCESS,i),[2]}}))}))},this.onBackToInfoClick=function(){re.changeStep(W.INFO)},this.onBackToShippingClick=function(){re.changeStep(W.SHIPPING)},this.setCustomerConsentGranted=function(e){re.checkout.customer&&(re.checkout.customer.notificationsAccepted=e)},this.setUseDifferentAddress=function(e,t){var s;re.useDifferentAddress=e,re.useDifferentAddress?(localStorage.setItem("sAddr","1"),re.checkout.billingAddress=re.checkout.billingAddress||new Y,re.checkout.billingAddress.countrySettings=re.countrySettings):(localStorage.removeItem("sAddr"),re.checkout.billingAddress=new Y(i({},re.checkout.shippingAddress)),re.store.customerStore.customer&&(null===(s=re.customerAddresses)||void 0===s?void 0:s.length)&&t&&re.isShowBillingAddressOnShippingStep&&re.onSelectedBillingAddressIdChange(re.checkout.billingAddress.id||"-1"))},this.setShouldSaveAddress=function(e){re.shouldSaveAddress=e},this.setAddressTitle=function(e){re.addressTitle=e},this.reInitPaymentMethod=function(){return e(re,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?this.isCustomFlowStripe?[4,this.createStripePaymentIntent(this.checkout.selectedPaymentGateway)]:[3,2]:[3,6];case 1:e.sent(),e.label=2;case 2:return this.isKlarna&&window.location.reload(),this.isAdyen?[4,this.createAdyenBalancePlatformPaymentSession(this.checkout.selectedPaymentGateway)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.isPayPal?[4,this.getPayPalClientId(this.checkout.selectedPaymentGateway)]:[3,6];case 5:e.sent(),e.label=6;case 6:return[2]}}))}))},this.createStripePaymentIntent=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.createStripePaymentIntent({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data?(this.stripeResponse=e.data,this.stripeError=null):this.stripeError={type:Q.API_ERROR,data:e.firstErrorMessage},[2]}}))}))},this.createKlarnaClientToken=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.createKlarnaClientToken({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data?(this.klarnaResponse=e.data,this.klarnaError=null):this.klarnaError={type:Q.API_ERROR,data:e.firstErrorMessage},[2]}}))}))},this.createAdyenBalancePlatformPaymentSession=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.createAdyenBalancePlatformPaymentSession({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.adyenResponse=e.data),[2]}}))}))},this.getPayPalClientId=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.getPayPalClientId({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.payPalClientIdResponse=e.data),[2]}}))}))},this.setPaymentGateway=function(i){return e(re,void 0,void 0,(function(){var e,s;return t(this,(function(t){switch(t.label){case 0:return this.paymentGateways.length?(e=this.paymentGateways[i],s=!0,this.step!==W.PAYMENT?[3,7]:this.checkout.selectedPaymentGateway?[3,3]:"CUSTOM"!==e.code?[3,2]:[4,this.updatePaymentGateway(e)]):[2];case 1:s=t.sent(),t.label=2;case 2:return[3,7];case 3:return"CUSTOM"!==this.checkout.selectedPaymentGateway.code?[3,5]:[4,this.updatePaymentGateway(e)];case 4:return s=t.sent(),[3,7];case 5:return"CUSTOM"!==e.code?[3,7]:[4,this.updatePaymentGateway(e)];case 6:s=t.sent(),t.label=7;case 7:return s?"STRIPE"!==e.code&&"STRIPE_EU"!==e.code||this.stripeResponse?[3,9]:[4,this.createStripePaymentIntent(e)]:[2];case 8:t.sent(),t.label=9;case 9:return"KLARNA"!==e.code||this.klarnaResponse?[3,11]:[4,this.createKlarnaClientToken(e)];case 10:t.sent(),t.label=11;case 11:return"ADYEN_PLATFORM"!==e.code||this.adyenResponse?[3,13]:[4,this.createAdyenBalancePlatformPaymentSession(e)];case 12:t.sent(),t.label=13;case 13:return"PAYPAL"!==e.code||this.payPalClientIdResponse?[3,15]:[4,this.getPayPalClientId(e)];case 14:t.sent(),t.label=15;case 15:return this.checkout.selectedPaymentGateway=e,this.step!==W.SUCCESS&&(e.paymentMethodType===u.CREDIT_CARD&&e.type===l.INTERNAL&&(this.cardData=new N,e.masterPassClientId&&this.mpVM.checkMasterPass({checkout:this.checkout,store:this.store})),this.installmentInfo=void 0),[2]}}))}))},this.updatePaymentGateway=function(s){return e(re,void 0,void 0,(function(){var e,n,r;return t(this,(function(t){switch(t.label){case 0:return this.isPaymentMethodVisible=!1,[4,D.getCartById({id:this.checkout.id,getCompletedCart:!1,paymentGatewayId:s.id})];case 1:return(e=t.sent()).isSuccess?((n=e.data)&&(r=this.checkout,this.checkout=new k(i(i({},n),{shippingAddress:r.shippingAddress,billingAddress:r.billingAddress,customer:r.customer,selectedPaymentGateway:r.selectedPaymentGateway}),this.countrySettings)),this.isPaymentMethodVisible=!0,[2,!0]):(this.isPaymentMethodVisible=!0,[2,!1])}}))}))},this.setInstallmentCount=function(e){re.cardData&&(re.cardData.installmentCount=e)},this.changeStep=function(i,s){return e(re,void 0,void 0,(function(){return t(this,(function(e){return X||window.location.replace("".concat(window.location.pathname,"?id=").concat(s||this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return e(re,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:this.checkout.customer=null,this.store.customerStore.logout(),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.saveCart()];case 2:case 3:return e.sent(),[3,4];case 4:return this.createCustomer(),[2]}}))}))},this.setContactModalVisible=function(e){re.isContactModalVisible=e},this.getCampaignOffer=function(s,n){return e(re,void 0,void 0,(function(){var r,o,a=this;return t(this,(function(c){switch(c.label){case 0:return(null==n?void 0:n.length)?(r=n.filter((function(e){var t;return e.status===f.WAITING_FOR_ACTION&&(null===(t=e.campaignOffer)||void 0===t?void 0:t.targetPageTypes.some((function(e){return e===s})))})),o=r.map((function(s){return e(a,void 0,void 0,(function(){var e,n,r,o,a,c,d,u,l;return t(this,(function(t){switch(t.label){case 0:return(e=null===(d=s.campaignOffer)||void 0===d?void 0:d.offers.find((function(e){return e.id===s.campaignOfferProductId})))?(n=[e.productId],[4,x.searchProducts({input:{productIdList:n,priceListId:B.getPriceListId(),salesChannelId:B.getSalesChannelId()}})]):[2,Promise.reject()];case 1:return(r=t.sent()).isSuccess&&(null===(l=null===(u=r.data)||void 0===u?void 0:u.data)||void 0===l?void 0:l.length)?(o=r.data.data[0],(a=o.variants.filter((function(t){return t.hasStock&&!(e.excludedVariantIdList||[]).some((function(e){return e===t.id}))})).map((function(t){if(!e.discountAmount)return t;var s=!1;return e.discountType===y.AMOUNT&&(s=!0),new O(i(i({},t),{prices:t.prices.map((function(t){var n=t.finalPrice,r=t.finalPrice-(s?e.discountAmount:t.finalPrice*e.discountAmount/100);return e.applicablePrice===S.SELL_PRICE&&(n=t.sellPrice,r=t.sellPrice-(s?e.discountAmount:t.sellPrice*e.discountAmount/100)),new w(i(i({},t),{sellPrice:n,discountPrice:r}))}))}))}))).length?(c=a.find((function(e){return e.isActive})),[2,{product:new E(i(i({},o),{selectedVariantValues:(c||a[0]).variantValues,variants:a})),offer:e,campaignOffer:s}]):[2,Promise.reject()]):[2,Promise.reject()]}}))}))})),[4,Promise.allSettled(o)]):[2,[]];case 1:return[2,c.sent().filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))]}}))}))},this.createCampaignOffer=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return e=this,[4,this.getCampaignOffer(this.step===W.SUCCESS?g.POST_CHECKOUT:g.CHECKOUT,this.checkout.campaignOffers)];case 1:return e.campaignOffers=t.sent(),[2]}}))}))},this.updateCartCampaignOffer=function(i){return e(re,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:return i.accepted?this.isCheckoutLoaded=!1:this.isCampaignOfferLoaded=!1,[4,D.updateCartCampaignOffer({input:i})];case 1:return(e=t.sent()).isSuccess?i.accepted?(this.changeStep(this.step===W.SUCCESS?W.PAYMENT:this.step,null===(s=e.data)||void 0===s?void 0:s.id),[3,4]):[3,2]:[3,4];case 2:return this.checkout.campaignOffers=(null===(n=e.data)||void 0===n?void 0:n.campaignOffers)||[],[4,this.createCampaignOffer()];case 3:t.sent(),this.isCampaignOfferLoaded=!0,t.label=4;case 4:return[2]}}))}))},this.registerCustomer=function(i){return e(re,void 0,void 0,(function(){var e,s,n,r;return t(this,(function(t){switch(t.label){case 0:return this.checkout.customer?(e=this.checkout.customer,s=e.firstName,n=e.lastName,r=e.email,s&&n&&r?[4,j.register({orderId:this.checkout.id,firstName:s,lastName:n,email:r,password:i})]:[3,2]):[3,2];case 1:return[2,t.sent()];case 2:return[2]}}))}))},this.listProductFile=function(){return e(re,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return(e=this.checkout.orderLineItems.filter((function(e){return!!e.variant.fileId&&e.status!==v.REFUNDED})).map((function(e){return e.variant.fileId}))).length?[4,T.listProductFile({id:{in:e}})]:[3,2];case 1:(i=t.sent()).isSuccess&&(this.productFiles=i.data||[]),t.label=2;case 2:return[2]}}))}))},this.getDigitalProductFileDownloadUrl=function(i){return e(re,void 0,void 0,(function(){var e,s,n,r,o;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),(e=this.checkout.orderLineItems.find((function(e){return e.variant.id===i.variantId})))?[4,T.getDigitalProductFileDownloadUrl({orderId:this.checkout.id,orderLineItemId:e.id})]:[3,2];case 1:s=t.sent(),(n=s.data)&&((r=document.createElement("a")).href=n,r.download=function(e){try{return decodeURIComponent(e.split("/")[e.split("/").length-1])}catch(e){return""}}(i.name),r.click(),r.remove()),t.label=2;case 2:return[3,4];case 3:return o=t.sent(),console.error(o),[3,4];case 4:return[2]}}))}))},this.checkout=a,this.checkoutSettings=d,this.router=C,this.returnPolicy=A,this.privacyPolicy=z,this.termsOfService=J,this.imprint=te,this.shippingPolicy=ie,this.t=se,this.customizationProps=ne,this.mpVM=new M,this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked||!1,this.countrySettings=new R({currentLocale:B.getCurrentLocale()}),this.init(),s(this)}return Object.defineProperty(z.prototype,"merchantSettings",{get:function(){return new A(B.getMerchantSettings())},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"selectedPaymentGatewayIndex",{get:function(){var e=this;return this.paymentGateways.findIndex((function(t){var i;return t.id===(null===(i=e.checkout.selectedPaymentGateway)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"selectedInstallmentIndex",{get:function(){var e,t,i=this;return(null===(t=null===(e=this.installmentInfo)||void 0===e?void 0:e.installmentPrices)||void 0===t?void 0:t.findIndex((function(e){var t;return e.installmentCount===(null===(t=i.cardData)||void 0===t?void 0:t.installmentCount)})))||0},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"customerAddressOptions",{get:function(){var e,t,i={label:this.t("checkout-page:newAddress"),value:"-1"},s=(null===(t=null===(e=F.getInstance().customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===t?void 0:t.map((function(e){return{label:e.title+" - "+e.addressText,value:e.id}})))||[];return[i].concat(s)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"installmentPrice",{get:function(){var e,t,i,s=this;if(this.installmentInfo&&(null===(e=this.cardData)||void 0===e?void 0:e.installmentCount))return null===(i=null===(t=this.installmentInfo.installmentPrices)||void 0===t?void 0:t.find((function(e){var t;return e.installmentCount===(null===(t=s.cardData)||void 0===t?void 0:t.installmentCount)})))||void 0===i?void 0:i.totalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"giftCardTotalPrice",{get:function(){var e;return(null===(e=this.checkout.giftCardLines)||void 0===e?void 0:e.reduce((function(e,t){return e+t.amount}),0))||0},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-(this.checkout.totalFinalPrice-this.giftCardTotalPrice)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"finalPrice",{get:function(){return this.step===W.SUCCESS?this.checkout.totalFinalPrice-this.giftCardTotalPrice:this.installmentPrice?this.installmentPrice:this.checkout.totalFinalPrice-this.giftCardTotalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"hasStockError",{get:function(){var e;return(null===(e=this.error)||void 0===e?void 0:e.type)===Q.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isPaymentGatewayHasMasterPass",{get:function(){return-1!==this.selectedPaymentGatewayIndex&&(!!this.paymentGateways.length&&!!this.paymentGateways[this.selectedPaymentGatewayIndex].masterPassClientId)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"hasQuickRegistration",{get:function(){return this.checkoutSettings.isQuickRegistrationEnabled&&this.checkout.customer&&this.checkout.customer.isGuestCheckout},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"canProceedToShipping",{get:function(){var e,t,i;return(this.isDigitalOnly||this.isShowBillingAddressOnShippingStep?null===(e=this.checkout.billingAddress)||void 0===e?void 0:e.isValidAddress:null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.isValidAddress)&&(this.checkout.hasCustomer||this.checkout.hasValidCustomerEmail)&&(null===(i=this.error)||void 0===i?void 0:i.type)!==Q.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"canProceedToInStoreDelivery",{get:function(){var e,t,i;return!!((null===(e=this.checkout.shippingAddress)||void 0===e?void 0:e.firstName)&&(null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.lastName)&&(null===(i=this.checkout.customer)||void 0===i?void 0:i.email)&&this.checkout.stockLocationId)&&(!this.isShowBillingAddressOnShippingStep||this.canProceedToShipping)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping&&this.isValidShippingSettings},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isValidShippingSettings",{get:function(){var e,t=this;return!!(this.isInStoreDelivery||this.isDigitalOnly||this.isManualOrderWithShippingLines)||this.checkout.shippingSettingsId&&this.checkout.shippingZoneRateId&&(null===(e=this.checkout.shippingLines)||void 0===e?void 0:e.some((function(e){return e.shippingSettingsId===t.checkout.shippingSettingsId&&e.shippingZoneRateId===t.checkout.shippingZoneRateId})))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isManualOrderWithShippingLines",{get:function(){var e,t;return this.checkout.createdBy===a.ADMIN&&(null===(e=this.checkout.shippingLines)||void 0===e?void 0:e.length)&&!(null===(t=this.checkout.availableShippingMethods)||void 0===t?void 0:t.length)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isInStoreDelivery",{get:function(){return!!this.checkout.stockLocationId},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"klarnaPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"KLARNA"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"klarnaPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"KLARNA"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"adyenPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"ADYEN_PLATFORM"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"adyenPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"ADYEN_PLATFORM"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"payPalPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"PAYPAL"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"payPalPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"PAYPAL"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCustomFlowStripe",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&("STRIPE"===e.code||"STRIPE_EU"===e.code)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isKlarna",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"KLARNA"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isAdyen",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"ADYEN_PLATFORM"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isPayPal",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"PAYPAL"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isFree",{get:function(){return 0===this.checkout.totalFinalPrice||0===this.finalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"store",{get:function(){return F.getInstance()},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCouponCodeRequirementDefult",{get:function(){return this.checkoutSettings.couponCodeRequirement===c.DEFAULT||null===this.checkoutSettings.couponCodeRequirement},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCouponCodeRequirementOpen",{get:function(){return this.checkoutSettings.couponCodeRequirement===c.OPEN},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCouponCodeRequirementInvisible",{get:function(){return this.checkoutSettings.couponCodeRequirement===c.INVISIBLE},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCouponCodeVisible",{get:function(){return this.isCouponCodeRequirementDefult&&!this.isCouponCodeRequirementInvisible},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCorporateInvoiceVisible",{get:function(){return this.checkoutSettings.corporateInvoiceRequirement!==d.INVISIBLE},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isShowBillingAddressOnShippingStep",{get:function(){return this.checkoutSettings.showBillingAddressOnShippingStep},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"canPerformPayment",{get:function(){var e,t;if(this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked)return!1;var i=this.checkout.selectedPaymentGateway,s=!!("in-store"===this.deliveryMethod)||!!this.canProceedToShipping,n=!!(null===(e=this.checkout.billingAddress)||void 0===e?void 0:e.isValidAddress),r=!!this.isFree||(!!this.mpVM.selectedCard||((null==i?void 0:i.paymentMethodType)===u.CREDIT_CARD&&i.type===l.INTERNAL?!!this.isCustomFlowStripe||(!(!this.isKlarna&&!this.isPayPal)||(null===(t=this.cardData)||void 0===t?void 0:t.isValid)):!!i));return s&&n&&r},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isDigitalOnly",{get:function(){return this.checkout.shippingMethod===h.DIGITAL_DELIVERY},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"customerAddresses",{get:function(){var e,t,s,n=this,r=null===(e=B.getCurrentRouting())||void 0===e?void 0:e.countryCodes;return null===(s=null===(t=this.store.customerStore.customer)||void 0===t?void 0:t.addresses)||void 0===s?void 0:s.filter((function(e){var t;return!(null==r?void 0:r.length)||(null===(t=e.country)||void 0===t?void 0:t.iso2)&&r.includes(e.country.iso2)})).map((function(e){var t=new C(i({countrySettings:n.countrySettings},e));return t.checkoutSettings=n.checkoutSettings,t.shippingZones=n.shippingZones,t.getValidatedCustomerAddress(),t}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isManualOrder",{get:function(){return this.checkout.createdBy===a.ADMIN},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isUpsellOrder",{get:function(){return this.checkout.createdBy===a.UPSELL},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isEPayKolayEnabled",{get:function(){var e=B.getCustom();return!!e&&!!e.isEPayKolayEnabled},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isPoweredByHidden",{get:function(){var e=B.getCustom();return!!e&&!!e.hidePoweredBy},enumerable:!1,configurable:!0}),z.prototype.setAdyenDropinElement=function(e){this.adyenDropinElement=e},z}();function $(e,t){return e.match(new RegExp(".{1,"+t+"}","g"))||[]}function ee(e){return e&&z.test(e.charAt(e.length-1))}!function(e){e.INFO="info",e.SHIPPING="shipping",e.PAYMENT="payment",e.SUCCESS="success"}(W||(W={})),function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.API_ERROR=1]="API_ERROR",e[e.STOCK_ERROR=2]="STOCK_ERROR",e[e.PAYMENT_ERROR=3]="PAYMENT_ERROR",e[e.NO_SHIPPING_ERROR=4]="NO_SHIPPING_ERROR",e[e.CUSTOMER_LOGIN_REQUIRED_ERROR=5]="CUSTOMER_LOGIN_REQUIRED_ERROR",e[e.CUSTOMER_ACCOUNT_DISABLED_ERROR=6]="CUSTOMER_ACCOUNT_DISABLED_ERROR",e[e.ARGUMENT_VALIDATION_ERROR=7]="ARGUMENT_VALIDATION_ERROR"}(Q||(Q={}));export{W as CheckoutStep,Q as ErrorType,J as default};
1
+ import{__awaiter as e,__generator as t,__assign as i}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as s}from"mobx";import n from"lodash/cloneDeep";import r from"lodash/sortBy";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as o,IkasCartCreatedBy as a,IkasCouponCodeRequirement as c,IkasCorporateInvoiceRequirement as d,IkasPaymentMethodType as u,IkasPaymentGatewayType as l,IkasOrderShippingMethod as h,IkasOrderPaymentStatus as p,IkasTransactionStatus as m,IkasCartCampaignOfferStatus as f,IkasCampaignOfferTargetPageType as g,IkasOrderLineItemStatus as v,IkasAmountType as y,IkasCampaignOfferProductApplicablePriceEnum as S}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import{IkasCheckout as k}from"../../models/data/checkout/index.js";import{IkasCheckoutSettings as b}from"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import{IkasCustomerAddress as P}from"../../models/data/customer/address/index.js";import{IkasLocalizedCustomerAddress as C}from"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import{IkasMerchantSettings as A}from"../../models/data/merchant-settings/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import{IkasOrderCustomer as I}from"../../models/data/order/customer/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import{IkasProductPrice as w}from"../../models/data/product/variant/price/index.js";import{IkasProductVariant as O}from"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import{IkasProduct as E}from"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import{LocalizedAddressModel as R}from"@ikas/localized-address";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/customer-review-summary-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/ikas-address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import N from"./components/credit-card-form/model.js";import j from"../../store/customer/api.js";import T from"../../store/checkout/index.js";import D from"../../store/cart/api.js";import M,{MFS_ELEMENT_ID as G,MFS_SCRIPT_URL as L}from"./modelMasterPass.js";import x from"../../store/product/index.js";import{TransactionCardAssociationEnum as _,SaveCartInput as V,CheckStocksLineInput as U}from"@ikas/storefront-api";import{IkasBaseStore as F}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import{IkasStorefrontConfig as B}from"@ikas/storefront-config";import{Analytics as K}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import Y from"../../models/data/order/address/ikas-localized-order-address.js";import Z from"../../store/location/index.js";import{getCookieValue as H}from"../../utils/helper.js";import q from"../../analytics/ikasV3.js";var W,Q,z=/^\d+$/,X="undefined"==typeof localStorage,J=function(){function z(a,d,C,A,z,J,te,ie,se,ne){var re=this;this.storefront=null,this.isCheckoutLoaded=!1,this.isErrorsVisible=!1,this.isStepLoading=!1,this.isTermsAndConditionsChecked=!1,this.isChangingShippingMethod=!1,this.isContactModalVisible=!1,this.isPaymentMethodVisible=!0,this.step=W.INFO,this.customizationProps=null,this.cardData=null,this.paymentGateways=[],this.productFiles=[],this.installmentInfo=null,this.useDifferentAddress=!1,this.shouldSaveAddress=!0,this.addressTitle="",this.shippingCountryIds=null,this.selectedShippingAddressId="-1",this.selectedBillingAddressId="-1",this.stockLocations=[],this.availableStockLocations=[],this.deliveryMethod="address",this.stripeResponse=null,this.stripeError=null,this.klarnaResponse=null,this.isKlarnaPaymentCompleted=!1,this.klarnaError=null,this.adyenResponse=null,this.payPalClientIdResponse=null,this.paypalOrderResponse=null,this.isCampaignOfferLoaded=!0,this.shippingZones=null,this.policyModalTitle="",this.policyModalText="",this.error=null,this.couponError=null,this.showTestModal=!1,this.init=function(){return e(re,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this.countrySettings.waitUntilInitialized()];case 1:return e.sent(),[4,F.getInstance().customerStore.waitUntilInitialized()];case 2:return e.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.initStep()];case 3:return e.sent(),[2]}}))}))},this.initStep=function(){return e(re,void 0,void 0,(function(){var e,s,n,r,o,a,d;return t(this,(function(t){switch(t.label){case 0:if(B.getIsEditor())return this.step=W.INFO,this.isCheckoutLoaded=!0,[2];if(e=new URLSearchParams(window.location.search),s=e.get("step"),n=e.get("failed"),r=e.get("error"),s){if(this.step=s,this.step===W.SHIPPING&&!this.canProceedToShipping)return[2,this.changeStep(W.INFO)];if(this.step!==W.PAYMENT||this.canProceedToPayment){if(this.step===W.SUCCESS&&!this.canProceedToPayment)return[2,this.changeStep(W.INFO)];if(![W.INFO,W.SUCCESS,W.SHIPPING,W.PAYMENT].includes(this.step))return[2,this.changeStep(W.INFO)]}else{if(!this.isInStoreDelivery)return this.isValidShippingSettings?[2,this.changeStep(W.INFO)]:[2,this.changeStep(W.SHIPPING)];this.deliveryMethod="in-store"}}return[4,this.createCampaignOffer()];case 1:return t.sent(),this.step!==W.SHIPPING&&this.step!==W.PAYMENT||this.isCouponCodeRequirementInvisible||(this.checkoutSettings=new b(i(i({},this.checkoutSettings),{couponCodeRequirement:c.DEFAULT}))),this.step!==W.INFO?[3,7]:this.isDigitalOnly?[3,4]:[4,this.getAvailableShippingZones()];case 2:return t.sent(),this.createCustomer(),this.createShippingAddress(),this.createBillingAddress(),[4,this.getShippingCountries()];case 3:t.sent(),this.checkShippingCountries(),t.label=4;case 4:return[4,this.getStockLocations()];case 5:return t.sent(),[4,this.getAvailableStockLocations()];case 6:t.sent(),this.isInStoreDelivery&&(this.deliveryMethod="in-store"),t.label=7;case 7:return this.step!==W.SHIPPING||1!==(null===(a=this.checkout.availableShippingMethods)||void 0===a?void 0:a.length)||this.checkoutSettings.isGiftPackageEnabled||(this.step=W.PAYMENT,this.router.replace("/checkout?id=".concat(this.checkout.id,"&step=").concat(this.step),void 0,{shallow:!0})),this.step!==W.SHIPPING||(null===(d=this.checkout.availableShippingMethods)||void 0===d?void 0:d.length)?this.step!==W.SUCCESS||this.checkout.orderPaymentStatus!==p.PAID?[3,9]:[4,this.listProductFile()]:(this.error={type:Q.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2]);case 8:t.sent(),t.label=9;case 9:return this.step!==W.PAYMENT&&this.step!==W.SUCCESS?[3,13]:[4,this.listPaymentGateways()];case 10:return t.sent(),this.isInStoreDelivery?(this.deliveryMethod="in-store",[4,this.getStockLocations()]):[3,12];case 11:t.sent(),t.label=12;case 12:if(!this.paymentGateways.length&&!this.isFree)return this.error={type:Q.NO_SHIPPING_ERROR},this.isCheckoutLoaded=!0,[2];t.label=13;case 13:return this.step===W.SUCCESS?[3,17]:this.checkout.isComplete?[2,this.changeStep(W.SUCCESS)]:[3,14];case 14:return[4,this.initialStockCheck()];case 15:t.sent(),t.label=16;case 16:return[3,19];case 17:return[4,this.getSuccessTransaction()];case 18:t.sent(),this.successTransaction&&(o=this.successTransaction.paymentGatewayId,this.checkout.selectedPaymentGateway=this.paymentGateways.find((function(e){return e.id===o}))),t.label=19;case 19:return n&&(this.error={type:Q.PAYMENT_ERROR,data:r||null}),this.isCheckoutLoaded=!0,K.checkoutStep(this.checkout,this.step),[2]}}))}))},this.getSuccessTransaction=function(){return e(re,void 0,void 0,(function(){var e,i,s;return t(this,(function(t){switch(t.label){case 0:return[4,j.listOrderTransactions({orderId:{eq:this.checkout.id}})];case 1:return e=t.sent(),this.successTransactions=e.isSuccess&&(null===(i=e.data)||void 0===i?void 0:i.length)?e.data:[],this.successTransaction=e.isSuccess&&(null===(s=e.data)||void 0===s?void 0:s.length)?e.data[e.data.length-1]:void 0,[2]}}))}))},this.saveCart=function(){return e(re,void 0,void 0,(function(){var e,i,s,n,r,a,c,d,u;return t(this,(function(t){switch(t.label){case 0:return e=new V(this.checkout),"in-store"!==this.deliveryMethod?[3,2]:[4,this.inStockDeliveryInputData(e)];case 1:e=t.sent(),t.label=2;case 2:return this.step!==W.INFO&&this.step!==W.SHIPPING||this.isDigitalOnly||(this.isShowBillingAddressOnShippingStep||(e.billingAddress=null),this.isShowBillingAddressOnShippingStep&&this.useDifferentAddress&&e.billingAddress&&(e.billingAddress.company=(null===(n=e.shippingAddress)||void 0===n?void 0:n.company)||null,e.billingAddress.taxNumber=(null===(r=e.shippingAddress)||void 0===r?void 0:r.taxNumber)||null,e.billingAddress.taxOffice=(null===(a=e.shippingAddress)||void 0===a?void 0:a.taxOffice)||null)),this.isDigitalOnly&&(e.shippingAddress=null),e.customer&&(this.store.customerStore.customer?e.customer.notificationsAccepted=this.store.customerStore.customer.subscriptionStatus===o.SUBSCRIBED:this.checkout.customer&&(e.customer.notificationsAccepted=this.checkout.customer.notificationsAccepted||!1)),[4,D.saveCart({input:e})];case 3:if((null==(i=t.sent())?void 0:i.graphQLErrors)&&i.graphQLErrors.length)throw s=i.graphQLErrors[0],"CUSTOMER_LOGIN_REQUIRED"===(null===(c=s.extensions)||void 0===c?void 0:c.code)?{type:Q.CUSTOMER_LOGIN_REQUIRED_ERROR}:"CUSTOMER_ACCOUNT_DISABLED"===(null===(d=s.extensions)||void 0===d?void 0:d.code)?{type:Q.CUSTOMER_ACCOUNT_DISABLED_ERROR}:"ARGUMENT_VALIDATION_ERROR"===(null===(u=s.extensions)||void 0===u?void 0:u.code)?{type:Q.ARGUMENT_VALIDATION_ERROR,data:s.extensions.validationErrors}:{type:Q.API_ERROR,data:i.firstErrorMessage};return[2,i.data]}}))}))},this.inStockDeliveryInputData=function(i){return e(re,void 0,void 0,(function(){var e,s,n=this;return t(this,(function(t){return e=i,(s=this.stockLocations.find((function(e){return e.id===n.checkout.stockLocationId})))&&e.shippingAddress&&s.address&&(e.shippingAddress.country=s.address.country,e.shippingAddress.city=s.address.city,e.shippingAddress.state=s.address.state,e.shippingAddress.district=s.address.district,e.shippingAddress.postalCode=s.address.postalCode,e.shippingAddress.addressLine1=s.address.address||"",e.shippingAddress.addressLine2=null),[2,e]}))}))},this.checkStocks=function(){return e(re,void 0,void 0,(function(){var e,i,s,n,r,o,a,c,d,u,l,p;return t(this,(function(t){switch(t.label){case 0:return this.isManualOrder?[2]:(e=this.checkout.stockLocationId&&this.checkout.shippingMethod===h.CLICK_AND_COLLECT?[this.checkout.stockLocationId]:(null===(u=B.getStockLocationIds())||void 0===u?void 0:u.length)?B.getStockLocationIds():null,[4,T.checkCartStocks({cartId:this.checkout.id,stockLocationIdList:e})]);case 1:if(!(i=t.sent()).isSuccess)throw{type:Q.API_ERROR,data:i.firstErrorMessage};if(null==(s=null===(p=null===(l=i.data)||void 0===l?void 0:l.lines)||void 0===p?void 0:p.filter((function(e){return!e.isAvailable})))?void 0:s.length){for(n=[],r=function(e){var t=o.checkout.items.find((function(t){return t.variant.id===e.variantId}));t&&n.push({item:t,stockCount:e.stockCount})},o=this,a=0,c=s;a<c.length;a++)d=c[a],r(d);throw{type:Q.STOCK_ERROR,data:n}}return[2]}}))}))},this.setIsKlarnaPaymentCompleted=function(i){return e(re,void 0,void 0,(function(){return t(this,(function(e){return this.isKlarnaPaymentCompleted=i,[2]}))}))},this.removeUnavailableItems=function(i){return e(re,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:e=0,s=i,t.label=1;case 1:return e<s.length?(n=s[e],[4,F.getInstance().cartStore.changeItemQuantity(n.item,n.stockCount<0?0:n.stockCount)]):[3,4];case 2:t.sent(),t.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))},this.getShippingCountries=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.getAvailableShippingCountries({salesChannelId:B.getSalesChannelId()})];case 1:return e=t.sent(),this.shippingCountryIds=e.data,[2]}}))}))},this.getStockLocations=function(){return e(re,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return B.getPickupStockLocationIds()?[4,T.listStockLocation({id:{in:B.getPickupStockLocationIds()}})]:[3,2];case 1:if(!(e=t.sent()).isSuccess||!(null===(i=e.data)||void 0===i?void 0:i.length))return this.error={type:Q.API_ERROR,data:e.firstErrorMessage},[2];this.stockLocations=e.data,t.label=2;case 2:return[2]}}))}))},this.getAvailableStockLocations=function(){return e(re,void 0,void 0,(function(){var e,i,s,n=this;return t(this,(function(t){switch(t.label){case 0:return B.getPickupStockLocationIds()?(e=this.checkout.items.map((function(e){return{quantity:e.quantity,variantId:e.variant.id,productId:e.variant.productId}})),[4,T.getAvailableStockLocations({lines:e.map((function(e){return new U(e)})),stockLocationIdList:B.getPickupStockLocationIds(),cartId:this.checkout.id})]):[3,2];case 1:if(!(i=t.sent()).isSuccess)return this.error={type:Q.API_ERROR},[2];s=B.getCurrentRouting(),this.availableStockLocations=(i.data||[]).filter((function(e){var t,i,r,o;return(null===(i=null===(t=e.address)||void 0===t?void 0:t.country)||void 0===i?void 0:i.id)&&e.address.country.iso2&&(null===(r=n.shippingCountryIds)||void 0===r?void 0:r.includes(e.address.country.id))&&(!(null===(o=null==s?void 0:s.countryCodes)||void 0===o?void 0:o.length)||s.countryCodes.includes(e.address.country.iso2))})),t.label=2;case 2:return[2]}}))}))},this.checkShippingCountries=function(){var e;(null===(e=re.shippingCountryIds)||void 0===e?void 0:e.length)||(re.error={type:Q.NO_SHIPPING_ERROR})},this.onDeliveryMethodChange=function(e){var t;re.deliveryMethod!==e&&("address"===e&&(re.checkout.stockLocationId=null,(null===(t=re.customerAddresses)||void 0===t?void 0:t.length)?re.onSelectedShippingAddressIdChange(re.customerAddresses[0].id||"-1"):(re.checkout.shippingAddress=new Y,re.checkout.shippingAddress.countrySettings=re.countrySettings,re.checkout.shippingAddress.checkoutSettings=re.checkoutSettings,re.checkout.shippingAddress.shippingZones=re.shippingZones)),re.deliveryMethod=e,re.isErrorsVisible=!1)},this.initialStockCheck=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.checkStocks()];case 1:return t.sent(),[3,3];case 2:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:Q.UNKNOWN}),[3,3];case 3:return[2]}}))}))},this.listPaymentGateways=function(){return e(re,void 0,void 0,(function(){var e,i,s,n,o,a,c,d,u,l,h,p,m,f=this;return t(this,(function(t){switch(t.label){case 0:return e="local"===process.env.NEXT_PUBLIC_ENV,i=B.getPaymentGateways().map((function(e){return e.id})),[4,T.listPaymentGateway({cartId:this.checkout.id,id:e?void 0:{in:i},locale:B.getCurrentLocale(),transactionAmount:this.checkout.totalFinalPrice})];case 1:return(s=t.sent()).isSuccess?(null===(h=s.data)||void 0===h?void 0:h.length)||this.isFree?(this.error=void 0,n=s.data||[],this.step===W.PAYMENT&&(n=n.filter((function(e){var t;return!(null===(t=e.supportedCurrencies)||void 0===t?void 0:t.length)||e.supportedCurrencies.includes(f.checkout.currencyCode)})),(o=null===(p=this.checkout.shippingAddress)||void 0===p?void 0:p.country)&&o.iso2&&(n=n.filter((function(e){var t;return!(null===(t=e.availableCountries)||void 0===t?void 0:t.length)||e.availableCountries.includes(o.iso2||"")}))),a=null===(m=this.checkout.billingAddress)||void 0===m?void 0:m.country,!o&&a&&a.iso2&&(n=n.filter((function(e){var t;return!(null===(t=e.availableCountries)||void 0===t?void 0:t.length)||e.availableCountries.includes(a.iso2||"")})))),c=[],r(B.getPaymentGateways(),"order").forEach((function(e){var t=null==n?void 0:n.find((function(t){return t.id===e.id}));t&&c.push(t)})),this.paymentGateways=e?n:c,d=this.paymentGateways.findIndex((function(e){return"ADYEN_PLATFORM"===e.code})),this.checkout.selectedPaymentGateway&&this.paymentGateways.some((function(e){var t;return e.id===(null===(t=f.checkout.selectedPaymentGateway)||void 0===t?void 0:t.id)}))?[3,2]:(this.setPaymentGateway(-1!==d?d:0),[3,4])):(this.error={type:Q.NO_SHIPPING_ERROR},[2]):(this.error={type:Q.API_ERROR,data:s.firstErrorMessage},[2]);case 2:return this.step!==W.PAYMENT?[3,4]:[4,this.updatePaymentGateway(this.checkout.selectedPaymentGateway)];case 3:t.sent(),t.label=4;case 4:return this.step===W.PAYMENT&&(u=n.find((function(e){return!!e.masterPassClientId})))&&(this.checkout.masterPassPaymentGateway=u,(l=document.createElement("script")).id=G,l.src=L,l.onload=function(){f.mpVM.checkMasterPass({checkout:f.checkout,store:F.getInstance()})},document.head.appendChild(l)),[2]}}))}))},this.retrieveInstallmentInfo=function(i){return e(re,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:return[4,T.retrieveInstallmentInfo(i)];case 1:return e=t.sent(),s=e.data,null===(n=null==s?void 0:s.installmentPrices)||void 0===n||n.sort((function(e,t){return(e.installmentCount||-1)>(t.installmentCount||-1)?1:-1})),this.installmentInfo=s,[2]}}))}))},this.createCustomer=function(){var e;re.store.customerStore.customer?(null===(e=re.customerAddresses)||void 0===e||e.forEach((function(e){e.checkoutSettings=re.checkoutSettings,e.shippingZones=re.shippingZones})),re.checkout.customer=new I(i(i({},re.store.customerStore.customer),{notificationsAccepted:re.store.customerStore.customer.subscriptionStatus===o.SUBSCRIBED}))):re.checkout.customer=new I(re.checkout.customer||{})},this.setCheckoutShippingAddressSettings=function(){re.checkout.shippingAddress&&(re.checkout.shippingAddress.checkoutSettings=re.checkoutSettings,re.checkout.shippingAddress.shippingZones=re.shippingZones,re.checkout.shippingAddress.countrySettings=re.countrySettings,re.checkout.shippingAddress.getValidatedCustomerAddress())},this.setCheckoutBillingAddressSettings=function(){re.checkout.billingAddress&&(re.checkout.billingAddress.checkoutSettings=re.checkoutSettings,re.checkout.billingAddress.shippingZones=re.shippingZones,re.checkout.billingAddress.countrySettings=re.countrySettings,re.checkout.billingAddress.getValidatedCustomerAddress())},this.createShippingAddress=function(){if(!re.isDigitalOnly)if(re.isInStoreDelivery)re.setCheckoutShippingAddressSettings();else if(re.checkout.shippingAddress){if(re.store.customerStore.customer){var e=null==(t=re.customerAddresses)?void 0:t.find((function(e){var t;return e.id===(null===(t=re.checkout.shippingAddress)||void 0===t?void 0:t.id)}));if(e)return re.onSelectedShippingAddressIdChange(e.id||"-1"),void re.setCheckoutShippingAddressSettings()}re.checkout.shippingAddress=new Y(n(re.checkout.shippingAddress)||{}),re.setCheckoutShippingAddressSettings()}else if(re.store.customerStore.customer){var t=re.customerAddresses;re.onSelectedShippingAddressIdChange((null==t?void 0:t.length)?t[0].id:"-1")}else re.onSelectedShippingAddressIdChange("-1")},this.createBillingAddress=function(){if("undefined"!=typeof localStorage)if(re.useDifferentAddress=!!localStorage.getItem("sAddr"),re.checkout.billingAddress){if(re.store.customerStore.customer){var e=null==(t=re.customerAddresses)?void 0:t.find((function(e){var t;return e.id===(null===(t=re.checkout.billingAddress)||void 0===t?void 0:t.id)}));if(e)return re.onSelectedBillingAddressIdChange(e.id||"-1"),void re.setCheckoutBillingAddressSettings()}re.checkout.billingAddress=new Y(n(re.checkout.billingAddress)||{}),re.setCheckoutBillingAddressSettings()}else if(re.store.customerStore.customer){var t=re.customerAddresses;re.onSelectedBillingAddressIdChange((null==t?void 0:t.length)?t[0].id:"-1"),(null==t?void 0:t.length)||re.useDifferentAddress||!re.checkout.shippingAddress||re.isInStoreDelivery||(re.checkout.billingAddress=new Y(n(re.checkout.shippingAddress)),re.setCheckoutBillingAddressSettings())}else re.onSelectedBillingAddressIdChange("-1"),re.useDifferentAddress||!re.checkout.shippingAddress||re.isInStoreDelivery||(re.checkout.billingAddress=new Y(n(re.checkout.shippingAddress)),re.setCheckoutBillingAddressSettings())},this.onShippingMethodChange=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isChangingShippingMethod?[2]:(this.isChangingShippingMethod=!0,this.checkout.shippingSettingsId=i.shippingSettingsId,this.checkout.shippingZoneRateId=i.shippingZoneRateId,[4,this.saveCart()]);case 1:return(e=t.sent())&&(this.checkout=new k(e,this.countrySettings)),this.checkout.shippingAddress&&(this.checkout.shippingAddress.checkoutSettings=this.checkoutSettings,this.checkout.shippingAddress.shippingZones=this.shippingZones),this.isChangingShippingMethod=!1,[2]}}))}))},this.onStockLocationChange=function(i){return e(re,void 0,void 0,(function(){return t(this,(function(e){return this.checkout.stockLocationId=i.id,[2]}))}))},this.onCouponCodeApply=function(){return e(re,void 0,void 0,(function(){var e,s,n,r,o,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,8,,9]),[4,D.saveCartCouponCode({cartId:this.checkout.id,couponCode:this.checkout.couponCode||null})];case 1:return(e=t.sent()).isSuccess&&e.data?(s=e.data,n=null===(a=null===(o=this.cardData)||void 0===o?void 0:o.cardNumber)||void 0===a?void 0:a.split(" ").join(""),this.couponError=null,this.step===W.PAYMENT&&(null==n?void 0:n.length)&&n.length>=6&&this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:n.slice(0,6),paymentGatewayId:this.checkout.selectedPaymentGateway.id,price:s.totalFinalPrice,currencyCode:this.checkout.currencyCode}}),this.mpVM.selectedCard&&this.mpVM.selectedCard.Value1?[4,this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:this.mpVM.selectedCard.Value1.slice(0,6),paymentGatewayId:this.mpVM.selectedCard.paymentGatewayId,price:s.totalFinalPrice,currencyCode:this.checkout.currencyCode}})]:[3,3]):[3,7];case 2:t.sent(),t.label=3;case 3:return s?(r=this.checkout,this.checkout=new k(i(i({},s),{shippingAddress:this.checkout.shippingAddress,billingAddress:this.checkout.billingAddress,customer:this.checkout.customer,selectedPaymentGateway:this.checkout.selectedPaymentGateway}),this.countrySettings),this.step!==W.PAYMENT||this.checkout.totalFinalPrice===r.totalFinalPrice&&!this.checkout.giftCardLines?[3,5]:[4,this.listPaymentGateways()]):[3,7];case 4:t.sent(),t.label=5;case 5:return this.checkout.campaignOffers=s.campaignOffers,this.isCampaignOfferLoaded=!1,[4,this.createCampaignOffer()];case 6:t.sent(),this.isCampaignOfferLoaded=!0,t.label=7;case 7:return e.isSuccess||(this.couponError=e.errorCodes[0]),[3,9];case 8:return t.sent(),[3,9];case 9:return[2]}}))}))},this.removeGiftCardLine=function(s){return e(re,void 0,void 0,(function(){var e,n,r,o,a;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,8,,9]),[4,D.removeGiftCardFromCart({cartId:this.checkout.id,giftCardId:s})];case 1:return(e=t.sent()).isSuccess&&e.data?(n=e.data,r=null===(a=null===(o=this.cardData)||void 0===o?void 0:o.cardNumber)||void 0===a?void 0:a.split(" ").join(""),this.couponError=null,this.step===W.PAYMENT&&(null==r?void 0:r.length)&&r.length>=6&&this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:r.slice(0,6),paymentGatewayId:this.checkout.selectedPaymentGateway.id,price:n.totalFinalPrice,currencyCode:this.checkout.currencyCode}}),this.mpVM.selectedCard&&this.mpVM.selectedCard.Value1?[4,this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:this.mpVM.selectedCard.Value1.slice(0,6),paymentGatewayId:this.mpVM.selectedCard.paymentGatewayId,price:n.totalFinalPrice,currencyCode:this.checkout.currencyCode}})]:[3,3]):[3,7];case 2:t.sent(),t.label=3;case 3:return n?(this.checkout,this.checkout=new k(i(i({},n),{shippingAddress:this.checkout.shippingAddress,billingAddress:this.checkout.billingAddress,customer:this.checkout.customer,selectedPaymentGateway:this.checkout.selectedPaymentGateway}),this.countrySettings),this.step!==W.PAYMENT?[3,5]:[4,this.listPaymentGateways()]):[3,7];case 4:t.sent(),t.label=5;case 5:return this.checkout.campaignOffers=n.campaignOffers,this.isCampaignOfferLoaded=!1,[4,this.createCampaignOffer()];case 6:t.sent(),this.isCampaignOfferLoaded=!0,t.label=7;case 7:return[3,9];case 8:return t.sent(),[3,9];case 9:return[2]}}))}))},this.getAvailableShippingZones=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,Z.getAvailableShippingZones({salesChannelId:B.getSalesChannelId()})];case 1:return e=t.sent(),this.shippingZones=e.data||null,[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}}))}))},this.onSelectedShippingAddressIdChange=function(e){var t;if(re.selectedShippingAddressId=e,"-1"===e)re.checkout.shippingAddress=new Y,re.checkout.shippingAddress.countrySettings=re.countrySettings;else{var i=null===(t=re.customerAddresses)||void 0===t?void 0:t.find((function(t){return t.id===e}));i&&(re.checkout.shippingAddress=new Y(i),re.checkout.shippingAddress.countrySettings=re.countrySettings)}re.checkout.shippingAddress&&(re.checkout.shippingAddress.checkoutSettings=re.checkoutSettings,re.checkout.shippingAddress.shippingZones=re.shippingZones)},this.onSelectedBillingAddressIdChange=function(e){var t;if(re.selectedBillingAddressId=e,"-1"===e)re.checkout.billingAddress=new Y,re.checkout.billingAddress.countrySettings=re.countrySettings;else{var i=null===(t=re.customerAddresses)||void 0===t?void 0:t.find((function(t){return t.id===e}));i&&(re.checkout.billingAddress=new Y(i),re.checkout.billingAddress.countrySettings=re.countrySettings)}re.checkout.billingAddress&&(re.checkout.billingAddress.checkoutSettings=re.checkoutSettings,re.checkout.billingAddress.shippingZones=re.shippingZones)},this.onTermsAndConditionsCheckedChange=function(e){re.isTermsAndConditionsChecked=e},this.onCardNumberChange=function(e){var t;if(re.cardData&&(!(e.length>re.cardData.cardNumber.length)||ee(e))){var i=(re.cardData.cardNumber||"").split(" ").join(""),s=e.split(" ").join("");s.length>16||(i.length<6&&s.length>=6&&!re.installmentInfo?re.getRetrieveInstallmentInfo(s):s.length<6&&i.length>s.length&&(re.cardData.installmentCount=1,re.installmentInfo=void 0),(null===(t=re.installmentInfo)||void 0===t?void 0:t.cardAssociation)===_.AMERICAN_EXPRESS?re.cardData.cardNumber=function(e){var t=[],i=e.slice(0,4),s=e.slice(4,10),n=e.slice(10,15);i&&t.push(i);s&&t.push(s);n&&t.push(n);return t}(s).join(" "):re.cardData.cardNumber=$(s,4).join(" "))}},this.getRetrieveInstallmentInfo=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,this.retrieveInstallmentInfo({input:{orderId:this.checkout.id,binNumber:i.slice(0,6),paymentGatewayId:this.checkout.selectedPaymentGateway.id,price:this.checkout.totalFinalPrice,currencyCode:this.checkout.currencyCode}})];case 1:return t.sent(),(null===(e=this.cardData)||void 0===e?void 0:e.cardNumber)&&this.onCardNumberChange(this.cardData.cardNumber),[2]}}))}))},this.onCardHolderNameChange=function(e){re.cardData&&(re.cardData.cardHolderName=e)},this.onExpirationDateChange=function(e){var t;if(re.cardData&&(!(e.length>re.cardData.expirationDate.length)||ee(e))){if(0===(null===(t=re.cardData.expirationDate)||void 0===t?void 0:t.length)){var i=e.replace(".","/").split("/");if(2===i.length){var s=i[0].trim(),n=i[1].trim();if(4===s.length&&2===n.length){var r=parseInt(s.slice(2)),o=parseInt(n);if(!isNaN(r)&&!isNaN(o))return void(re.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&4===n.length){o=parseInt(s),r=parseInt(n.slice(2));if(!isNaN(r)&&!isNaN(o))return void(re.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}if(2===s.length&&2===n.length){var a=parseInt(s),c=parseInt(n);o=a<=12?a:c,r=c>12?c:a;if(!isNaN(r)&&!isNaN(o))return void(re.cardData.expirationDate="".concat(o<10?"0"+o:o," / ").concat(r<10?"0"+r:r))}}}var d=e.split(" / ").join("");d.length>4||(re.cardData.expirationDate=$(d,2).join(" / "))}},this.onCvcChange=function(e){if(re.cardData&&(!(e.length>re.cardData.cvv.length)||ee(e))){if(re.installmentInfo){if(re.installmentInfo.cardAssociation===_.AMERICAN_EXPRESS&&e.length>4)return;if(re.installmentInfo.cardAssociation!==_.AMERICAN_EXPRESS&&e.length>3)return}else if(e.length>3)return;re.cardData.cvv=e}},this.saveAddress=function(s){return e(re,void 0,void 0,(function(){var e,r,o,a,c,d,u,l,h,p,m,f,g=this;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),this.shouldSaveAddress&&this.store.customerStore.customer?(e="shipping"===s?this.checkout.shippingAddress:this.checkout.billingAddress,(null===(h=this.customerAddresses)||void 0===h?void 0:h.find((function(t){return t.id===(null==e?void 0:e.id)})))?[2]:(r=null===(p=this.customerAddresses)||void 0===p?void 0:p.map((function(e){return e.id})),o=new P(i(i({},e),{title:this.addressTitle||this.t("checkout-page:newAddress")})),(a=n(this.store.customerStore.customer)).addresses||(a.addresses=[]),a.addresses.push(o),[4,this.store.customerStore.saveCustomer(a)])):[3,2];case 1:t.sent(),null===(m=this.customerAddresses)||void 0===m||m.forEach((function(e){e.checkoutSettings=g.checkoutSettings,e.shippingZones=g.shippingZones})),c=null===(f=this.customerAddresses)||void 0===f?void 0:f.map((function(e){return e.id})),d=null==c?void 0:c.filter((function(e){return!(null==r?void 0:r.includes(e))})),u=(null==d?void 0:d.length)?d[0]:void 0,"shipping"===s?(this.checkout.shippingAddress.id=u||"",this.selectedShippingAddressId=u||"-1"):(this.checkout.billingAddress.id=u||"",this.selectedBillingAddressId=u||"-1"),t.label=2;case 2:return[3,4];case 3:return l=t.sent(),console.error(l),[3,4];case 4:return[2]}}))}))},this.onGoToCartClick=function(){re.router.push("/cart")},this.onBackToShoppingClick=function(){re.router.push("/")},this.onGoToLoginClick=function(){re.router.push("/account/login")},this.onHandleBillingAddressOnShippingStep=function(){return e(re,void 0,void 0,(function(){return t(this,(function(e){return this.isShowBillingAddressOnShippingStep&&!this.useDifferentAddress&&("address"===this.deliveryMethod&&this.checkout.shippingAddress?this.checkout.billingAddress=new Y(i({},this.checkout.shippingAddress)):this.checkout.billingAddress=new Y(i({},this.checkout.billingAddress))),[2]}))}))},this.onProceedToShippingClick=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isShowBillingAddressOnShippingStep?[4,this.onHandleBillingAddressOnShippingStep()]:[3,2];case 1:t.sent(),t.label=2;case 2:if("address"===this.deliveryMethod){if(!this.canProceedToShipping)return this.isErrorsVisible=!0,[2]}else if(!this.canProceedToInStoreDelivery)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=3;case 3:return t.trys.push([3,10,,11]),this.isStepLoading=!0,"address"!==this.deliveryMethod?[3,5]:[4,this.saveAddress("shipping")];case 4:t.sent(),t.label=5;case 5:return this.isShowBillingAddressOnShippingStep?[4,this.saveAddress("billing")]:[3,7];case 6:t.sent(),t.label=7;case 7:return[4,this.checkStocks()];case 8:return t.sent(),[4,this.saveCart()];case 9:return t.sent(),this.isManualOrderWithShippingLines?[2,this.changeStep(W.PAYMENT)]:("address"===this.deliveryMethod?this.changeStep(W.SHIPPING):this.changeStep(W.PAYMENT),[3,11]);case 10:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:Q.UNKNOWN}),this.isStepLoading=!1,[3,11];case 11:return[2]}}))}))},this.onProceedToDigitalOnlyPaymentClick=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return this.isShowBillingAddressOnShippingStep?[4,this.onHandleBillingAddressOnShippingStep()]:[3,2];case 1:t.sent(),t.label=2;case 2:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=3;case 3:return t.trys.push([3,6,,7]),this.isStepLoading=!0,[4,this.checkStocks()];case 4:return t.sent(),[4,this.saveCart()];case 5:return t.sent(),this.changeStep(W.PAYMENT),[3,7];case 6:return(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:Q.UNKNOWN}),this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.onProceedToPaymentClick=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:if(!this.canProceedToPayment)return this.isErrorsVisible=!0,[2];this.isErrorsVisible=!1,t.label=1;case 1:return t.trys.push([1,4,,5]),this.isStepLoading=!0,[4,this.checkStocks()];case 2:return t.sent(),[4,this.saveCart()];case 3:return t.sent(),this.error=void 0,this.changeStep(W.PAYMENT),[3,5];case 4:return void 0!==typeof(e=t.sent()).type?this.error=e:(console.log(e),this.error={type:Q.UNKNOWN}),this.isStepLoading=!1,[3,5];case 5:return[2]}}))}))},this.checkPaypalButtonAvailable=function(){return!!re.canPerformPayment||(re.isErrorsVisible=!0,!1)},this.handlePaymentError=function(e,t){re.error={type:e,data:t}},this.onCompletePaymentClick=function(){return e(re,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return this.canPerformPayment?(this.useDifferentAddress||(this.checkout.billingAddress=this.checkout.shippingAddress),this.isFree||!this.isKlarna?[3,2]:[4,this.saveCart()]):(this.isErrorsVisible=!0,[2]);case 1:return t.sent(),this.setIsKlarnaPaymentCompleted(!0),[2];case 2:return t.trys.push([2,8,,9]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 3:return t.sent(),"address"===this.deliveryMethod&&this.useDifferentAddress?[4,this.saveAddress("billing")]:[3,5];case 4:t.sent(),t.label=5;case 5:return[4,this.saveCart()];case 6:return t.sent(),!this.isFree&&this.isCustomFlowStripe?((e=document.querySelector("#stripe-form-btn"))&&e.click(),[2]):!this.isFree&&this.isAdyen?(this.adyenDropinElement.submit(),this.adyenDropinElement.isValid||(this.isStepLoading=!1),[2]):!this.isFree&&this.isPayPal?[2]:[4,this.createSaleTransaction()];case 7:return t.sent(),[3,9];case 8:return void 0!==typeof(i=t.sent()).type?this.error=i:this.error={type:Q.UNKNOWN},this.isStepLoading=!1,[3,9];case 9:return[2]}}))}))},this.onCompleteDigitalOnlyPaymentClick=function(){return e(re,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return!this.canProceedToPayment||this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked?(this.isErrorsVisible=!0,[2]):this.isKlarna?[4,this.saveCart()]:[3,2];case 1:return t.sent(),this.setIsKlarnaPaymentCompleted(!0),[2];case 2:return t.trys.push([2,6,,7]),this.isErrorsVisible=!1,this.isStepLoading=!0,[4,this.checkStocks()];case 3:return t.sent(),[4,this.saveCart()];case 4:return t.sent(),this.isCustomFlowStripe?((e=document.querySelector("#stripe-form-btn"))&&e.click(),[2]):this.isAdyen?(this.adyenDropinElement.submit(),this.adyenDropinElement.isValid||(this.isStepLoading=!1),[2]):this.isPayPal?[2]:[4,this.createSaleTransaction()];case 5:return t.sent(),[3,7];case 6:return(i=t.sent()).type?this.error=i:this.error={type:Q.UNKNOWN},this.isStepLoading=!1,[3,7];case 7:return[2]}}))}))},this.createSaleTransaction=function(){return e(re,void 0,void 0,(function(){var e,i,s,n,r,o,a,c,d,h,p,f,g,v,y,S,k,b,P;return t(this,(function(t){switch(t.label){case 0:return i=this.mpVM.selectedCard,!this.isFree&&i&&(null===(c=this.mpVM.selectedCard)||void 0===c?void 0:c.Name)?((n=this.mpVM.phoneNumber({store:this.store,checkout:this.checkout}))&&(e=n),void 0===(null===(d=this.cardData)||void 0===d?void 0:d.installmentCount)?[2]:[4,T.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:{phoneNumber:e,savedCardName:null===(h=this.mpVM.selectedCard)||void 0===h?void 0:h.Name},paymentGatewayId:null===(p=this.mpVM.selectedCard)||void 0===p?void 0:p.paymentGatewayId,paymentMethodDetail:{cardNumber:this.mpVM.selectedCard.Value1,cardHolderName:this.mpVM.selectedCard.Name,cvv:this.mpVM.selectedCard.Value2,expiredMonth:11,expiredYear:11,installmentCount:this.cardData.installmentCount,threeDSecure:!!(null===(f=this.cardData)||void 0===f?void 0:f.threeDSecure)},metadata:{_fbp:H("_fbp"),_fbc:H("_fbc")}}})]):[3,2];case 1:return s=t.sent(),[3,4];case 2:return this.checkout.selectedPaymentGateway||this.isFree?[4,T.createSaleTransactionWithCart({input:{cartId:this.checkout.id,masterPassDetail:this.isFree?void 0:i&&e?{phoneNumber:e,savedCardName:null===(g=this.mpVM.selectedCard)||void 0===g?void 0:g.Name}:void 0,paymentGatewayId:this.isFree?"9d41af41-4793-4879-a19c-e9a66c929726":null===(v=this.checkout.selectedPaymentGateway)||void 0===v?void 0:v.id,paymentMethodDetail:this.isFree||i?void 0:(null===(y=this.checkout.selectedPaymentGateway)||void 0===y?void 0:y.paymentMethodType)===u.CREDIT_CARD&&(null===(S=this.checkout.selectedPaymentGateway)||void 0===S?void 0:S.type)===l.INTERNAL&&this.cardData?this.cardData.toInput():void 0,metadata:{_fbp:H("_fbp"),_fbc:H("_fbc")}}})]:[2];case 3:s=t.sent(),t.label=4;case 4:return r=null===(k=null==s?void 0:s.data)||void 0===k?void 0:k.transactionStatus,o=r&&[m.SUCCESS,m.AUTHORIZED].includes(r),a=r===m.PENDING,o?[4,this.getSuccessTransaction()]:[3,7];case 5:return t.sent(),[4,this.onCheckoutTransactionSuccess((null===(b=null==s?void 0:s.data)||void 0===b?void 0:b.orderId)||void 0)];case 6:return t.sent(),[3,8];case 7:if(!a||!(null===(P=null==s?void 0:s.data)||void 0===P?void 0:P.returnSlug))throw{data:s.firstErrorMessage,type:Q.UNKNOWN};window.location.href=process.env.NEXT_PUBLIC_BASE_URL+s.data.returnSlug,t.label=8;case 8:return[2]}}))}))},this.onCheckoutTransactionSuccess=function(i){return e(re,void 0,void 0,(function(){var e,s;return t(this,(function(t){switch(t.label){case 0:return localStorage.removeItem("sAddr"),(null===(e=this.checkout.customer)||void 0===e?void 0:e.notificationsAccepted)?[4,this.store.customerStore.createEmailSubscription((null===(s=this.checkout.customer)||void 0===s?void 0:s.email)||"")]:[3,2];case 1:t.sent(),t.label=2;case 2:return q.refreshJourneyId(),this.changeStep(W.SUCCESS,i),[2]}}))}))},this.onBackToInfoClick=function(){re.changeStep(W.INFO)},this.onBackToShippingClick=function(){re.changeStep(W.SHIPPING)},this.setCustomerConsentGranted=function(e){re.checkout.customer&&(re.checkout.customer.notificationsAccepted=e)},this.setUseDifferentAddress=function(e,t){var s;re.useDifferentAddress=e,re.useDifferentAddress?(localStorage.setItem("sAddr","1"),re.checkout.billingAddress=re.checkout.billingAddress||new Y,re.checkout.billingAddress.countrySettings=re.countrySettings):(localStorage.removeItem("sAddr"),re.checkout.billingAddress=new Y(i({},re.checkout.shippingAddress)),re.store.customerStore.customer&&(null===(s=re.customerAddresses)||void 0===s?void 0:s.length)&&t&&re.isShowBillingAddressOnShippingStep&&re.onSelectedBillingAddressIdChange(re.checkout.billingAddress.id||"-1"))},this.setShouldSaveAddress=function(e){re.shouldSaveAddress=e},this.setAddressTitle=function(e){re.addressTitle=e},this.reInitPaymentMethod=function(){return e(re,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return this.checkout.selectedPaymentGateway?this.isCustomFlowStripe?[4,this.createStripePaymentIntent(this.checkout.selectedPaymentGateway)]:[3,2]:[3,6];case 1:e.sent(),e.label=2;case 2:return this.isKlarna&&window.location.reload(),this.isAdyen?[4,this.createAdyenBalancePlatformPaymentSession(this.checkout.selectedPaymentGateway)]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.isPayPal?[4,this.getPayPalClientId(this.checkout.selectedPaymentGateway)]:[3,6];case 5:e.sent(),e.label=6;case 6:return[2]}}))}))},this.createStripePaymentIntent=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.createStripePaymentIntent({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data?(this.stripeResponse=e.data,this.stripeError=null):this.stripeError={type:Q.API_ERROR,data:e.firstErrorMessage},[2]}}))}))},this.createKlarnaClientToken=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.createKlarnaClientToken({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data?(this.klarnaResponse=e.data,this.klarnaError=null):this.klarnaError={type:Q.API_ERROR,data:e.firstErrorMessage},[2]}}))}))},this.createAdyenBalancePlatformPaymentSession=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.createAdyenBalancePlatformPaymentSession({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.adyenResponse=e.data),[2]}}))}))},this.getPayPalClientId=function(i){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return[4,T.getPayPalClientId({input:{cartId:this.checkout.id,paymentGatewayId:i.id||""}})];case 1:return(e=t.sent()).isSuccess&&e.data&&(this.payPalClientIdResponse=e.data),[2]}}))}))},this.setPaymentGateway=function(i){return e(re,void 0,void 0,(function(){var e,s;return t(this,(function(t){switch(t.label){case 0:return this.paymentGateways.length?(e=this.paymentGateways[i],s=!0,this.step!==W.PAYMENT?[3,7]:this.checkout.selectedPaymentGateway?[3,3]:"CUSTOM"!==e.code?[3,2]:[4,this.updatePaymentGateway(e)]):[2];case 1:s=t.sent(),t.label=2;case 2:return[3,7];case 3:return"CUSTOM"!==this.checkout.selectedPaymentGateway.code?[3,5]:[4,this.updatePaymentGateway(e)];case 4:return s=t.sent(),[3,7];case 5:return"CUSTOM"!==e.code?[3,7]:[4,this.updatePaymentGateway(e)];case 6:s=t.sent(),t.label=7;case 7:return s?"STRIPE"!==e.code&&"STRIPE_EU"!==e.code||this.stripeResponse?[3,9]:[4,this.createStripePaymentIntent(e)]:[2];case 8:t.sent(),t.label=9;case 9:return"KLARNA"!==e.code||this.klarnaResponse?[3,11]:[4,this.createKlarnaClientToken(e)];case 10:t.sent(),t.label=11;case 11:return"ADYEN_PLATFORM"!==e.code||this.adyenResponse?[3,13]:[4,this.createAdyenBalancePlatformPaymentSession(e)];case 12:t.sent(),t.label=13;case 13:return"PAYPAL"!==e.code||this.payPalClientIdResponse?[3,15]:[4,this.getPayPalClientId(e)];case 14:t.sent(),t.label=15;case 15:return this.checkout.selectedPaymentGateway=e,this.step!==W.SUCCESS&&(e.paymentMethodType===u.CREDIT_CARD&&e.type===l.INTERNAL&&(this.cardData=new N,e.masterPassClientId&&this.mpVM.checkMasterPass({checkout:this.checkout,store:this.store})),this.installmentInfo=void 0),[2]}}))}))},this.updatePaymentGateway=function(s){return e(re,void 0,void 0,(function(){var e,n,r;return t(this,(function(t){switch(t.label){case 0:return this.isPaymentMethodVisible=!1,[4,D.getCartById({id:this.checkout.id,getCompletedCart:!1,paymentGatewayId:s.id})];case 1:return(e=t.sent()).isSuccess?((n=e.data)&&(r=this.checkout,this.checkout=new k(i(i({},n),{shippingAddress:r.shippingAddress,billingAddress:r.billingAddress,customer:r.customer,selectedPaymentGateway:r.selectedPaymentGateway}),this.countrySettings)),this.isPaymentMethodVisible=!0,[2,!0]):(this.isPaymentMethodVisible=!0,[2,!1])}}))}))},this.setInstallmentCount=function(e){re.cardData&&(re.cardData.installmentCount=e)},this.changeStep=function(i,s){return e(re,void 0,void 0,(function(){return t(this,(function(e){return X||window.location.replace("".concat(window.location.pathname,"?id=").concat(s||this.checkout.id,"&step=").concat(i)),[2]}))}))},this.logout=function(){return e(re,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:this.checkout.customer=null,this.store.customerStore.logout(),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.saveCart()];case 2:case 3:return e.sent(),[3,4];case 4:return this.createCustomer(),[2]}}))}))},this.setContactModalVisible=function(e){re.isContactModalVisible=e},this.getCampaignOffer=function(s,n){return e(re,void 0,void 0,(function(){var r,o,a=this;return t(this,(function(c){switch(c.label){case 0:return(null==n?void 0:n.length)?(r=n.filter((function(e){var t;return e.status===f.WAITING_FOR_ACTION&&(null===(t=e.campaignOffer)||void 0===t?void 0:t.targetPageTypes.some((function(e){return e===s})))})),o=r.map((function(s){return e(a,void 0,void 0,(function(){var e,n,r,o,a,c,d,u,l;return t(this,(function(t){switch(t.label){case 0:return(e=null===(d=s.campaignOffer)||void 0===d?void 0:d.offers.find((function(e){return e.id===s.campaignOfferProductId})))?(n=[e.productId],[4,x.searchProducts({input:{productIdList:n,priceListId:B.getPriceListId(),salesChannelId:B.getSalesChannelId()}})]):[2,Promise.reject()];case 1:return(r=t.sent()).isSuccess&&(null===(l=null===(u=r.data)||void 0===u?void 0:u.data)||void 0===l?void 0:l.length)?(o=r.data.data[0],(a=o.variants.filter((function(t){return t.hasStock&&!(e.excludedVariantIdList||[]).some((function(e){return e===t.id}))})).map((function(t){if(!e.discountAmount)return t;var s=!1;return e.discountType===y.AMOUNT&&(s=!0),new O(i(i({},t),{prices:t.prices.map((function(t){var n=t.finalPrice,r=t.finalPrice-(s?e.discountAmount:t.finalPrice*e.discountAmount/100);return e.applicablePrice===S.SELL_PRICE&&(n=t.sellPrice,r=t.sellPrice-(s?e.discountAmount:t.sellPrice*e.discountAmount/100)),new w(i(i({},t),{sellPrice:n,discountPrice:r}))}))}))}))).length?(c=a.find((function(e){return e.isActive})),[2,{product:new E(i(i({},o),{selectedVariantValues:(c||a[0]).variantValues,variants:a})),offer:e,campaignOffer:s}]):[2,Promise.reject()]):[2,Promise.reject()]}}))}))})),[4,Promise.allSettled(o)]):[2,[]];case 1:return[2,c.sent().filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))]}}))}))},this.createCampaignOffer=function(){return e(re,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return e=this,[4,this.getCampaignOffer(this.step===W.SUCCESS?g.POST_CHECKOUT:g.CHECKOUT,this.checkout.campaignOffers)];case 1:return e.campaignOffers=t.sent(),[2]}}))}))},this.updateCartCampaignOffer=function(i){return e(re,void 0,void 0,(function(){var e,s,n;return t(this,(function(t){switch(t.label){case 0:return i.accepted?this.isCheckoutLoaded=!1:this.isCampaignOfferLoaded=!1,[4,D.updateCartCampaignOffer({input:i})];case 1:return(e=t.sent()).isSuccess?i.accepted?(this.changeStep(this.step===W.SUCCESS?W.PAYMENT:this.step,null===(s=e.data)||void 0===s?void 0:s.id),[3,4]):[3,2]:[3,4];case 2:return this.checkout.campaignOffers=(null===(n=e.data)||void 0===n?void 0:n.campaignOffers)||[],[4,this.createCampaignOffer()];case 3:t.sent(),this.isCampaignOfferLoaded=!0,t.label=4;case 4:return[2]}}))}))},this.registerCustomer=function(i){return e(re,void 0,void 0,(function(){var e,s,n,r;return t(this,(function(t){switch(t.label){case 0:return this.checkout.customer?(e=this.checkout.customer,s=e.firstName,n=e.lastName,r=e.email,s&&n&&r?[4,j.register({orderId:this.checkout.id,firstName:s,lastName:n,email:r,password:i})]:[3,2]):[3,2];case 1:return[2,t.sent()];case 2:return[2]}}))}))},this.listProductFile=function(){return e(re,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return(e=this.checkout.orderLineItems.filter((function(e){return!!e.variant.fileId&&e.status!==v.REFUNDED})).map((function(e){return e.variant.fileId}))).length?[4,T.listProductFile({id:{in:e}})]:[3,2];case 1:(i=t.sent()).isSuccess&&(this.productFiles=i.data||[]),t.label=2;case 2:return[2]}}))}))},this.getDigitalProductFileDownloadUrl=function(i){return e(re,void 0,void 0,(function(){var e,s,n,r,o;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,3,,4]),(e=this.checkout.orderLineItems.find((function(e){return e.variant.id===i.variantId})))?[4,T.getDigitalProductFileDownloadUrl({orderId:this.checkout.id,orderLineItemId:e.id})]:[3,2];case 1:s=t.sent(),(n=s.data)&&((r=document.createElement("a")).href=n,r.download=function(e){try{return decodeURIComponent(e.split("/")[e.split("/").length-1])}catch(e){return""}}(i.name),r.click(),r.remove()),t.label=2;case 2:return[3,4];case 3:return o=t.sent(),console.error(o),[3,4];case 4:return[2]}}))}))},this.checkout=a,this.checkoutSettings=d,this.router=C,this.returnPolicy=A,this.privacyPolicy=z,this.termsOfService=J,this.imprint=te,this.shippingPolicy=ie,this.t=se,this.customizationProps=ne,this.mpVM=new M,this.isTermsAndConditionsChecked=this.checkoutSettings.isTermsAndConditionsDefaultChecked||!1,this.countrySettings=new R({currentLocale:B.getCurrentLocale()}),this.init(),s(this)}return Object.defineProperty(z.prototype,"merchantSettings",{get:function(){return new A(B.getMerchantSettings())},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"selectedPaymentGatewayIndex",{get:function(){var e=this;return this.paymentGateways.findIndex((function(t){var i;return t.id===(null===(i=e.checkout.selectedPaymentGateway)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"selectedInstallmentIndex",{get:function(){var e,t,i=this;return(null===(t=null===(e=this.installmentInfo)||void 0===e?void 0:e.installmentPrices)||void 0===t?void 0:t.findIndex((function(e){var t;return e.installmentCount===(null===(t=i.cardData)||void 0===t?void 0:t.installmentCount)})))||0},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"checkoutUrl",{get:function(){return"/checkout?id=".concat(this.checkout.id,"&step=info")},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"customerAddressOptions",{get:function(){var e,t,i={label:this.t("checkout-page:newAddress"),value:"-1"},s=(null===(t=null===(e=F.getInstance().customerStore.customer)||void 0===e?void 0:e.addresses)||void 0===t?void 0:t.map((function(e){return{label:e.title+" - "+e.addressText,value:e.id}})))||[];return[i].concat(s)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"installmentPrice",{get:function(){var e,t,i,s=this;if(this.installmentInfo&&(null===(e=this.cardData)||void 0===e?void 0:e.installmentCount))return null===(i=null===(t=this.installmentInfo.installmentPrices)||void 0===t?void 0:t.find((function(e){var t;return e.installmentCount===(null===(t=s.cardData)||void 0===t?void 0:t.installmentCount)})))||void 0===i?void 0:i.totalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"giftCardTotalPrice",{get:function(){var e;return(null===(e=this.checkout.giftCardLines)||void 0===e?void 0:e.reduce((function(e,t){return e+t.amount}),0))||0},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"installmentExtraPrice",{get:function(){if(this.installmentPrice&&this.checkout.totalFinalPrice)return this.installmentPrice-(this.checkout.totalFinalPrice-this.giftCardTotalPrice)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"finalPrice",{get:function(){return this.step===W.SUCCESS?this.checkout.totalFinalPrice-this.giftCardTotalPrice:this.installmentPrice?this.installmentPrice:this.checkout.totalFinalPrice-this.giftCardTotalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"hasStockError",{get:function(){var e;return(null===(e=this.error)||void 0===e?void 0:e.type)===Q.STOCK_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isPaymentGatewayHasMasterPass",{get:function(){return-1!==this.selectedPaymentGatewayIndex&&(!!this.paymentGateways.length&&!!this.paymentGateways[this.selectedPaymentGatewayIndex].masterPassClientId)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"hasQuickRegistration",{get:function(){return this.checkoutSettings.isQuickRegistrationEnabled&&this.checkout.customer&&this.checkout.customer.isGuestCheckout},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"canProceedToShipping",{get:function(){var e,t,i;return(this.isDigitalOnly||this.isShowBillingAddressOnShippingStep?null===(e=this.checkout.billingAddress)||void 0===e?void 0:e.isValidAddress:null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.isValidAddress)&&(this.checkout.hasCustomer||this.checkout.hasValidCustomerEmail)&&(null===(i=this.error)||void 0===i?void 0:i.type)!==Q.NO_SHIPPING_ERROR},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"canProceedToInStoreDelivery",{get:function(){var e,t,i;return!!((null===(e=this.checkout.shippingAddress)||void 0===e?void 0:e.firstName)&&(null===(t=this.checkout.shippingAddress)||void 0===t?void 0:t.lastName)&&(null===(i=this.checkout.customer)||void 0===i?void 0:i.email)&&this.checkout.stockLocationId)&&(!this.isShowBillingAddressOnShippingStep||this.canProceedToShipping)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"canProceedToPayment",{get:function(){return this.canProceedToShipping&&this.isValidShippingSettings},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isValidShippingSettings",{get:function(){var e,t=this;return!!(this.isInStoreDelivery||this.isDigitalOnly||this.isManualOrderWithShippingLines)||this.checkout.shippingSettingsId&&this.checkout.shippingZoneRateId&&(null===(e=this.checkout.shippingLines)||void 0===e?void 0:e.some((function(e){return e.shippingSettingsId===t.checkout.shippingSettingsId&&e.shippingZoneRateId===t.checkout.shippingZoneRateId})))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isManualOrderWithShippingLines",{get:function(){var e,t;return this.checkout.createdBy===a.ADMIN&&(null===(e=this.checkout.shippingLines)||void 0===e?void 0:e.length)&&!(null===(t=this.checkout.availableShippingMethods)||void 0===t?void 0:t.length)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isInStoreDelivery",{get:function(){return!!this.checkout.stockLocationId},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"klarnaPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"KLARNA"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"klarnaPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"KLARNA"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"adyenPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"ADYEN_PLATFORM"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"adyenPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"ADYEN_PLATFORM"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"payPalPaymentGateway",{get:function(){var e=this.paymentGateways.findIndex((function(e){return"PAYPAL"===e.code}));if(-1!==e)return this.paymentGateways[e]},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"payPalPaymentGatewayIndex",{get:function(){return this.paymentGateways.findIndex((function(e){return"PAYPAL"===e.code}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCustomFlowStripe",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&("STRIPE"===e.code||"STRIPE_EU"===e.code)},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isKlarna",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"KLARNA"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isAdyen",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"ADYEN_PLATFORM"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isPayPal",{get:function(){var e=this.checkout.selectedPaymentGateway;return e&&"PAYPAL"===e.code},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isFree",{get:function(){return 0===this.checkout.totalFinalPrice||0===this.finalPrice},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"store",{get:function(){return F.getInstance()},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCouponCodeRequirementDefult",{get:function(){return this.checkoutSettings.couponCodeRequirement===c.DEFAULT||null===this.checkoutSettings.couponCodeRequirement},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCouponCodeRequirementOpen",{get:function(){return this.checkoutSettings.couponCodeRequirement===c.OPEN},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCouponCodeRequirementInvisible",{get:function(){return this.checkoutSettings.couponCodeRequirement===c.INVISIBLE},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCouponCodeVisible",{get:function(){return this.isCouponCodeRequirementDefult&&!this.isCouponCodeRequirementInvisible},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isCorporateInvoiceVisible",{get:function(){return this.checkoutSettings.corporateInvoiceRequirement!==d.INVISIBLE},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isShowBillingAddressOnShippingStep",{get:function(){return this.checkoutSettings.showBillingAddressOnShippingStep},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"canPerformPayment",{get:function(){var e,t;if(this.checkoutSettings.showTermsAndConditionsCheckbox&&!this.isTermsAndConditionsChecked)return!1;var i=this.checkout.selectedPaymentGateway,s=!!("in-store"===this.deliveryMethod)||!!this.canProceedToShipping,n=!!(null===(e=this.checkout.billingAddress)||void 0===e?void 0:e.isValidAddress),r=!!this.isFree||(!!this.mpVM.selectedCard||((null==i?void 0:i.paymentMethodType)===u.CREDIT_CARD&&i.type===l.INTERNAL?!!this.isCustomFlowStripe||(!(!this.isKlarna&&!this.isPayPal)||(null===(t=this.cardData)||void 0===t?void 0:t.isValid)):!!i));return s&&n&&r},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isDigitalOnly",{get:function(){return this.checkout.shippingMethod===h.DIGITAL_DELIVERY},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"customerAddresses",{get:function(){var e,t,s,n=this,r=null===(e=B.getCurrentRouting())||void 0===e?void 0:e.countryCodes;return null===(s=null===(t=this.store.customerStore.customer)||void 0===t?void 0:t.addresses)||void 0===s?void 0:s.filter((function(e){var t;return!(null==r?void 0:r.length)||(null===(t=e.country)||void 0===t?void 0:t.iso2)&&r.includes(e.country.iso2)})).map((function(e){var t=new C(i({countrySettings:n.countrySettings},e));return t.checkoutSettings=n.checkoutSettings,t.shippingZones=n.shippingZones,t.getValidatedCustomerAddress(),t}))},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isManualOrder",{get:function(){return this.checkout.createdBy===a.ADMIN},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isUpsellOrder",{get:function(){return this.checkout.createdBy===a.UPSELL},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isEPayKolayEnabled",{get:function(){var e=B.getCustom();return!!e&&!!e.isEPayKolayEnabled},enumerable:!1,configurable:!0}),Object.defineProperty(z.prototype,"isPoweredByHidden",{get:function(){var e=B.getCustom();return!!e&&!!e.hidePoweredBy},enumerable:!1,configurable:!0}),z.prototype.setAdyenDropinElement=function(e){this.adyenDropinElement=e},z}();function $(e,t){return e.match(new RegExp(".{1,"+t+"}","g"))||[]}function ee(e){return e&&z.test(e.charAt(e.length-1))}!function(e){e.INFO="info",e.SHIPPING="shipping",e.PAYMENT="payment",e.SUCCESS="success"}(W||(W={})),function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.API_ERROR=1]="API_ERROR",e[e.STOCK_ERROR=2]="STOCK_ERROR",e[e.PAYMENT_ERROR=3]="PAYMENT_ERROR",e[e.NO_SHIPPING_ERROR=4]="NO_SHIPPING_ERROR",e[e.CUSTOMER_LOGIN_REQUIRED_ERROR=5]="CUSTOMER_LOGIN_REQUIRED_ERROR",e[e.CUSTOMER_ACCOUNT_DISABLED_ERROR=6]="CUSTOMER_ACCOUNT_DISABLED_ERROR",e[e.ARGUMENT_VALIDATION_ERROR=7]="ARGUMENT_VALIDATION_ERROR"}(Q||(Q={}));export{W as CheckoutStep,Q as ErrorType,J as default};
@@ -1 +1 @@
1
- import*as e from"react";import{observer as t}from"mobx-react-lite";import{FormItem as o}from"../../components/form-item/index.js";import{FormItemType as i,FormItemInputMode as n}from"../../components/form-item/model.js";import{Button as r}from"../../components/button/index.js";import{Checkbox as s}from"../../components/checkbox/index.js";import c from"../../components/error/index.js";import m from"../../styles/common.module.scss.js";import l from"../../components/customer-addresses/index.js";import a from"../../components/customer-addresses/model.js";import"@ikas/storefront-config";import{useTranslation as p}from"../../../../utils/i18n.js";var d=t((function(t){var d,u,h=t.vm,g=p().t,f=e.useCallback((function(e){h.checkout.customer&&(h.checkout.customer.email=e?e.trim():e)}),[h,h.checkout,h.checkout.customer]),k=e.useMemo((function(){return h.isDigitalOnly?new a(h,"billing"):new a(h,"shipping")}),[h]);return e.createElement("div",null,e.createElement(c,{vm:h}),!h.checkout.hasCustomer&&e.createElement("div",{style:{marginTop:"8px",marginBottom:"40px"}},e.createElement("div",{className:m.FormSectionTitle},e.createElement("div",{className:m.Title},g("checkout-page:contactInfo"))),e.createElement(o,{type:i.TEXT,inputMode:n.EMAIL,label:g("checkout-page:email"),autocomplete:"email",value:(null===(d=h.checkout.customer)||void 0===d?void 0:d.email)||"",onChange:f,hasError:h.isErrorsVisible&&!h.checkout.hasValidCustomerEmail,errorText:g("checkout-page:emailError"),tooltipText:g("checkout-page:guestEmailTooltip")}),e.createElement(s,{value:(null===(u=h.checkout.customer)||void 0===u?void 0:u.notificationsAccepted)||!1,label:g("checkout-page:customerConsentCta"),onChange:h.setCustomerConsentGranted})),e.createElement(l,{vm:k}),h.isShowBillingAddressOnShippingStep&&"address"===h.deliveryMethod&&e.createElement(s,{value:!h.useDifferentAddress,hasError:h.isErrorsVisible&&!h.isTermsAndConditionsChecked,label:g("checkout-page:useShippingForBilling"),onChange:function(e){return h.setUseDifferentAddress(!e,!0)}}),h.isShowBillingAddressOnShippingStep&&(h.useDifferentAddress||"in-store"===h.deliveryMethod)&&e.createElement(l,{vm:new a(h,"billing"),showBillingAddressOnShippingStep:!0}),!k.editingCustomerAddress&&e.createElement(r,{style:{width:"100%",marginTop:h.store.customerStore.customer&&!h.isShowBillingAddressOnShippingStep?"0px":"32px"},text:"address"!==h.deliveryMethod||h.isDigitalOnly?g("checkout-page:actions.continueWithPayment"):g("checkout-page:actions.continueWithShipping"),isLoading:h.isStepLoading,onClick:h.isDigitalOnly?h.onProceedToDigitalOnlyPaymentClick:h.onProceedToShippingClick}))}));export{d as default};
1
+ import*as e from"react";import{observer as t}from"mobx-react-lite";import{FormItem as o}from"../../components/form-item/index.js";import{FormItemType as i,FormItemInputMode as n}from"../../components/form-item/model.js";import{Button as r}from"../../components/button/index.js";import{Checkbox as s}from"../../components/checkbox/index.js";import c from"../../components/error/index.js";import m from"../../styles/common.module.scss.js";import l from"../../components/customer-addresses/index.js";import a from"../../components/customer-addresses/model.js";import"@ikas/storefront-config";import{useTranslation as p}from"../../../../utils/i18n.js";var d=t((function(t){var d,u,h=t.vm,g=p().t,f=e.useCallback((function(e){h.checkout.customer&&(h.checkout.customer.email=e?e.trim():e)}),[h,h.checkout,h.checkout.customer]),k=e.useMemo((function(){return h.isDigitalOnly?new a(h,"billing"):new a(h,"shipping")}),[h]);return e.createElement("div",null,e.createElement(c,{vm:h}),!h.checkout.hasCustomer&&e.createElement("div",{style:{marginTop:"8px",marginBottom:"40px"}},e.createElement("div",{className:m.FormSectionTitle},e.createElement("div",{className:m.Title},g("checkout-page:contactInfo"))),e.createElement(o,{type:i.TEXT,inputMode:n.EMAIL,label:g("checkout-page:email"),autocomplete:"email",value:(null===(d=h.checkout.customer)||void 0===d?void 0:d.email)||"",onChange:f,hasError:h.isErrorsVisible&&!h.checkout.hasValidCustomerEmail,errorText:g("checkout-page:emailError"),tooltipText:g("checkout-page:guestEmailTooltip")}),e.createElement(s,{value:(null===(u=h.checkout.customer)||void 0===u?void 0:u.notificationsAccepted)||!1,label:g("checkout-page:customerConsentCta"),onChange:h.setCustomerConsentGranted})),e.createElement(l,{vm:k}),h.isShowBillingAddressOnShippingStep&&"address"===h.deliveryMethod&&!h.isDigitalOnly&&e.createElement(s,{value:!h.useDifferentAddress,hasError:h.isErrorsVisible&&!h.isTermsAndConditionsChecked,label:g("checkout-page:useShippingForBilling"),onChange:function(e){return h.setUseDifferentAddress(!e,!0)}}),h.isShowBillingAddressOnShippingStep&&(h.useDifferentAddress||"in-store"===h.deliveryMethod)&&e.createElement(l,{vm:new a(h,"billing"),showBillingAddressOnShippingStep:!0}),!k.editingCustomerAddress&&e.createElement(r,{style:{width:"100%",marginTop:h.store.customerStore.customer&&!h.isShowBillingAddressOnShippingStep?"0px":"32px"},text:"address"!==h.deliveryMethod||h.isDigitalOnly?g("checkout-page:actions.continueWithPayment"):g("checkout-page:actions.continueWithShipping"),isLoading:h.isStepLoading,onClick:h.isDigitalOnly?h.onProceedToDigitalOnlyPaymentClick:h.onProceedToShippingClick}))}));export{d as default};
@@ -1 +1 @@
1
- import{__assign as e}from'./../../ext/tslib/tslib.es6.js';import*as t from"react";import{observer as o}from"mobx-react-lite";import i from"next/head.js";import{useRouter as a}from"next/router";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasThemeJsonPageType as r}from"@ikas/storefront-models";import"mobx";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import{IkasIndexPageSeoSetting as n}from"../../models/data/storefront/index-page-seo-setting/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/category-list/index.js";import{IkasProductList as s}from"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/customer-review-summary-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/ikas-address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import{IkasStorefrontConfig as d}from"@ikas/storefront-config";import"../../analytics/analytics.js";import"../../analytics/head/index.js";import"./index.js";import"next/image.js";import"@ikas/storefront-model-functions";import"../link/index.js";import"../page-editor/loader/style.module.scss.js";import"../google-captcha/index.js";import"../paypal-express-checkout/index.js";import"../../pages/home.js";import"../../pages/_slug_/index.js";import"../../pages/pages/_slug_.js";import"../../pages/checkout.js";import"../../pages/account/index.js";import"../../pages/account/addresses.js";import"../../pages/account/orders/index.js";import"../../pages/account/orders/_id_.js";import"../../pages/account/login.js";import"../../pages/account/register.js";import"../../pages/account/forgot-password.js";import"../../pages/account/recover-password.js";import"../../pages/cart.js";import"../../pages/editor.js";import"../../pages/account/favorite-products.js";import"../../pages/search.js";import"next/error.js";import"../../pages/blog/index.js";import"../../pages/blog/_slug_.js";import"../../pages/raffle/_slug_.js";import"../../pages/raffle/index.js";import"../../pages/account/raffles.js";import"../../pages/account/activate.js";import{IkasBaseStore as l}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import"lodash/get";var c=o((function(o){var s,c=o.pageType,g=o.pageTitle,f=o.pageDescription,v=o.canonicals,h=o.disableIndex,j=o.pageSpecificData,x=o.merchantSettings,y=o.addOgpMetas,b=o.productReviewSummary,C=o.pageComponentPropValues,T=a(),D="undefined"!=typeof window,L="local"===process.env.NEXT_PUBLIC_ENV,k=T.asPath.split("?")[0].replace("/",""),w=(k="/"===k.charAt(k.length-1)?k.slice(0,-1):k).startsWith("pages/"),O=d.getCurrentRouting(),P=(null==O?void 0:O.path)?"/"+O.path:"",R=L?"http://localhost:3333":"https://"+d.getDomain(),E=null===(s=d.getIndexPageSeoSettings())||void 0===s?void 0:s.find((function(e){return e.locale===d.getCurrentLocale()})),_=E?new n(E):null;t.useEffect((function(){document.documentElement.lang=d.getCurrentLocale()}),[c,j]);var I=t.useMemo((function(){if(j&&j.href)return"".concat(R).concat(j.href)}),[j]),V=t.useMemo((function(){var e,t,o,i=[];if(y){if(i.push({property:"og:type",content:"website"}),i.push({property:"og:site_name",content:"https://"+d.getDomain()}),g&&i.push({property:"og:title",content:g}),f&&i.push({property:"og:description",content:f}),c===r.INDEX){var a=null,n=null;!g&&(null==_?void 0:_.pageTitle)&&(a=_.pageTitle),!f&&(null==_?void 0:_.description)&&(n=_.description),(s=null===(e=d.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c})))&&(a=u(j,c,s.titleTemplate||""),n=u(j,c,s.descriptionTemplate||"")),a&&i.push({property:"og:title",content:a}),n&&i.push({property:"og:description",content:n})}if(c===r.PRODUCT){var s,l=null,p=null;(s=null===(t=d.getMetaTemplates())||void 0===t?void 0:t.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c})))&&(l=u(j,c,s.titleTemplate||""),p=u(j,c,s.descriptionTemplate||"")),l&&!g&&i.push({property:"og:title",content:l}),p&&!f&&i.push({property:"og:description",content:p})}i.push({property:"og:url",content:I||(D?window.location.href:"")||"https://".concat(d.getDomain())});var m=null;if(j&&c===r.PRODUCT){var v=j.selectedVariant.mainImage;(null==v?void 0:v.image)&&(m={property:"og:image",content:v.image.src.replace(".webp",".jpg")})}if(j&&c===r.CATEGORY){var h=j;h.image&&(m={property:"og:image",content:h.image.src.replace(".webp",".jpg")})}if(j&&c===r.BRAND){var b=j;b.image&&(m={property:"og:image",content:b.image.src.replace(".webp",".jpg")})}if(j&&c===r.BLOG_CATEGORY){var C=j;C.image&&(m={property:"og:image",content:C.image.src.replace(".webp",".jpg")})}if(j&&c===r.BLOG){var T=j;T.image&&(m={property:"og:image",content:T.image.src.replace(".webp",".jpg")})}!m&&(null==_?void 0:_.icon)&&(m={property:"og:image",content:null===(o=null==_?void 0:_.icon)||void 0===o?void 0:o.src.replace(".webp",".jpg")}),!m&&(null==x?void 0:x.logo)&&(m={property:"og:image",content:x.logo.src.replace(".webp",".jpg")}),m&&i.push(m)}return i}),[g,j,I,f,x,y,x]),S=t.useMemo((function(){var t=[],o=(null==_?void 0:_.pageTitle)||(null==x?void 0:x.merchantName)||"";if(x){var i={"@context":"https://schema.org","@type":"Website",url:"https://"+d.getDomain()},a=function(t){var o,i,a,r,n,s,l=(null==t?void 0:t.logo)?t.logo.src:void 0;return{"@context":"https://schema.org","@type":"Store",name:null==t?void 0:t.merchantName,logo:l,image:l,url:"https://"+d.getDomain(),telephone:null==t?void 0:t.phone,address:e(e({"@type":"PostalAddress",streetAddress:null===(o=t.address)||void 0===o?void 0:o.addressLine1,addressLocality:null===(a=null===(i=t.address)||void 0===i?void 0:i.city)||void 0===a?void 0:a.name},t.address&&t.address.state&&{addressRegion:t.address.state.code}),{postalCode:null===(r=t.address)||void 0===r?void 0:r.postalCode,addressCountry:null===(s=null===(n=t.address)||void 0===n?void 0:n.country)||void 0===s?void 0:s.code})}}(x);t.push(i),t.push(a)}if(j&&c===r.PRODUCT){var n=j,s=function(t,o){var i,a,n,s,l,c;try{var p=d.getCurrentRouting(),m=null==p?void 0:p.path,g=function(e){return m?"https://".concat(d.getDomain(),"/").concat(m).concat(e):"https://".concat(d.getDomain()).concat(e)},f=t.selectedVariant,v=null,h=null===(i=d.getMetaTemplates())||void 0===i?void 0:i.find((function(e){return e.locale===d.getCurrentLocale()&&r.PRODUCT}));return h&&(v=u(t,r.PRODUCT,h.descriptionTemplate||"")),e(e({"@context":"https://schema.org/","@type":"Product",name:t.name,description:(null===(a=t.metaData)||void 0===a?void 0:a.description)||v,image:null===(n=f.images)||void 0===n?void 0:n.map((function(e){return e.image?e.image.src:""})),productId:f.id,sku:f.sku,mpn:(null===(s=f.barcodeList)||void 0===s?void 0:s.length)?f.barcodeList[0]:"",brand:{"@type":"Brand",name:null===(l=t.brand)||void 0===l?void 0:l.name}},o&&{aggregateRating:{"@type":"AggregateRating",ratingValue:o.averageStar,reviewCount:o.totalReview}}),{offers:{"@type":"Offer",url:g(t.href),priceCurrency:f.price.currency||"TRY",price:(null!==(c=f.campaignPrice)&&void 0!==c?c:f.price.finalPrice).toFixed(2),priceValidUntil:"",itemCondition:"https://schema.org/NewCondition",availability:f.stock>0||f.sellIfOutOfStock?"https://schema.org/InStock":"https://schema.org/OutOfStock"}})}catch(e){}}(n,b||null);if(s&&t.push(s),n.categories.length)(g=p(n.categories[0],o,n))&&t.push(g)}if(j&&c===r.CATEGORY){var l=function(e){var t,o;try{var i=d.getCurrentRouting(),a=null==i?void 0:i.path,r=function(e){return a?"https://".concat(d.getDomain(),"/").concat(a).concat(e):"https://".concat(d.getDomain()).concat(e)};return{"@context":"http://schema.org","@type":"CollectionPage",url:r(e.href),name:null===(t=e.metaData)||void 0===t?void 0:t.pageTitle,description:null===(o=e.metaData)||void 0===o?void 0:o.description,image:e.image?e.image.src:void 0}}catch(e){}}(j),g=p(j,o),f=m(C);l&&t.push(l),g&&t.push(g),f&&t.push(f)}j&&c===r.BRAND&&((f=m(C))&&t.push(f));if(j&&c===r.BLOG){var v=function(t){var o;try{var i="https://".concat(d.getDomain()).concat(t.href),a=function(e){var t=new Date(e),o=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0");return"".concat(o,"-").concat(i,"-").concat(a)},r="".concat(t.writer.firstName," ").concat(t.writer.lastName),n=(new DOMParser).parseFromString(t.blogContent.content,"text/html").body.textContent;return e(e({"@context":"https://schema.org","@type":"BlogPosting",headline:t.title,image:null===(o=t.image)||void 0===o?void 0:o.src},t.category&&{genre:t.category.name}),{url:i,datePublished:a(t.createdAt),dateCreated:a(t.createdAt),dateModified:a(t.updatedAt),description:t.shortDescription,articleBody:n,author:{"@type":"Person",name:r}})}catch(e){}}(j);v&&t.push(v)}return t}),[j,x]),M=t.useMemo((function(){var e,t=null===(e=d.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c}));return t?u(j,c,t.titleTemplate||""):null}),[c,j]),N=t.useMemo((function(){var e,t=null===(e=d.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c}));return t?u(j,c,t.descriptionTemplate||""):null}),[c,j]),A=t.useMemo((function(){return!d.getFavicon()&&(null==_?void 0:_.favIcon)?_.favIcon:null}),[]),B=[];d.getRoutings().forEach((function(e){var t;(null===(t=e.countryCodes)||void 0===t?void 0:t.length)?e.countryCodes.forEach((function(t){B.push({routing:e,hrefLang:e.locale+"-"+t})})):B.push({routing:e,hrefLang:e.locale})}));var U=function(e){var t,o,i,a,r,n=j,s=null===(o=null===(t=null==n?void 0:n.metaData)||void 0===t?void 0:t.translations)||void 0===o?void 0:o.find((function(t){return t.locale===e.locale}));if(s&&(null==s?void 0:s.slug))return s.slug;var d=B.find((function(e){return!e.routing.path}));return d&&(null===(r=null===(a=null===(i=null==n?void 0:n.metaData)||void 0===i?void 0:i.translations)||void 0===a?void 0:a.find((function(e){return e.locale===d.routing.locale})))||void 0===r?void 0:r.slug)||""},F=l.getInstance();return t.createElement(i,null,t.createElement("title",null,g||M||(null==_?void 0:_.pageTitle)||""),t.createElement("meta",{name:"description",content:f||N||(null==_?void 0:_.description)||""}),B.length>1&&B.filter((function(e){return!w||e.routing.id===(null==O?void 0:O.id)})).map((function(e){return t.createElement("link",{key:e.routing.id+e.hrefLang,rel:"alternate",hrefLang:e.hrefLang,href:"".concat(R+(e.routing.path?"/"+e.routing.path:""),"/").concat(U(e.routing))})})),!!h&&t.createElement("meta",{name:"robots",content:"noindex"}),!!y&&V.map((function(e,o){return t.createElement("meta",{key:"".concat(e.content,"-").concat(o),property:e.property,content:e.content})})),!!v&&v.map((function(e,o){return t.createElement("link",{key:o+"url",rel:"canonical",href:"".concat(R).concat(P).concat(e)})})),A&&t.createElement("link",{rel:"shortcut icon",href:"".concat(process.env.NEXT_PUBLIC_CDN_URL,"images/").concat(A,"/image_180.webp"),type:"image/webp"}),!v&&F.currentPageType!==r.NOT_FOUND&&t.createElement("link",{rel:"canonical",href:"".concat(R).concat(P,"/").concat(k)}),!!S.length&&S.map((function(e,o){return t.createElement("script",{key:o,type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(e)}})})))}));function p(e,t,o){try{var i=l.getInstance(),a=d.getCurrentRouting(),n=null==a?void 0:a.path,s=function(e){return n?"https://".concat(d.getDomain(),"/").concat(n).concat(e):"https://".concat(d.getDomain()).concat(e)},c=[{"@type":"ListItem",position:1,name:t,item:"https://".concat(d.getDomain())}];return(c=c.concat(e.categoryPathItems.map((function(e,t){return{"@type":"ListItem",position:t+2,name:e.name,item:s(e.href)}})))).push({"@type":"ListItem",position:c.length+1,name:e.name,item:s(e.href)}),i.currentPageType===r.PRODUCT&&o&&c.push({"@type":"ListItem",position:c.length+1,name:o.name,item:s(o.productHref)}),{"@context":"http://schema.org","@type":"BreadcrumbList",itemListElement:c}}catch(e){}}function m(e){try{var t=d.getCurrentRouting(),o=null==t?void 0:t.path;if(e){var i=(e.filter((function(e){return!e.component.isHeader&&!e.component.isFooter}))||[]).find((function(e){return Object.values(e.propValues).find((function(e){var t;return e instanceof s&&(null===(t=e._productListPropValue)||void 0===t?void 0:t.usePageFilter)}))}));if(i){var a=Object.values(i.propValues).find((function(e){var t;return e instanceof s&&(null===(t=e._productListPropValue)||void 0===t?void 0:t.usePageFilter)}));if(a)return{"@context":"http://schema.org","@type":"ItemList",itemListElement:(a.data||[]).slice(0,10).map((function(e,t){var i,a,r,n;return{"@type":"ListItem",position:t+1,item:{"@type":"Product",name:e.name,image:(null===(a=null===(i=e.selectedVariant.mainImage)||void 0===i?void 0:i.image)||void 0===a?void 0:a.src)||"",offers:{"@type":"Offer",url:(n=e.href,o?"https://".concat(d.getDomain(),"/").concat(o).concat(n):"https://".concat(d.getDomain()).concat(n)),priceCurrency:e.selectedVariant.price.currency||"TRY",price:(null!==(r=e.selectedVariant.campaignPrice)&&void 0!==r?r:e.selectedVariant.finalPrice).toFixed(2),availability:e.selectedVariant.stock>0||e.selectedVariant.sellIfOutOfStock?"https://schema.org/InStock":"https://schema.org/OutOfStock"}}}}))}}}}catch(e){}}function u(e,t,o){var i,a,n=o;try{switch(t){case r.PRODUCT:var s=e,d=s.name,l=(null===(i=s.brand)||void 0===i?void 0:i.name)||"",c=s.selectedVariant.sku||"",p=(null===(a=s.selectedVariant.barcodeList)||void 0===a?void 0:a.length)?s.selectedVariant.barcodeList[0]:"",m=s.selectedVariant.campaignPrice?s.selectedVariant.formattedCampaignPrice:s.selectedVariant.formattedFinalPrice;n.includes("{{name}}")&&(n=g(n,"{{name}}",d)),n.includes("{{brand}}")&&(n=g(n,"{{brand}}",l)),n.includes("{{sku}}")&&(n=g(n,"{{sku}}",c)),n.includes("{{barcode}}")&&(n=g(n,"{{barcode}}",p)),n.includes("{{price}}")&&(n=g(n,"{{price}}",m.toString()));break;case r.BRAND:case r.CATEGORY:case r.BLOG_CATEGORY:var u=e.name||"";n.includes("{{name}}")&&(n=g(n,"{{name}}",u));break;case r.BLOG:var f=e.title;n.includes("{{name}}")&&(n=g(n,"{{name}}",f))}}catch(e){}return n.trimEnd()}function g(e,t,o){var i=new RegExp(t,"g");return e.replace(i,o)}export{c as IkasPageHead};
1
+ import{__assign as e}from'./../../ext/tslib/tslib.es6.js';import*as t from"react";import{observer as o}from"mobx-react-lite";import i from"next/head.js";import{useRouter as a}from"next/router";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasThemeJsonPageType as r}from"@ikas/storefront-models";import"mobx";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import{IkasIndexPageSeoSetting as n}from"../../models/data/storefront/index-page-seo-setting/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/category-list/index.js";import{IkasProductList as s}from"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/customer-review-summary-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/ikas-address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import{IkasStorefrontConfig as d}from"@ikas/storefront-config";import"../../analytics/analytics.js";import"../../analytics/head/index.js";import"./index.js";import"next/image.js";import"@ikas/storefront-model-functions";import"../link/index.js";import"../page-editor/loader/style.module.scss.js";import"../google-captcha/index.js";import"../paypal-express-checkout/index.js";import"../../pages/home.js";import"../../pages/_slug_/index.js";import"../../pages/pages/_slug_.js";import"../../pages/checkout.js";import"../../pages/account/index.js";import"../../pages/account/addresses.js";import"../../pages/account/orders/index.js";import"../../pages/account/orders/_id_.js";import"../../pages/account/login.js";import"../../pages/account/register.js";import"../../pages/account/forgot-password.js";import"../../pages/account/recover-password.js";import"../../pages/cart.js";import"../../pages/editor.js";import"../../pages/account/favorite-products.js";import"../../pages/search.js";import"next/error.js";import"../../pages/blog/index.js";import"../../pages/blog/_slug_.js";import"../../pages/raffle/_slug_.js";import"../../pages/raffle/index.js";import"../../pages/account/raffles.js";import"../../pages/account/activate.js";import{IkasBaseStore as l}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import"lodash/get";var c=o((function(o){var s,c=o.pageType,g=o.pageTitle,f=o.pageDescription,v=o.canonicals,h=o.disableIndex,j=o.pageSpecificData,x=o.merchantSettings,y=o.addOgpMetas,b=o.productReviewSummary,T=o.pageComponentPropValues,C=a(),L="undefined"!=typeof window,D="local"===process.env.NEXT_PUBLIC_ENV,k=C.asPath.split("?")[0].replace("/",""),w=(k="/"===k.charAt(k.length-1)?k.slice(0,-1):k).startsWith("pages/"),O=d.getCurrentRouting(),P=(null==O?void 0:O.path)?"/"+O.path:"",R=D?"http://localhost:3333":"https://"+d.getDomain(),E=null===(s=d.getIndexPageSeoSettings())||void 0===s?void 0:s.find((function(e){return e.locale===d.getCurrentLocale()})),_=E?new n(E):null;t.useEffect((function(){document.documentElement.lang=d.getCurrentLocale()}),[c,j]);var I=t.useMemo((function(){if(j&&j.href)return"".concat(R).concat(j.href)}),[j]),V=t.useMemo((function(){if(j&&j.href)return P?"".concat(R,"/").concat(k).concat(I):"".concat(R).concat(I)}),[j]),S=t.useMemo((function(){var e;return null===(e=d.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c}))}),[j,c]),M=t.useMemo((function(){var e,t,o,i=[];if(y){if(i.push({property:"og:type",content:"website"}),i.push({property:"og:site_name",content:(null==S?void 0:S.titleTemplate)||g||""}),g&&i.push({property:"og:title",content:g}),f&&i.push({property:"og:description",content:f}),c===r.INDEX){var a=null,n=null;!g&&(null==_?void 0:_.pageTitle)&&(a=_.pageTitle),!f&&(null==_?void 0:_.description)&&(n=_.description);var s=null===(e=d.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c}));s&&(a=u(j,c,s.titleTemplate||""),n=u(j,c,s.descriptionTemplate||"")),a&&i.push({property:"og:title",content:a}),n&&i.push({property:"og:description",content:n})}if(c===r.PRODUCT){var l=null,p=null,m=null===(t=d.getMetaTemplates())||void 0===t?void 0:t.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c}));m&&(l=u(j,c,m.titleTemplate||""),p=u(j,c,m.descriptionTemplate||"")),l&&!g&&i.push({property:"og:title",content:l}),p&&!f&&i.push({property:"og:description",content:p})}i.push({property:"og:url",content:V||(L?window.location.href:"")||"https://".concat(d.getDomain())});var v=null;if(j&&c===r.PRODUCT){var h=j.selectedVariant.mainImage;(null==h?void 0:h.image)&&(v={property:"og:image",content:h.image.src.replace(".webp",".jpg")})}if(j&&c===r.CATEGORY){var b=j;b.image&&(v={property:"og:image",content:b.image.src.replace(".webp",".jpg")})}if(j&&c===r.BRAND){var T=j;T.image&&(v={property:"og:image",content:T.image.src.replace(".webp",".jpg")})}if(j&&c===r.BLOG_CATEGORY){var C=j;C.image&&(v={property:"og:image",content:C.image.src.replace(".webp",".jpg")})}if(j&&c===r.BLOG){var D=j;D.image&&(v={property:"og:image",content:D.image.src.replace(".webp",".jpg")})}!v&&(null==_?void 0:_.icon)&&(v={property:"og:image",content:null===(o=null==_?void 0:_.icon)||void 0===o?void 0:o.src.replace(".webp",".jpg")}),!v&&(null==x?void 0:x.logo)&&(v={property:"og:image",content:x.logo.src.replace(".webp",".jpg")}),v&&i.push(v)}return i}),[g,j,I,f,x,y,x]),N=t.useMemo((function(){var t=[],o=(null==_?void 0:_.pageTitle)||(null==x?void 0:x.merchantName)||"";if(x){var i={"@context":"https://schema.org","@type":"Website",url:"https://"+d.getDomain()},a=function(t){var o,i,a,r,n,s,l=(null==t?void 0:t.logo)?t.logo.src:void 0;return{"@context":"https://schema.org","@type":"Store",name:null==t?void 0:t.merchantName,logo:l,image:l,url:"https://"+d.getDomain(),telephone:null==t?void 0:t.phone,address:e(e({"@type":"PostalAddress",streetAddress:null===(o=t.address)||void 0===o?void 0:o.addressLine1,addressLocality:null===(a=null===(i=t.address)||void 0===i?void 0:i.city)||void 0===a?void 0:a.name},t.address&&t.address.state&&{addressRegion:t.address.state.code}),{postalCode:null===(r=t.address)||void 0===r?void 0:r.postalCode,addressCountry:null===(s=null===(n=t.address)||void 0===n?void 0:n.country)||void 0===s?void 0:s.code})}}(x);t.push(i),t.push(a)}if(j&&c===r.PRODUCT){var n=j,s=function(t,o){var i,a,n,s,l,c;try{var p=d.getCurrentRouting(),m=null==p?void 0:p.path,g=function(e){return m?"https://".concat(d.getDomain(),"/").concat(m).concat(e):"https://".concat(d.getDomain()).concat(e)},f=t.selectedVariant,v=null,h=null===(i=d.getMetaTemplates())||void 0===i?void 0:i.find((function(e){return e.locale===d.getCurrentLocale()&&r.PRODUCT}));return h&&(v=u(t,r.PRODUCT,h.descriptionTemplate||"")),e(e({"@context":"https://schema.org/","@type":"Product",name:t.name,description:(null===(a=t.metaData)||void 0===a?void 0:a.description)||v,image:null===(n=f.images)||void 0===n?void 0:n.map((function(e){return e.image?e.image.src:""})),productId:f.id,sku:f.sku,mpn:(null===(s=f.barcodeList)||void 0===s?void 0:s.length)?f.barcodeList[0]:"",brand:{"@type":"Brand",name:null===(l=t.brand)||void 0===l?void 0:l.name}},o&&{aggregateRating:{"@type":"AggregateRating",ratingValue:o.averageStar,reviewCount:o.totalReview}}),{offers:{"@type":"Offer",url:g(t.href),priceCurrency:f.price.currency||"TRY",price:(null!==(c=f.campaignPrice)&&void 0!==c?c:f.price.finalPrice).toFixed(2),priceValidUntil:"",itemCondition:"https://schema.org/NewCondition",availability:f.stock>0||f.sellIfOutOfStock?"https://schema.org/InStock":"https://schema.org/OutOfStock"}})}catch(e){}}(n,b||null);if(s&&t.push(s),n.categories.length)(g=p(n.categories[0],o,n))&&t.push(g)}if(j&&c===r.CATEGORY){var l=function(e){var t,o;try{var i=d.getCurrentRouting(),a=null==i?void 0:i.path,r=function(e){return a?"https://".concat(d.getDomain(),"/").concat(a).concat(e):"https://".concat(d.getDomain()).concat(e)};return{"@context":"http://schema.org","@type":"CollectionPage",url:r(e.href),name:null===(t=e.metaData)||void 0===t?void 0:t.pageTitle,description:null===(o=e.metaData)||void 0===o?void 0:o.description,image:e.image?e.image.src:void 0}}catch(e){}}(j),g=p(j,o),f=m(T);l&&t.push(l),g&&t.push(g),f&&t.push(f)}j&&c===r.BRAND&&((f=m(T))&&t.push(f));if(j&&c===r.BLOG){var v=function(t){var o;try{var i="https://".concat(d.getDomain()).concat(t.href),a=function(e){var t=new Date(e),o=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0");return"".concat(o,"-").concat(i,"-").concat(a)},r="".concat(t.writer.firstName," ").concat(t.writer.lastName),n=(new DOMParser).parseFromString(t.blogContent.content,"text/html").body.textContent;return e(e({"@context":"https://schema.org","@type":"BlogPosting",headline:t.title,image:null===(o=t.image)||void 0===o?void 0:o.src},t.category&&{genre:t.category.name}),{url:i,datePublished:a(t.createdAt),dateCreated:a(t.createdAt),dateModified:a(t.updatedAt),description:t.shortDescription,articleBody:n,author:{"@type":"Person",name:r}})}catch(e){}}(j);v&&t.push(v)}return t}),[j,x]),A=t.useMemo((function(){var e,t=null===(e=d.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c}));return t?u(j,c,t.titleTemplate||""):null}),[c,j]),B=t.useMemo((function(){var e,t=null===(e=d.getMetaTemplates())||void 0===e?void 0:e.find((function(e){return e.locale===d.getCurrentLocale()&&e.pageType===c}));return t?u(j,c,t.descriptionTemplate||""):null}),[c,j]),U=t.useMemo((function(){return!d.getFavicon()&&(null==_?void 0:_.favIcon)?_.favIcon:null}),[]),F=[];d.getRoutings().forEach((function(e){var t;(null===(t=e.countryCodes)||void 0===t?void 0:t.length)?e.countryCodes.forEach((function(t){F.push({routing:e,hrefLang:e.locale+"-"+t})})):F.push({routing:e,hrefLang:e.locale})}));var G=function(e){var t,o,i,a,r,n=j,s=null===(o=null===(t=null==n?void 0:n.metaData)||void 0===t?void 0:t.translations)||void 0===o?void 0:o.find((function(t){return t.locale===e.locale}));if(s&&(null==s?void 0:s.slug))return s.slug;var d=F.find((function(e){return!e.routing.path}));return d&&(null===(r=null===(a=null===(i=null==n?void 0:n.metaData)||void 0===i?void 0:i.translations)||void 0===a?void 0:a.find((function(e){return e.locale===d.routing.locale})))||void 0===r?void 0:r.slug)||""},Y=l.getInstance();return t.createElement(i,null,t.createElement("title",null,g||A||(null==_?void 0:_.pageTitle)||""),t.createElement("meta",{name:"description",content:f||B||(null==_?void 0:_.description)||""}),F.length>1&&F.filter((function(e){return!w||e.routing.id===(null==O?void 0:O.id)})).map((function(e){return t.createElement("link",{key:e.routing.id+e.hrefLang,rel:"alternate",hrefLang:e.hrefLang,href:"".concat(R+(e.routing.path?"/"+e.routing.path:""),"/").concat(G(e.routing))})})),!!h&&t.createElement("meta",{name:"robots",content:"noindex"}),!!y&&M.map((function(e,o){return t.createElement("meta",{key:"".concat(e.content,"-").concat(o),property:e.property,content:e.content})})),!!v&&v.map((function(e,o){return t.createElement("link",{key:o+"url",rel:"canonical",href:"".concat(R).concat(P).concat(e)})})),U&&t.createElement("link",{rel:"shortcut icon",href:"".concat(process.env.NEXT_PUBLIC_CDN_URL,"images/").concat(U,"/image_180.webp"),type:"image/webp"}),!v&&Y.currentPageType!==r.NOT_FOUND&&t.createElement("link",{rel:"canonical",href:"".concat(R).concat(P,"/").concat(k)}),!!N.length&&N.map((function(e,o){return t.createElement("script",{key:o,type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(e)}})})))}));function p(e,t,o){try{var i=l.getInstance(),a=d.getCurrentRouting(),n=null==a?void 0:a.path,s=function(e){return n?"https://".concat(d.getDomain(),"/").concat(n).concat(e):"https://".concat(d.getDomain()).concat(e)},c=[{"@type":"ListItem",position:1,name:t,item:"https://".concat(d.getDomain())}];return(c=c.concat(e.categoryPathItems.map((function(e,t){return{"@type":"ListItem",position:t+2,name:e.name,item:s(e.href)}})))).push({"@type":"ListItem",position:c.length+1,name:e.name,item:s(e.href)}),i.currentPageType===r.PRODUCT&&o&&c.push({"@type":"ListItem",position:c.length+1,name:o.name,item:s(o.productHref)}),{"@context":"http://schema.org","@type":"BreadcrumbList",itemListElement:c}}catch(e){}}function m(e){try{var t=d.getCurrentRouting(),o=null==t?void 0:t.path;if(e){var i=(e.filter((function(e){return!e.component.isHeader&&!e.component.isFooter}))||[]).find((function(e){return Object.values(e.propValues).find((function(e){var t;return e instanceof s&&(null===(t=e._productListPropValue)||void 0===t?void 0:t.usePageFilter)}))}));if(i){var a=Object.values(i.propValues).find((function(e){var t;return e instanceof s&&(null===(t=e._productListPropValue)||void 0===t?void 0:t.usePageFilter)}));if(a)return{"@context":"http://schema.org","@type":"ItemList",itemListElement:(a.data||[]).slice(0,10).map((function(e,t){var i,a,r,n;return{"@type":"ListItem",position:t+1,item:{"@type":"Product",name:e.name,image:(null===(a=null===(i=e.selectedVariant.mainImage)||void 0===i?void 0:i.image)||void 0===a?void 0:a.src)||"",offers:{"@type":"Offer",url:(n=e.href,o?"https://".concat(d.getDomain(),"/").concat(o).concat(n):"https://".concat(d.getDomain()).concat(n)),priceCurrency:e.selectedVariant.price.currency||"TRY",price:(null!==(r=e.selectedVariant.campaignPrice)&&void 0!==r?r:e.selectedVariant.finalPrice).toFixed(2),availability:e.selectedVariant.stock>0||e.selectedVariant.sellIfOutOfStock?"https://schema.org/InStock":"https://schema.org/OutOfStock"}}}}))}}}}catch(e){}}function u(e,t,o){var i,a,n=o;try{switch(t){case r.PRODUCT:var s=e,d=s.name,l=(null===(i=s.brand)||void 0===i?void 0:i.name)||"",c=s.selectedVariant.sku||"",p=(null===(a=s.selectedVariant.barcodeList)||void 0===a?void 0:a.length)?s.selectedVariant.barcodeList[0]:"",m=s.selectedVariant.campaignPrice?s.selectedVariant.formattedCampaignPrice:s.selectedVariant.formattedFinalPrice;n.includes("{{name}}")&&(n=g(n,"{{name}}",d)),n.includes("{{brand}}")&&(n=g(n,"{{brand}}",l)),n.includes("{{sku}}")&&(n=g(n,"{{sku}}",c)),n.includes("{{barcode}}")&&(n=g(n,"{{barcode}}",p)),n.includes("{{price}}")&&(n=g(n,"{{price}}",m.toString()));break;case r.BRAND:case r.CATEGORY:case r.BLOG_CATEGORY:var u=e.name||"";n.includes("{{name}}")&&(n=g(n,"{{name}}",u));break;case r.BLOG:var f=e.title;n.includes("{{name}}")&&(n=g(n,"{{name}}",f))}}catch(e){}return n.trimEnd()}function g(e,t,o){var i=new RegExp(t,"g");return e.replace(i,o)}export{c as IkasPageHead};
@@ -1 +1 @@
1
- import{__assign as e,__awaiter as t,__generator as o}from'./../../ext/tslib/tslib.es6.js';import*as i from"react";import{observer as r}from"mobx-react-lite";import{useRouter as a}from"next/router.js";import s from"next/dynamic";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasThemeJsonPageType as d}from"@ikas/storefront-models";import"mobx";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import{IkasMerchantSettings as n}from"../../models/data/merchant-settings/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import{IkasThemeJsonCustomData as m}from"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/customer-review-summary-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/ikas-address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import{IkasStorefrontConfig as p}from"@ikas/storefront-config";import{Analytics as l}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{IkasPageHead as c}from"./head.js";import{ThemeComponent as u}from"./ThemeComponent.js";import{IkasBaseStore as f}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import{initIkasEvents as j}from"../../analytics/events.js";import{IkasPageDataInit as x}from"../../page-data-init/index.js";import{setAPIClientConfig as g}from"@ikas/storefront-api";var v=s((function(){return import("../popup/index.js").then((function(e){return e.PopupListRendererForPage}))}),{ssr:!1}),y=r((function(r){var s=r.propValues,u=r.themeJsonComponents,y=r.customDataList,w=r.pageType,b=r.pageTitle,S=r.pageDescription,C=r.pageSpecificData,P=r.canonicals,D=r.disableIndex,k=r.settings,T=r.configJson,E=r.reInitOnBrowser,I=r.addOgpMetas,R=r.components,M=r.productReviewSummary,V=a(),O=i.useState(),z=O[0],B=O[1];p.init(e(e({},T),{currentPageComponents:R,loginRequiredCallback:function(){V.push("/account/login")}})),f.getInstance().router=V,g();var A=f.getInstance();A.router=V,A.currentPageType=w;var F=i.useState(!1),H=F[0],L=F[1],U=i.useMemo((function(){return(null==z?void 0:z.id)===(null==C?void 0:C.id)&&x.pageSpecificData&&x.isBrowser?w===d.PRODUCT&&x._initProductOnBrowser(x.pageSpecificData):x.setPageSpecificData(C,w,H),x.initPagePropValues(s,u,y.map((function(e){return new m(e)})),k,H)}),[H,s,w,k,C,u]);i.useEffect((function(){E&&L("undefined"!=typeof window),window.addToCart=A.cartStore._windowAddToCart,A.cartStore.getCart(),A.checkLocalization(),j()}),[]),i.useEffect((function(){C?(null==z?void 0:z.id)!==C.id&&B(C):B(null)}),[C]),i.useEffect((function(){var e=function(){A.customerStore.routeChangeInit()};return V.events.on("routeChangeStart",e),function(){V.events.off("routeChangeStart",e)}}),[]),i.useEffect((function(){!function(e,i){var r,a;t(this,void 0,void 0,(function(){var t,s,n,m,p,c;return o(this,(function(o){switch(o.label){case 0:t=f.getInstance(),l.pageView(e),o.label=1;case 1:return o.trys.push([1,4,,5]),e===d.PRODUCT&&(s=i,l.productView(s),t.customerStore.onProductView(s.id,s.selectedVariant.id)),e===d.CATEGORY&&(m=null===(r=(n=i).categoryPathItems)||void 0===r?void 0:r.map((function(e){return e.name})).join(" > "),m=n.categoryPathItems&&(null===(a=n.categoryPathItems)||void 0===a?void 0:a.length)>0?m+" > "+n.name:n.name,l.viewCategory(m,n)),e===d.BRAND&&(p=i,l.viewBrand(p)),e!==d.CART?[3,3]:[4,t.cartStore.waitUntilInitialized()];case 2:o.sent(),l.viewCart(t.cartStore.cart),o.label=3;case 3:return[3,5];case 4:return c=o.sent(),console.error(c),[3,5];case 5:return[2]}}))}))}(w,x.pageSpecificData)}),[w,C]);var _=i.useMemo((function(){var e=U.find((function(e){return e.component.isHeader})),t=U.find((function(e){return e.component.isFooter})),o=U.filter((function(e){return!e.component.isHeader&&!e.component.isFooter}))||[];return i.createElement("div",{style:{position:"relative",minHeight:"100vh",display:"flex",flexDirection:"column",justifyContent:"space-between"}},i.createElement("div",null,e&&h(e,k,-1),o.map((function(e,t){return h(e,k,t)}))),t&&h(t,k,-1),i.createElement(v,{key:Date.now()}))}),[U,k]),J=i.useMemo((function(){return p.getMerchantSettings()?new n(p.getMerchantSettings()):null}),[p.getMerchantSettings()]);return i.createElement(i.Fragment,null,i.createElement(c,{pageType:w,pageTitle:b,pageDescription:S,pageSpecificData:x.pageSpecificData,canonicals:P&&P.length>0?P:null,disableIndex:D,merchantSettings:J,addOgpMetas:I,productReviewSummary:M,pageComponentPropValues:U}),_)})),h=function(e,t,o){return i.createElement(u,{key:e.pageComponent.id,index:o,pageComponentPropValue:e,settings:t})};export{y as IkasPage,h as renderComponent};
1
+ import{__assign as e,__awaiter as t,__generator as o}from'./../../ext/tslib/tslib.es6.js';import*as i from"react";import{observer as r}from"mobx-react-lite";import{useRouter as a}from"next/router.js";import s from"next/dynamic";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasThemeJsonPageType as d}from"@ikas/storefront-models";import"mobx";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import{IkasMerchantSettings as n}from"../../models/data/merchant-settings/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import{IkasThemeJsonCustomData as m}from"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../../models/ui/blog-list/index.js";import"../../models/ui/blog-category-list/index.js";import"../../models/ui/brand-list/index.js";import"../../models/ui/category-list/index.js";import"../../models/ui/product-list/index.js";import"../../models/ui/product-attribute-detail/index.js";import"../../models/ui/product-attribute-list/index.js";import"../../models/ui/customer-review-list/index.js";import"../../models/ui/customer-review-summary-list/index.js";import"../../models/ui/validator/index.js";import"../../models/ui/validator/rules/index.js";import"../../models/ui/validator/form/login.js";import"../../models/ui/validator/form/address.js";import"../../models/ui/validator/form/ikas-address.js";import"../../models/ui/validator/form/register.js";import"../../models/ui/validator/form/contact-form.js";import"../../models/ui/validator/form/forgot-password.js";import"../../models/ui/validator/form/recover-password.js";import"../../models/ui/validator/form/account-info.js";import"../../models/ui/validator/form/raffle-form.js";import"../../models/ui/validator/form/customer-review.js";import"../../models/ui/raffle-list/index.js";import{IkasStorefrontConfig as p}from"@ikas/storefront-config";import{Analytics as l}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{IkasPageHead as c}from"./head.js";import{ThemeComponent as u}from"./ThemeComponent.js";import{IkasBaseStore as f}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import{initIkasEvents as j}from"../../analytics/events.js";import{IkasPageDataInit as x}from"../../page-data-init/index.js";import{setAPIClientConfig as g}from"@ikas/storefront-api";var v=s((function(){return import("../popup/index.js").then((function(e){return e.PopupListRendererForPage}))}),{ssr:!1}),y=r((function(r){var s=r.propValues,u=r.themeJsonComponents,y=r.customDataList,w=r.pageType,b=r.pageTitle,S=r.pageDescription,C=r.pageSpecificData,P=r.canonicals,D=r.disableIndex,k=r.settings,T=r.configJson,E=r.reInitOnBrowser,I=r.addOgpMetas,R=r.components,M=r.productReviewSummary,V=a(),O=i.useState(),z=O[0],B=O[1];p.init(e(e({},T),{currentPageComponents:R,loginRequiredCallback:function(){V.push("/account/login")}})),f.getInstance().router=V,g();var A=f.getInstance();A.router=V,A.currentPageType=w;var F=i.useState(!1),H=F[0],L=F[1],U=i.useMemo((function(){return(null==z?void 0:z.id)===(null==C?void 0:C.id)&&x.pageSpecificData&&x.isBrowser?w===d.PRODUCT&&x._initProductOnBrowser(x.pageSpecificData):x.setPageSpecificData(C,w,H),x.initPagePropValues(s,u,y.map((function(e){return new m(e)})),k,H)}),[H,s,w,k,C,u]);i.useEffect((function(){E&&L("undefined"!=typeof window),window.addToCart=A.cartStore._windowAddToCart,A.cartStore.getCart(),A.checkLocalization(),j()}),[]),i.useEffect((function(){C?(null==z?void 0:z.id)!==C.id&&B(C):B(null)}),[C]),i.useEffect((function(){var e=function(){A.customerStore.routeChangeInit()};return V.events.on("routeChangeStart",e),function(){V.events.off("routeChangeStart",e)}}),[]),i.useEffect((function(){!function(e,i){var r,a;t(this,void 0,void 0,(function(){var t,s,n,m,p,c;return o(this,(function(o){switch(o.label){case 0:return t=f.getInstance(),[4,l.pageView(e)];case 1:o.sent(),o.label=2;case 2:return o.trys.push([2,7,,8]),e!==d.PRODUCT?[3,4]:(s=i,[4,l.productView(s)]);case 3:o.sent(),t.customerStore.onProductView(s.id,s.selectedVariant.id),o.label=4;case 4:return e===d.CATEGORY&&(m=null===(r=(n=i).categoryPathItems)||void 0===r?void 0:r.map((function(e){return e.name})).join(" > "),m=n.categoryPathItems&&(null===(a=n.categoryPathItems)||void 0===a?void 0:a.length)>0?m+" > "+n.name:n.name,l.viewCategory(m,n)),e===d.BRAND&&(p=i,l.viewBrand(p)),e!==d.CART?[3,6]:[4,t.cartStore.waitUntilInitialized()];case 5:o.sent(),l.viewCart(t.cartStore.cart),o.label=6;case 6:return[3,8];case 7:return c=o.sent(),console.error(c),[3,8];case 8:return[2]}}))}))}(w,x.pageSpecificData)}),[w,C]);var _=i.useMemo((function(){var e=U.find((function(e){return e.component.isHeader})),t=U.find((function(e){return e.component.isFooter})),o=U.filter((function(e){return!e.component.isHeader&&!e.component.isFooter}))||[];return i.createElement("div",{style:{position:"relative",minHeight:"100vh",display:"flex",flexDirection:"column",justifyContent:"space-between"}},i.createElement("div",null,e&&h(e,k,-1),o.map((function(e,t){return h(e,k,t)}))),t&&h(t,k,-1),i.createElement(v,{key:Date.now()}))}),[U,k]),J=i.useMemo((function(){return p.getMerchantSettings()?new n(p.getMerchantSettings()):null}),[p.getMerchantSettings()]);return i.createElement(i.Fragment,null,i.createElement(c,{pageType:w,pageTitle:b,pageDescription:S,pageSpecificData:x.pageSpecificData,canonicals:P&&P.length>0?P:null,disableIndex:D,merchantSettings:J,addOgpMetas:I,productReviewSummary:M,pageComponentPropValues:U}),_)})),h=function(e,t,o){return i.createElement(u,{key:e.pageComponent.id,index:o,pageComponentPropValue:e,settings:t})};export{y as IkasPage,h as renderComponent};
@@ -7,6 +7,7 @@ declare type PaypalExpressCheckoutProps = {
7
7
  shape?: "rect" | "pill";
8
8
  label?: "paypal" | "checkout" | "buynow" | "pay" | "installment" | "subscribe" | "donate";
9
9
  errorMessage?: string;
10
+ quantity?: number;
10
11
  };
11
12
  export declare const PaypalExpressCheckout: React.FC<PaypalExpressCheckoutProps>;
12
13
  export {};
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as n}from'./../../ext/tslib/tslib.es6.js';import*as r from"react";import{observer as i}from"mobx-react-lite";import{IkasBaseStore as o}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import a from"../../store/checkout/index.js";import{IkasStorefrontConfig as s}from"@ikas/storefront-config";var c=i((function(i){var c=i.product,u=i.layout,l=i.color,d=i.shape,p=i.label,f=i.errorMessage,v=o.getInstance(),h=v.cartStore.cart,m=v.customerStore.customer,g=r.useState(""),y=g[0],w=g[1],I=r.useState(""),b=I[0],P=I[1],S=r.useState(""),E=S[0],C=S[1],U=r.useState(!1),j=U[0],A=U[1],R=r.useRef(null),N=r.useRef(null),O=r.useRef(null);r.useEffect((function(){if(E){t(void 0,void 0,void 0,(function(){var t,n,r,i,o,u;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=s.getPaymentGateways().map((function(t){return t.id})),[4,a.listPaymentGateway({cartId:E,id:{in:t},locale:s.getCurrentLocale(),transactionAmount:c.selectedVariant.finalPrice})];case 1:return n=e.sent(),r=null===(u=null===(o=n.data)||void 0===o?void 0:o.find((function(t){return"PAYPAL"===t.code})))||void 0===u?void 0:u.id,P(r||""),[3,3];case 2:return i=e.sent(),console.error("Error fetching PayPal ID:",i),[3,3];case 3:return[2]}}))}))}}),[E,c.selectedVariant.finalPrice]),r.useEffect((function(){if(E&&b){t(void 0,void 0,void 0,(function(){var t,n,r;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,a.getPayPalClientId({input:{cartId:E,paymentGatewayId:b}})];case 1:return t=e.sent(),w((null===(r=t.data)||void 0===r?void 0:r.clientId)||""),[3,3];case 2:return n=e.sent(),console.error("Error fetching Client ID:",n),[3,3];case 3:return[2]}}))}))}}),[E,b]),r.useEffect((function(){h&&C(h.id)}),[null==h?void 0:h.id]);var _=function(r){return t(void 0,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return(t=R.current)?(i=N.current,[4,a.updatePaypalOrder({input:n(n({cartId:E,transactionId:t,customer:m?{email:m.email,firstName:m.firstName,id:m.id,lastName:m.lastName}:null,address:i?{city:i.city,country:i.countryCode,postalCode:i.postalCode,state:i.state}:null},r.shippingSettingsId?{shippingSettingsId:r.shippingSettingsId}:{}),r.shippingZoneRateId?{shippingZoneRateId:r.shippingZoneRateId}:{})})]):[2,!1];case 1:return[2,!!e.sent().data]}}))}))};return r.useEffect((function(){if(E&&b&&y){var n=document.createElement("script");return n.src="https://www.paypal.com/sdk/js?client-id=".concat(y,"&currency=").concat(c.selectedVariant.price.currency),n.setAttribute("data-page-type","product-details"),n.addEventListener("load",(function(){window.paypal&&window.paypal.Buttons({style:{layout:u,color:l,shape:d,label:p},createOrder:function(){return t(void 0,void 0,void 0,(function(){var t,n,r;return e(this,(function(e){switch(e.label){case 0:return[4,a.createPayPalOrder({input:{cartId:E,paymentGatewayId:b},isPayNow:!0})];case 1:return t=e.sent(),A(!1),(null===(n=t.data)||void 0===n?void 0:n.transactionId)&&(o=t.data.transactionId,R.current=o,i={failUrl:t.data.failUrl,returnUrl:t.data.returnUrl},O.current={failUrl:i.failUrl,returnUrl:i.returnUrl}),[2,null===(r=t.data)||void 0===r?void 0:r.sessionToken]}var i,o}))}))},onShippingOptionsChange:function(n,r){return t(this,void 0,void 0,(function(){var t,i,o;return e(this,(function(e){switch(e.label){case 0:return console.log("selectedShippingOption",n),t=n.selectedShippingOption.id.split(":"),i=t[0],o=t[1],[4,_({shippingSettingsId:i,shippingZoneRateId:o})];case 1:return e.sent()?[2]:[2,r.reject()]}}))}))},onShippingAddressChange:function(n,r){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return console.log("SHIPPING_ADDRESS",n),function(t){N.current=t}(n.shippingAddress),[4,_({})];case 1:return t.sent()?[2]:[2,r.reject()]}}))}))},onApprove:function(n,r){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,r.order.capture().then((function(t){console.log("data",n),console.log("details",t),console.log("urls",O),O.current&&(console.log("burda"),"COMPLETED"===t.status?window.location.href=O.current.returnUrl:window.location.href=window.location.href=O.current.failUrl)})).catch((function(t){return A(!0)}))]}))}))},onError:function(t){console.error("PayPal button error:",t)}}).render("#paypal-button-container")})),document.body.appendChild(n),function(){document.body.removeChild(n)}}}),[y]),r.createElement("div",null,r.createElement("div",{id:"paypal-button-container"}),!E&&r.createElement("div",{onClick:function(){return t(void 0,void 0,void 0,(function(){var t,n,r,i;return e(this,(function(e){switch(e.label){case 0:return[4,v.cartStore.addItem(c.selectedVariant,c)];case 1:return t=e.sent(),(null===(i=null===(r=t.response)||void 0===r?void 0:r.data)||void 0===i?void 0:i.id)?(n=t.response.data,C(n.id),[2]):[2]}}))}))}},"Paypal Button ******"),!!j&&!!f&&r.createElement("div",{className:"paypal__error__message"},f))}));export{c as PaypalExpressCheckout};
1
+ import{__awaiter as e,__generator as t,__assign as r}from'./../../ext/tslib/tslib.es6.js';import*as n from"react";import{observer as o}from"mobx-react-lite";import{IkasBaseStore as i}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import a from"../../store/checkout/index.js";import{IkasStorefrontConfig as c}from"@ikas/storefront-config";var s=o((function(o){var s=o.product,u=o.layout,l=o.color,d=o.shape,p=o.label,f=o.errorMessage,v=o.quantity,h=i.getInstance(),m=h.customerStore.customer,g=n.useState(""),y=g[0],w=g[1],b=n.useState(!1),I=b[0],S=b[1],P=n.useRef(null),C=n.useRef(null),E=n.useRef(null),U=n.useRef(null),j=function(e){E.current=e};n.useEffect((function(){e(void 0,void 0,void 0,(function(){var e,r,n;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,a.getPayPalClientId({})];case 1:return e=t.sent(),w((null===(n=e.data)||void 0===n?void 0:n.clientId)||""),[3,3];case 2:return r=t.sent(),console.error("Error fetching Client ID:",r),[3,3];case 3:return[2]}}))}))}),[s]);var R=function(n){return e(void 0,void 0,void 0,(function(){var e,o,i;return t(this,(function(t){switch(t.label){case 0:return e=P.current,o=E.current,e&&o?(i=C.current,[4,a.updatePaypalOrder({input:r(r({cartId:o,transactionId:e,customer:m?{email:m.email,firstName:m.firstName,id:m.id,lastName:m.lastName}:null,address:i?{city:i.city,country:i.countryCode,postalCode:i.postalCode,state:i.state}:null},n.shippingSettingsId?{shippingSettingsId:n.shippingSettingsId}:{}),n.shippingZoneRateId?{shippingZoneRateId:n.shippingZoneRateId}:{})})]):[2,!1];case 1:return[2,!!t.sent().data]}}))}))};console.log("product.name 1",s.name);return n.useEffect((function(){if(y){var r=document.querySelector("#paypal-button-container");r&&(r.innerHTML="");var n=document.querySelector('script[src^="https://www.paypal.com/sdk/js"]');n&&document.body.removeChild(n);var o=document.createElement("script");return o.src="https://www.paypal.com/sdk/js?client-id=".concat(y,"&currency=").concat(s.selectedVariant.price.currency,"&disable-funding=credit,card"),o.setAttribute("data-page-type","product-details"),o.addEventListener("load",(function(){window.paypal&&window.paypal.Buttons({style:{layout:u,color:l,shape:d,label:p},onClick:function(r,n){return e(void 0,void 0,void 0,(function(){return t(this,(function(r){switch(r.label){case 0:return[4,e(void 0,void 0,void 0,(function(){return t(this,(function(e){if(h.cartStore.cart)try{h.cartStore.removeCart()}catch(e){console.error("Error removing items:",e)}return[2]}))}))];case 1:return r.sent(),[2,n.resolve()]}}))}))},createOrder:function(){return e(void 0,void 0,void 0,(function(){var r,n,o,i,u;return t(this,(function(l){switch(l.label){case 0:return[4,e(void 0,void 0,void 0,(function(){var e,r,n,o,i;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),console.log("product.name 2",s.name),[4,h.cartStore.addItem(s.selectedVariant,s,v||1)];case 1:return e=t.sent(),(null===(i=null===(o=e.response)||void 0===o?void 0:o.data)||void 0===i?void 0:i.id)?(r=e.response.data,j(r.id),[2,r.id]):[2,null];case 2:return n=t.sent(),console.log("err",n),[2,null];case 3:return[2]}}))}))];case 1:return l.sent(),[4,e(void 0,void 0,void 0,(function(){var e,r,n,o,i,u;return t(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),e=c.getPaymentGateways().map((function(e){return e.id})),(r=E.current)?[4,a.listPaymentGateway({cartId:r,id:{in:e},locale:c.getCurrentLocale(),transactionAmount:s.selectedVariant.finalPrice})]:[2,null];case 1:return n=t.sent(),[2,(null===(u=null===(i=n.data)||void 0===i?void 0:i.find((function(e){return"PAYPAL"===e.code})))||void 0===u?void 0:u.id)||null];case 2:return o=t.sent(),console.error("Error fetching PayPal ID:",o),[2,null];case 3:return[2]}}))}))];case 2:return r=l.sent(),(n=E.current)&&r?[4,a.createPayPalOrder({input:{cartId:n,paymentGatewayId:r},isPayNow:!0})]:[3,4];case 3:return o=l.sent(),S(!1),j(n),(null===(i=o.data)||void 0===i?void 0:i.transactionId)&&(p=o.data.transactionId,P.current=p,d={failUrl:o.data.failUrl,returnUrl:o.data.returnUrl},U.current={failUrl:d.failUrl,returnUrl:d.returnUrl}),[2,null===(u=o.data)||void 0===u?void 0:u.sessionToken];case 4:console.log("err"),l.label=5;case 5:return[2]}var d,p}))}))},onShippingOptionsChange:function(r,n){return e(this,void 0,void 0,(function(){var e,o,i;return t(this,(function(t){switch(t.label){case 0:return console.log("selectedShippingOption",r),e=r.selectedShippingOption.id.split(":"),o=e[0],i=e[1],[4,R({shippingSettingsId:o,shippingZoneRateId:i})];case 1:return t.sent()?[2]:[2,n.reject()]}}))}))},onShippingAddressChange:function(r,n){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return console.log("SHIPPING_ADDRESS",r),function(e){C.current=e}(r.shippingAddress),[4,R({})];case 1:return e.sent()?[2]:[2,n.reject()]}}))}))},onApprove:function(r,n){return e(this,void 0,void 0,(function(){return t(this,(function(e){return[2,n.order.capture().then((function(e){console.log("data",r),console.log("details",e),console.log("urls",U),U.current&&(console.log("burda"),"COMPLETED"===e.status?window.location.href=U.current.returnUrl:window.location.href=window.location.href=U.current.failUrl)})).catch((function(e){return S(!0)}))]}))}))},onError:function(e){console.error("PayPal button error:",e)}}).render("#paypal-button-container")})),document.body.appendChild(o),function(){document.body.removeChild(o)}}}),[y,s.id]),n.createElement("div",null,n.createElement("div",{id:"paypal-button-container"}),!!I&&!!f&&n.createElement("div",{className:"paypal__error__message"},f))}));export{s as PaypalExpressCheckout};
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as r}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import s from"lodash/xorBy";import o from"lodash/cloneDeep";import n from"./api.js";import{IkasCustomer as a}from"../../models/data/customer/index.js";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as c}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import{IkasRaffleParticipant as u}from"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import d from"../raffle/index.js";import'./../../ext/@ikas/fe-api-client/build/utils/api.js';import'./../../ext/axios/index.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_defineProperty.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseGetTag.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_stringToPath.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseToString.js';import l from"../product/index.js";import{Analytics as h}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{IkasStorefrontConfig as m}from"@ikas/storefront-config";import{IkasLoginError as p,IkasRegisterError as f,SaveMyCustomerInput as v}from"@ikas/storefront-api";import{populateRaffleParticipantProducts as g}from"@ikas/storefront-providers";import w from"../checkout/index.js";var k="undefined"==typeof localStorage,b=function(){function b(s){var a=this;this.customer=null,this.token=null,this.tokenExpiry=null,this.baseStore=null,this._initialized=!1,this._visitorSubscribedEmail=!1,this._lastViewedProducts=[],this._customerConsentGranted=!1,this._refundSettings=null,this._captchaToken=null,this._savedLastViewedProducts=[],this._savedLastViewedProductsResponse=null,this.toAnalyticsCustomer=function(t){return r(r({},t),{consentGranted:a._customerConsentGranted})},this.login=function(r,i){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:r,password:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(s=t.data,this.setToken(s.token,s.tokenExpiry),s.customer&&this.setCustomer(s.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,!0]):[2,!1]}}))}))},this.customerLogin=function(r,i){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:r,password:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(s=t.data,this.setToken(s.token,s.tokenExpiry),s.customer&&this.setCustomer(s.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,{isSuccess:!0,errorCodes:[]}]):[2,{isSuccess:!1,errorCodes:t.errorCodes.map((function(t){return Object.values(p).includes(t)?t:p.UNKOWN}))}]}}))}))},this.logout=function(){var t;a.clearLocalData(),null===(t=a.baseStore)||void 0===t||t.cartStore.removeCart(),h.customerLogout()},this.register=function(i,s,o,c,u,d,l){return t(a,void 0,void 0,(function(){var t,a;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.register({email:o,password:c,firstName:i,lastName:s,isAcceptMarketing:u,attributes:d,captchaToken:this._captchaToken,phone:l})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&(null===(a=t.data)||void 0===a?void 0:a.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.saveLocalLastViewedProducts(),h.completeRegistration(this.toAnalyticsCustomer(this.customer)),[2,{isSuccess:!0,errorCodes:[]}]):(t.errorCodes.some((function(t){return t===f.B2B_CUSTOMER_ACCOUNT_DISABLED}))&&h.completeRegistration(r(r({},this.toAnalyticsCustomer(this.customer)),{email:o,firstName:i,lastName:s,notificationsAccepted:null,attributes:d}),!0),[2,{isSuccess:!1,errorCodes:t.errorCodes.map((function(t){return Object.values(f).includes(t)?t:f.UNKOWN}))}])}}))}))},this.activateCustomer=function(){return t(a,void 0,void 0,(function(){var t,r,i;return e(this,(function(e){switch(e.label){case 0:return t=new URLSearchParams(window.location.search),(r=t.get("token"))?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.activateCustomer({token:r,captchaToken:this._captchaToken})];case 2:return i=e.sent(),this.clearCaptchaToken(),[2,i.isSuccess];case 3:return[2,!1]}}))}))},this.resendCustomerActivationMail=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return r?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.resendCustomerActivationMail({email:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess];case 3:return[2,!1]}}))}))},this.validateCustomerPhoneVerificationCode=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return r?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.validateCustomerPhoneVerificationCode({verificationCode:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!(!t.isSuccess||!t.data)&&t.data];case 3:return[2,!1]}}))}))},this.resendCustomerPhoneVerificationCode=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return r?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.resendCustomerPhoneVerificationCode({email:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!(!t.isSuccess||!t.data)&&t.data];case 3:return[2,!1]}}))}))},this.saveContactForm=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return h.contactForm(i),[4,this.getCaptcha()];case 1:return e.sent(),[4,n.sendContactFormToMerchant(r(r({},i),{captchaToken:this._captchaToken}))];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.checkEmail=function(r){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.checkEmail({email:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&!!(null===(i=t.data)||void 0===i?void 0:i.exists)]}}))}))},this.forgotPassword=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.forgotPassword({email:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&t.data]}}))}))},this.recoverPassword=function(r,i,s){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.recoverPassword({password:r,passwordAgain:i,token:s,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.saveCustomer=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.saveCustomer({input:new v(r)})];case 1:return(t=e.sent()).isSuccess&&t.data?(this.setCustomer(t.data),[2,!0]):[2,!1]}}))}))},this.getOrders=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getOrders({})];case 1:return[2,t.sent().data||[]]}}))}))},this.getOrder=function(r){return t(a,void 0,void 0,(function(){var t,i,s;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrders({orderId:r})];case 1:return(t=e.sent()).isSuccess&&(null===(s=t.data)||void 0===s?void 0:s.length)?(i=t.data[0],[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),i.refundSettings=this._refundSettings,[2,i]}}))}))},this.getOrderByEmail=function(r,i){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrderByEmail({email:r,orderNumber:i})];case 1:return(t=e.sent()).isSuccess&&t.data?(s=t.data,[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),s.refundSettings=this._refundSettings,[2,s]}}))}))},this.getOrderTransactions=function(r){return void 0===r&&(r={}),t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.listOrderTransactions({checkoutId:{eq:r.checkoutId},id:{eq:r.checkoutId},orderId:{eq:r.orderId}})];case 1:return[2,t.sent().data||[]]}}))}))},this.getOrderTransactionsWithPrices=function(r){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.listOrderTransactionsWithPrices({input:{orderId:r.orderId}})];case 1:return[2,t.sent().data]}}))}))},this.getFavoriteProductsIds=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProducts=function(){return t(a,void 0,void 0,(function(){var t,r,i,s,o,a;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return(t=e.sent()).isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)?[4,l.searchProducts({input:{productIdList:t.data.map((function(t){return t.productId})),priceListId:m.getPriceListId(),salesChannelId:m.getSalesChannelId(),perPage:100}})]:[2,[]];case 2:return r=e.sent(),null===(o=null===(s=r.data)||void 0===s?void 0:s.data)||void 0===o||o.forEach((function(t){t.selectedVariantValues=t.variants[0].variantValues})),[2,(null===(a=null==r?void 0:r.data)||void 0===a?void 0:a.data)||[]]}}))}))},this.addProductToFavorites=function(r){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.customer)||void 0===i?void 0:i.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!0,productId:r})];case 1:return t=e.sent(),h.addToWishlist(r),[2,t.data||!1]}}))}))},this.removeProductFromFavorites=function(r){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.customer)||void 0===i?void 0:i.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!1,productId:r})];case 1:return t=e.sent(),h.addToWishlist(r,!0),[2,t.data||!1]}}))}))},this.isProductFavorite=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!(null===(t=this.customer)||void 0===t?void 0:t.id))throw Error("Unauthorized");return[4,n.isFavoriteProduct({productId:r})];case 1:return[2,e.sent().data||!1]}}))}))},this.createEmailSubscription=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.subscribeToMarketingNotifications({input:{email:r,captchaToken:this._captchaToken}})];case 2:return(t=e.sent()).isSuccess&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,c.SUBSCRIBED):this._visitorSubscribedEmail=!0,h.createEmailSubscripition(r)),[2,t.isSuccess]}}))}))},this.saveCustomerFormData=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.saveCustomerFormData({input:r(r({},i),{captchaToken:this._captchaToken})})];case 2:return(t=e.sent()).isSuccess&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,c.SUBSCRIBED):this._visitorSubscribedEmail=!0,h.createEmailSubscripition(i.email)),[2,t.isSuccess]}}))}))},this.sendReview=function(i){return t(a,void 0,void 0,(function(){var t,s,o,a,c;return e(this,(function(e){switch(e.label){case 0:if(t=m.getCustomerReviewSettings(),s=m.getSalesChannelId(),o=m.getCurrentLocale(),!t)return[2];if(!(a=null===(c=this.customer)||void 0===c?void 0:c.id)&&t.customerLoginRequired)throw Error("Unauthorized");return[4,n.createCustomerReview({input:r(r({},i),{customerId:t.customerLoginRequired?a:void 0,salesChannelId:s||"",locale:o})})];case 1:return[2,e.sent().data]}}))}))},this.deactivateCustomer=function(r){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.deactivateCustomer({password:r})]:[3,2];case 1:return[2,t.sent()];case 2:return[2]}}))}))},this.exportCustomerPersonalData=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.exportCustomerPersonelData()]:[3,2];case 1:return[2,t.sent()];case 2:return[2]}}))}))},this.onCustomerConsentGrant=function(){a.saveCustomerConsent()},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a.initialized&&(clearInterval(e),t(null))}),100)}))},this.waitUntilCaptchaTokenInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a._captchaToken&&(clearInterval(e),t(null))}),100)}))},this.getRaffles=function(){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,d.listRaffleParticipants()];case 1:return(t=e.sent())&&t.data?[4,g(t.data)]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2,null===(r=t.data)||void 0===r?void 0:r.map((function(t){return new u(t)}))]}}))}))},this.getCustomerAttributes=function(){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,n.listCustomerAttribute()];case 1:return t=e.sent(),this.customer&&(null===(r=this.customer.attributes)||void 0===r||r.forEach((function(e){var r,i,s;e.customerAttribute=(null===(r=t.data)||void 0===r?void 0:r.find((function(t){return t.id===e.customerAttributeId})))||null,e.customerAttributeOptionId&&(e.customerAttributeOption=(null===(s=null===(i=e.customerAttribute)||void 0===i?void 0:i.options)||void 0===s?void 0:s.find((function(t){return t.id===e.customerAttributeOptionId})))||null)}))),[2,t.data||[]]}}))}))},this.getOrderProductFiles=function(r){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return r.length?[4,w.listProductFile({id:{in:r}})]:[2,[]];case 1:return[2,t.sent().data||[]]}}))}))},this.getDigitalProductFileDownloadUrl=function(r,i){return t(a,void 0,void 0,(function(){var t,s,o,n,a;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),(t=r.orderLineItems.find((function(t){return t.variant.id===i.variantId})))?[4,w.getDigitalProductFileDownloadUrl({orderId:r.id,orderLineItemId:t.id})]:[3,2];case 1:s=e.sent(),(o=s.data)&&((n=document.createElement("a")).href=o,n.download=decodeURIComponent(i.name.split("/")[i.name.split("/").length-1])||"",n.click(),n.remove()),e.label=2;case 2:return[3,4];case 3:return a=e.sent(),console.error(a),[3,4];case 4:return[2]}}))}))},this.getOrderRefundSettings=function(){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return this._refundSettings?[3,2]:[4,n.listOrderRefundSettings({})];case 1:(t=e.sent()).isSuccess&&(null===(r=t.data)||void 0===r?void 0:r.length)&&(this._refundSettings=t.data[0]),e.label=2;case 2:return[2]}}))}))},this.setSavedLastViewedProductsResponse=function(t){a._savedLastViewedProducts=o(a._lastViewedProducts),a._savedLastViewedProductsResponse=t},this.setCaptchaToken=function(t){a._captchaToken=t},this.baseStore=s,i(this)}return Object.defineProperty(b.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(b.prototype,"canCreateEmailSubscription",{get:function(){var t;return!((null===(t=this.customer)||void 0===t?void 0:t.isSubscribed)||k||this._visitorSubscribedEmail)&&!window.localStorage.getItem("customerEmailSubscription")},enumerable:!1,configurable:!0}),Object.defineProperty(b.prototype,"customerConsentGranted",{get:function(){return this._customerConsentGranted},enumerable:!1,configurable:!0}),Object.defineProperty(b.prototype,"isCaptchaRequired",{get:function(){var t;return(null===(t=m.getCustomerSettings())||void 0===t?void 0:t.requireCaptchaValidation)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(b.prototype,"useLastViewedProductResponse",{get:function(){var t;return(null===(t=this._savedLastViewedProducts)||void 0===t?void 0:t.length)&&this._savedLastViewedProductsResponse&&0===s(this._lastViewedProducts,this._savedLastViewedProducts,"productId").length},enumerable:!1,configurable:!0}),b.prototype.socialLogin=function(r){return t(this,void 0,void 0,(function(){var t,i,s;return e(this,(function(e){switch(e.label){case 0:return"undefined"==typeof window?[2]:(t=new URLSearchParams(window.location.search).get("redirect")||"",i="".concat(process.env.NEXT_PUBLIC_BASE_URL,"/ms/").concat(r,"/login/authenticate?redirect=").concat(t),[4,fetch(i,{headers:{"x-api-key":m.getApiKey()||"","x-sfid":m.getStorefrontId()||"","x-sfrid":m.getStorefrontRoutingId()||""}})]);case 1:return[4,e.sent().json()];case 2:return s=e.sent(),window.location.href=s.redirectUrl,[2]}}))}))},b.prototype.socialLoginToken=function(r){var i;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.socialLogin({code:r})];case 1:return(null==(t=e.sent())?void 0:t.isSuccess)&&(null===(i=t.data)||void 0===i?void 0:i.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.customer&&h.customerLogin(),[2,!0]):[2,!1]}}))}))},b.prototype.refundOrder=function(r,i){return t(this,void 0,void 0,(function(){var t,s,o=this;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=[],r.orderLineItems.map((function(e){null!==e.refundQuantity&&(null==t||t.push({orderLineItemId:e.id,quantity:e.refundQuantity?e.refundQuantity:0}))})),[4,n.createOrderRefundRequest({input:{email:i,orderId:r.id,orderLineItems:t}})];case 1:return(s=e.sent()).isSuccess&&s.data?(Object.entries(s.data).forEach((function(t){var e=t[0],r=t[1];o[e]=r})),[2,!0]):[3,3];case 2:return e.sent(),[3,3];case 3:return[2,!1]}}))}))},b.prototype.init=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.loadToken(),this.loadLastViewedProducts(),this.loadCustomerConsent(),[4,this.refreshToken()];case 1:return t.sent(),[4,this.getCustomer()];case 2:return t.sent(),this._initialized=!0,this.customer&&h.customerVisit(),[2]}}))}))},b.prototype.routeChangeInit=function(){this.loadToken(),!this.token&&this.customer&&this.clearLocalData(),this.token&&!this.customer&&this.getCustomer()},b.prototype.getCustomer=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return k||!this.token?[2]:[4,n.getCustomer()];case 1:return(t=e.sent()).data&&this.setCustomer(t.data),[2]}}))}))},b.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.token?[4,n.refreshToken({token:this.token})]:[2];case 1:return(t=e.sent()).isSuccess&&t.data?this.setToken(t.data.token,t.data.tokenExpiry):(this.token=null,this.tokenExpiry=null,this.clearLocalData()),[2]}}))}))},b.prototype.setCustomer=function(t){this.customer=new a(t)},b.prototype.getLastViewedProducts=function(){var r;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.getLastViewedProducts({customerId:this.customer.id})]:[3,2];case 1:return t=e.sent(),this._lastViewedProducts=(null===(r=o(t.data))||void 0===r?void 0:r.reverse())||[],[3,3];case 2:this.loadLastViewedProducts(),e.label=3;case 3:return[2,this._lastViewedProducts]}}))}))},b.prototype.saveLastViewedProducts=function(){k||window.localStorage.setItem("lastViewedProducts",JSON.stringify(this._lastViewedProducts))},b.prototype.loadLastViewedProducts=function(){k||(this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=o(this._lastViewedProducts).reverse())},b.prototype.getLocalLastViewedProducts=function(){if(k)return[];try{var t=window.localStorage.getItem("lastViewedProducts");if(t)return JSON.parse(t)}catch(t){}return[]},b.prototype.removeLastViewedProducts=function(){k||window.localStorage.removeItem("lastViewedProducts")},b.prototype.onProductView=function(r,i){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?this._lastViewedProducts.find((function(t){return t.productId===r}))?[2]:[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:[{productId:r,variantId:i}]}})]:[3,2];case 1:return t.sent()&&this._lastViewedProducts.push({productId:r,variantId:i}),[3,3];case 2:this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=this._lastViewedProducts.filter((function(t){return t.productId!==r})),this._lastViewedProducts.push({productId:r,variantId:i}),this._lastViewedProducts=this._lastViewedProducts.slice(-20),this.saveLastViewedProducts(),t.label=3;case 3:return[2]}}))}))},b.prototype.saveLocalLastViewedProducts=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(k)return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),(t=this.getLocalLastViewedProducts()).length?[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:t}})]:[3,3];case 2:e.sent()&&this.removeLastViewedProducts(),e.label=3;case 3:return[3,5];case 4:return e.sent(),[3,5];case 5:return[2]}}))}))},b.prototype.saveCustomerConsent=function(){k||(this._customerConsentGranted=!0,window.localStorage.setItem("customerConsent","true"))},b.prototype.loadCustomerConsent=function(){k||(this._customerConsentGranted=!!window.localStorage.getItem("customerConsent"))},b.prototype.removeCustomerConsent=function(){k||window.localStorage.removeItem("customerConsent")},b.prototype.setToken=function(t,e){k||(this.token=t,this.tokenExpiry=e,localStorage.setItem("customerToken",t),localStorage.setItem("customerTokenExpiry",e+""),m.init({customerToken:t}))},b.prototype.loadToken=function(){if(!k){var t=localStorage.getItem("customerToken"),e=localStorage.getItem("customerTokenExpiry");t&&e?this.setToken(t,parseInt(e)):this.clearLocalTokenData()}},b.prototype.clearLocalTokenData=function(){localStorage.removeItem("customerToken"),localStorage.removeItem("customerTokenExpiry"),this.token=void 0,this.tokenExpiry=void 0},b.prototype.clearLocalData=function(){this.clearLocalTokenData(),this.customer=void 0,m.init({customerToken:""}),this.clearCaptchaToken()},b.prototype.clearCaptchaToken=function(){this._captchaToken=null},b.prototype.getCaptcha=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),this.isCaptchaRequired?(window.grecaptcha.execute(),[4,this.waitUntilCaptchaTokenInitialized()]):[3,2];case 1:e.sent(),window.grecaptcha.reset(),e.label=2;case 2:return[3,4];case 3:return t=e.sent(),console.log("Get captcha error",t),[3,4];case 4:return[2]}}))}))},b}();export{b as IkasCustomerStore};
1
+ import{__awaiter as t,__generator as e,__assign as r}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import s from"lodash/xorBy";import o from"lodash/cloneDeep";import n from"./api.js";import{IkasCustomer as a}from"../../models/data/customer/index.js";import"../../models/data/blog/category/index.js";import"../../models/data/blog/content/index.js";import"../../models/data/blog/meta-data/index.js";import"../../models/data/blog/tag/index.js";import"../../models/data/blog/index.js";import"../../models/data/brand/index.js";import{IkasCustomerEmailSubscriptionStatus as c}from"@ikas/storefront-models";import"../../models/data/campaign-offer/index.js";import"../../models/data/cart/campaign-offer/index.js";import"../../models/data/cart/index.js";import"../../models/data/category/path-item/index.js";import"../../models/data/category/index.js";import"../../models/data/checkout/index.js";import"../../models/data/checkout-settings/index.js";import"../../models/data/city/index.js";import"../../models/data/country/index.js";import"../../models/data/customer/address/region/index.js";import"../../models/data/customer/address/index.js";import"../../models/data/customer/address/ikas-localized-customer-address.js";import"../../models/data/customer/attribute/index.js";import"../../models/data/customer/review/summary/index.js";import"../../models/data/customer/review/index.js";import"../../models/data/customer-form-data-input/index.js";import"../../models/data/district/index.js";import"../../models/data/favorite-product/index.js";import"../../models/data/filter-category/index.js";import"../../models/data/html-meta-data/index.js";import"../../models/data/image/index.js";import"../../models/data/order/address/region/index.js";import"../../models/data/order/address/index.js";import"../../models/data/order/line-item/option/value/index.js";import"../../models/data/order/line-item/variant/value/index.js";import"../../models/data/order/line-item/variant/index.js";import"../../models/data/order/line-item/index.js";import"../../models/data/order/order-transaction-with-prices/index.js";import"../../models/data/order/package/index.js";import"../../models/data/order/transaction/index.js";import"../../models/data/order/index.js";import"../../models/data/payment-gateway/index.js";import"../../models/data/product/attribute-value/index.js";import"../../models/data/product/filter/index.js";import"../../models/data/product/campaign-offer/index.js";import"../../models/data/product/option-set/option/index.js";import"../../models/data/product/option-set/index.js";import"../../models/data/product/stock-location/index.js";import"../../models/data/product/variant/price/index.js";import"../../models/data/product/variant/index.js";import"../../models/data/variant-type/index.js";import"../../models/data/product/index.js";import{IkasRaffleParticipant as u}from"../../models/data/raffle/index.js";import"../../models/data/shipping-zone/state/city/district/region/index.js";import"../../models/data/state/index.js";import"../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../models/data/storefront-popup/index.js";import"../../models/data/theme-json/index.js";import"../../models/data/theme-json/component/index.js";import"../../models/data/theme-json/custom-data/index.js";import"../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import d from"../raffle/index.js";import'./../../ext/@ikas/fe-api-client/build/utils/api.js';import'./../../ext/axios/index.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_defineProperty.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseGetTag.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_stringToPath.js';import'./../../ext/@ikas/fe-api-client/build/ext/lodash/_baseToString.js';import l from"../product/index.js";import{Analytics as h}from"../../analytics/analytics.js";import"../../analytics/head/index.js";import{IkasStorefrontConfig as m}from"@ikas/storefront-config";import{IkasLoginError as p,IkasRegisterError as f,SaveMyCustomerInput as v}from"@ikas/storefront-api";import{populateRaffleParticipantProducts as g}from"@ikas/storefront-providers";import w from"../checkout/index.js";var b="undefined"==typeof localStorage,k=function(){function k(s){var a=this;this.customer=null,this.token=null,this.tokenExpiry=null,this.baseStore=null,this._initialized=!1,this._visitorSubscribedEmail=!1,this._lastViewedProducts=[],this._customerConsentGranted=!1,this._refundSettings=null,this._captchaToken=null,this._savedLastViewedProducts=[],this._savedLastViewedProductsResponse=null,this.toAnalyticsCustomer=function(t){return r(r({},t),{consentGranted:a._customerConsentGranted})},this.login=function(r,i){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:r,password:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(s=t.data,this.setToken(s.token,s.tokenExpiry),s.customer&&this.setCustomer(s.customer),this.customer&&h.customerLogin(),this.saveLocalLastViewedProducts(),[2,!0]):[2,!1]}}))}))},this.customerLogin=function(r,i){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.login({email:r,password:i,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&t.data?(s=t.data,this.setToken(s.token,s.tokenExpiry),s.customer&&this.setCustomer(s.customer),this.customer?[4,h.customerLogin()]:[3,4]):[3,5];case 3:e.sent(),e.label=4;case 4:return this.saveLocalLastViewedProducts(),[2,{isSuccess:!0,errorCodes:[]}];case 5:return[2,{isSuccess:!1,errorCodes:t.errorCodes.map((function(t){return Object.values(p).includes(t)?t:p.UNKOWN}))}]}}))}))},this.logout=function(){var t;a.clearLocalData(),null===(t=a.baseStore)||void 0===t||t.cartStore.removeCart(),h.customerLogout()},this.register=function(i,s,o,c,u,d,l){return t(a,void 0,void 0,(function(){var t,a;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.register({email:o,password:c,firstName:i,lastName:s,isAcceptMarketing:u,attributes:d,captchaToken:this._captchaToken,phone:l})];case 2:return t=e.sent(),this.clearCaptchaToken(),t&&t.isSuccess&&(null===(a=t.data)||void 0===a?void 0:a.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.saveLocalLastViewedProducts(),h.completeRegistration(this.toAnalyticsCustomer(this.customer)),[2,{isSuccess:!0,errorCodes:[]}]):(t.errorCodes.some((function(t){return t===f.B2B_CUSTOMER_ACCOUNT_DISABLED}))&&h.completeRegistration(r(r({},this.toAnalyticsCustomer(this.customer)),{email:o,firstName:i,lastName:s,notificationsAccepted:null,attributes:d}),!0),[2,{isSuccess:!1,errorCodes:t.errorCodes.map((function(t){return Object.values(f).includes(t)?t:f.UNKOWN}))}])}}))}))},this.activateCustomer=function(){return t(a,void 0,void 0,(function(){var t,r,i;return e(this,(function(e){switch(e.label){case 0:return t=new URLSearchParams(window.location.search),(r=t.get("token"))?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.activateCustomer({token:r,captchaToken:this._captchaToken})];case 2:return i=e.sent(),this.clearCaptchaToken(),[2,i.isSuccess];case 3:return[2,!1]}}))}))},this.resendCustomerActivationMail=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return r?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.resendCustomerActivationMail({email:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess];case 3:return[2,!1]}}))}))},this.validateCustomerPhoneVerificationCode=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return r?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.validateCustomerPhoneVerificationCode({verificationCode:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!(!t.isSuccess||!t.data)&&t.data];case 3:return[2,!1]}}))}))},this.resendCustomerPhoneVerificationCode=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return r?[4,this.getCaptcha()]:[3,3];case 1:return e.sent(),[4,n.resendCustomerPhoneVerificationCode({email:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!(!t.isSuccess||!t.data)&&t.data];case 3:return[2,!1]}}))}))},this.saveContactForm=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return h.contactForm(i),[4,this.getCaptcha()];case 1:return e.sent(),[4,n.sendContactFormToMerchant(r(r({},i),{captchaToken:this._captchaToken}))];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.checkEmail=function(r){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.checkEmail({email:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&!!(null===(i=t.data)||void 0===i?void 0:i.exists)]}}))}))},this.forgotPassword=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.forgotPassword({email:r,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,!!t.isSuccess&&t.data]}}))}))},this.recoverPassword=function(r,i,s){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.recoverPassword({password:r,passwordAgain:i,token:s,captchaToken:this._captchaToken})];case 2:return t=e.sent(),this.clearCaptchaToken(),[2,t.isSuccess]}}))}))},this.saveCustomer=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.saveCustomer({input:new v(r)})];case 1:return(t=e.sent()).isSuccess&&t.data?(this.setCustomer(t.data),[2,!0]):[2,!1]}}))}))},this.getOrders=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.getOrders({})];case 1:return[2,t.sent().data||[]]}}))}))},this.getOrder=function(r){return t(a,void 0,void 0,(function(){var t,i,s;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrders({orderId:r})];case 1:return(t=e.sent()).isSuccess&&(null===(s=t.data)||void 0===s?void 0:s.length)?(i=t.data[0],[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),i.refundSettings=this._refundSettings,[2,i]}}))}))},this.getOrderByEmail=function(r,i){return t(a,void 0,void 0,(function(){var t,s;return e(this,(function(e){switch(e.label){case 0:return[4,n.getOrderByEmail({email:r,orderNumber:i})];case 1:return(t=e.sent()).isSuccess&&t.data?(s=t.data,[4,this.getOrderRefundSettings()]):[2,null];case 2:return e.sent(),s.refundSettings=this._refundSettings,[2,s]}}))}))},this.getOrderTransactions=function(r){return void 0===r&&(r={}),t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.listOrderTransactions({checkoutId:{eq:r.checkoutId},id:{eq:r.checkoutId},orderId:{eq:r.orderId}})];case 1:return[2,t.sent().data||[]]}}))}))},this.getOrderTransactionsWithPrices=function(r){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,n.listOrderTransactionsWithPrices({input:{orderId:r.orderId}})];case 1:return[2,t.sent().data]}}))}))},this.getFavoriteProductsIds=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return[2,t.sent().data||[]]}}))}))},this.getFavoriteProducts=function(){return t(a,void 0,void 0,(function(){var t,r,i,s,o,a;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.listFavoriteProducts()]:[2,[]];case 1:return(t=e.sent()).isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)?[4,l.searchProducts({input:{productIdList:t.data.map((function(t){return t.productId})),priceListId:m.getPriceListId(),salesChannelId:m.getSalesChannelId(),perPage:100}})]:[2,[]];case 2:return r=e.sent(),null===(o=null===(s=r.data)||void 0===s?void 0:s.data)||void 0===o||o.forEach((function(t){t.selectedVariantValues=t.variants[0].variantValues})),[2,(null===(a=null==r?void 0:r.data)||void 0===a?void 0:a.data)||[]]}}))}))},this.addProductToFavorites=function(r){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.customer)||void 0===i?void 0:i.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!0,productId:r})];case 1:return t=e.sent(),h.addToWishlist(r),[2,t.data||!1]}}))}))},this.removeProductFromFavorites=function(r){return t(a,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.customer)||void 0===i?void 0:i.id))throw Error("Unauthorized");return[4,n.saveFavoriteProduct({isFavorite:!1,productId:r})];case 1:return t=e.sent(),h.addToWishlist(r,!0),[2,t.data||!1]}}))}))},this.isProductFavorite=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(!(null===(t=this.customer)||void 0===t?void 0:t.id))throw Error("Unauthorized");return[4,n.isFavoriteProduct({productId:r})];case 1:return[2,e.sent().data||!1]}}))}))},this.createEmailSubscription=function(r){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.subscribeToMarketingNotifications({input:{email:r,captchaToken:this._captchaToken}})];case 2:return(t=e.sent()).isSuccess&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,c.SUBSCRIBED):this._visitorSubscribedEmail=!0,h.createEmailSubscripition(r)),[2,t.isSuccess]}}))}))},this.saveCustomerFormData=function(i){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,this.getCaptcha()];case 1:return e.sent(),[4,n.saveCustomerFormData({input:r(r({},i),{captchaToken:this._captchaToken})})];case 2:return(t=e.sent()).isSuccess&&(window.localStorage.setItem("customerEmailSubscription","true"),this.customer?(this.customer.subscriptionStatus,c.SUBSCRIBED):this._visitorSubscribedEmail=!0,h.createEmailSubscripition(i.email)),[2,t.isSuccess]}}))}))},this.sendReview=function(i){return t(a,void 0,void 0,(function(){var t,s,o,a,c;return e(this,(function(e){switch(e.label){case 0:if(t=m.getCustomerReviewSettings(),s=m.getSalesChannelId(),o=m.getCurrentLocale(),!t)return[2];if(!(a=null===(c=this.customer)||void 0===c?void 0:c.id)&&t.customerLoginRequired)throw Error("Unauthorized");return[4,n.createCustomerReview({input:r(r({},i),{customerId:t.customerLoginRequired?a:void 0,salesChannelId:s||"",locale:o})})];case 1:return[2,e.sent().data]}}))}))},this.deactivateCustomer=function(r){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.deactivateCustomer({password:r})]:[3,2];case 1:return[2,t.sent()];case 2:return[2]}}))}))},this.exportCustomerPersonalData=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?[4,n.exportCustomerPersonelData()]:[3,2];case 1:return[2,t.sent()];case 2:return[2]}}))}))},this.onCustomerConsentGrant=function(){a.saveCustomerConsent()},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a.initialized&&(clearInterval(e),t(null))}),100)}))},this.waitUntilCaptchaTokenInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a._captchaToken&&(clearInterval(e),t(null))}),100)}))},this.getRaffles=function(){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,d.listRaffleParticipants()];case 1:return(t=e.sent())&&t.data?[4,g(t.data)]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2,null===(r=t.data)||void 0===r?void 0:r.map((function(t){return new u(t)}))]}}))}))},this.getCustomerAttributes=function(){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return[4,n.listCustomerAttribute()];case 1:return t=e.sent(),this.customer&&(null===(r=this.customer.attributes)||void 0===r||r.forEach((function(e){var r,i,s;e.customerAttribute=(null===(r=t.data)||void 0===r?void 0:r.find((function(t){return t.id===e.customerAttributeId})))||null,e.customerAttributeOptionId&&(e.customerAttributeOption=(null===(s=null===(i=e.customerAttribute)||void 0===i?void 0:i.options)||void 0===s?void 0:s.find((function(t){return t.id===e.customerAttributeOptionId})))||null)}))),[2,t.data||[]]}}))}))},this.getOrderProductFiles=function(r){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return r.length?[4,w.listProductFile({id:{in:r}})]:[2,[]];case 1:return[2,t.sent().data||[]]}}))}))},this.getDigitalProductFileDownloadUrl=function(r,i){return t(a,void 0,void 0,(function(){var t,s,o,n,a;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),(t=r.orderLineItems.find((function(t){return t.variant.id===i.variantId})))?[4,w.getDigitalProductFileDownloadUrl({orderId:r.id,orderLineItemId:t.id})]:[3,2];case 1:s=e.sent(),(o=s.data)&&((n=document.createElement("a")).href=o,n.download=decodeURIComponent(i.name.split("/")[i.name.split("/").length-1])||"",n.click(),n.remove()),e.label=2;case 2:return[3,4];case 3:return a=e.sent(),console.error(a),[3,4];case 4:return[2]}}))}))},this.getOrderRefundSettings=function(){return t(a,void 0,void 0,(function(){var t,r;return e(this,(function(e){switch(e.label){case 0:return this._refundSettings?[3,2]:[4,n.listOrderRefundSettings({})];case 1:(t=e.sent()).isSuccess&&(null===(r=t.data)||void 0===r?void 0:r.length)&&(this._refundSettings=t.data[0]),e.label=2;case 2:return[2]}}))}))},this.setSavedLastViewedProductsResponse=function(t){a._savedLastViewedProducts=o(a._lastViewedProducts),a._savedLastViewedProductsResponse=t},this.setCaptchaToken=function(t){a._captchaToken=t},this.baseStore=s,i(this)}return Object.defineProperty(k.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"canCreateEmailSubscription",{get:function(){var t;return!((null===(t=this.customer)||void 0===t?void 0:t.isSubscribed)||b||this._visitorSubscribedEmail)&&!window.localStorage.getItem("customerEmailSubscription")},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"customerConsentGranted",{get:function(){return this._customerConsentGranted},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"isCaptchaRequired",{get:function(){var t;return(null===(t=m.getCustomerSettings())||void 0===t?void 0:t.requireCaptchaValidation)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(k.prototype,"useLastViewedProductResponse",{get:function(){var t;return(null===(t=this._savedLastViewedProducts)||void 0===t?void 0:t.length)&&this._savedLastViewedProductsResponse&&0===s(this._lastViewedProducts,this._savedLastViewedProducts,"productId").length},enumerable:!1,configurable:!0}),k.prototype.socialLogin=function(r){return t(this,void 0,void 0,(function(){var t,i,s;return e(this,(function(e){switch(e.label){case 0:return"undefined"==typeof window?[2]:(t=new URLSearchParams(window.location.search).get("redirect")||"",i="".concat(process.env.NEXT_PUBLIC_BASE_URL,"/ms/").concat(r,"/login/authenticate?redirect=").concat(t),[4,fetch(i,{headers:{"x-api-key":m.getApiKey()||"","x-sfid":m.getStorefrontId()||"","x-sfrid":m.getStorefrontRoutingId()||""}})]);case 1:return[4,e.sent().json()];case 2:return s=e.sent(),window.location.href=s.redirectUrl,[2]}}))}))},k.prototype.socialLoginToken=function(r){var i;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return[4,n.socialLogin({code:r})];case 1:return(null==(t=e.sent())?void 0:t.isSuccess)&&(null===(i=t.data)||void 0===i?void 0:i.customer)?(this.setToken(t.data.token,t.data.tokenExpiry),this.setCustomer(t.data.customer),this.customer?[4,h.customerLogin()]:[3,3]):[2,!1];case 2:e.sent(),e.label=3;case 3:return[2,!0]}}))}))},k.prototype.refundOrder=function(r,i){return t(this,void 0,void 0,(function(){var t,s,o=this;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=[],r.orderLineItems.map((function(e){null!==e.refundQuantity&&(null==t||t.push({orderLineItemId:e.id,quantity:e.refundQuantity?e.refundQuantity:0}))})),[4,n.createOrderRefundRequest({input:{email:i,orderId:r.id,orderLineItems:t}})];case 1:return(s=e.sent()).isSuccess&&s.data?(Object.entries(s.data).forEach((function(t){var e=t[0],r=t[1];o[e]=r})),[2,!0]):[3,3];case 2:return e.sent(),[3,3];case 3:return[2,!1]}}))}))},k.prototype.init=function(){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.loadToken(),this.loadLastViewedProducts(),this.loadCustomerConsent(),[4,this.refreshToken()];case 1:return t.sent(),[4,this.getCustomer()];case 2:return t.sent(),this._initialized=!0,this.customer?[4,h.customerVisit()]:[3,4];case 3:t.sent(),t.label=4;case 4:return[2]}}))}))},k.prototype.routeChangeInit=function(){this.loadToken(),!this.token&&this.customer&&this.clearLocalData(),this.token&&!this.customer&&this.getCustomer()},k.prototype.getCustomer=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return b||!this.token?[2]:[4,n.getCustomer()];case 1:return(t=e.sent()).data&&this.setCustomer(t.data),[2]}}))}))},k.prototype.refreshToken=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.token?[4,n.refreshToken({token:this.token})]:[2];case 1:return(t=e.sent()).isSuccess&&t.data?this.setToken(t.data.token,t.data.tokenExpiry):(this.token=null,this.tokenExpiry=null,this.clearLocalData()),[2]}}))}))},k.prototype.setCustomer=function(t){this.customer=new a(t)},k.prototype.getLastViewedProducts=function(){var r;return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.customer?[4,n.getLastViewedProducts({customerId:this.customer.id})]:[3,2];case 1:return t=e.sent(),this._lastViewedProducts=(null===(r=o(t.data))||void 0===r?void 0:r.reverse())||[],[3,3];case 2:this.loadLastViewedProducts(),e.label=3;case 3:return[2,this._lastViewedProducts]}}))}))},k.prototype.saveLastViewedProducts=function(){b||window.localStorage.setItem("lastViewedProducts",JSON.stringify(this._lastViewedProducts))},k.prototype.loadLastViewedProducts=function(){b||(this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=o(this._lastViewedProducts).reverse())},k.prototype.getLocalLastViewedProducts=function(){if(b)return[];try{var t=window.localStorage.getItem("lastViewedProducts");if(t)return JSON.parse(t)}catch(t){}return[]},k.prototype.removeLastViewedProducts=function(){b||window.localStorage.removeItem("lastViewedProducts")},k.prototype.onProductView=function(r,i){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return this.customer?this._lastViewedProducts.find((function(t){return t.productId===r}))?[2]:[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:[{productId:r,variantId:i}]}})]:[3,2];case 1:return t.sent()&&this._lastViewedProducts.push({productId:r,variantId:i}),[3,3];case 2:this._lastViewedProducts=this.getLocalLastViewedProducts(),this._lastViewedProducts=this._lastViewedProducts.filter((function(t){return t.productId!==r})),this._lastViewedProducts.push({productId:r,variantId:i}),this._lastViewedProducts=this._lastViewedProducts.slice(-20),this.saveLastViewedProducts(),t.label=3;case 3:return[2]}}))}))},k.prototype.saveLocalLastViewedProducts=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:if(b)return[2];e.label=1;case 1:return e.trys.push([1,4,,5]),(t=this.getLocalLastViewedProducts()).length?[4,n.saveLastViewedProducts({input:{customerId:this.customer.id,products:t}})]:[3,3];case 2:e.sent()&&this.removeLastViewedProducts(),e.label=3;case 3:return[3,5];case 4:return e.sent(),[3,5];case 5:return[2]}}))}))},k.prototype.saveCustomerConsent=function(){b||(this._customerConsentGranted=!0,window.localStorage.setItem("customerConsent","true"))},k.prototype.loadCustomerConsent=function(){b||(this._customerConsentGranted=!!window.localStorage.getItem("customerConsent"))},k.prototype.removeCustomerConsent=function(){b||window.localStorage.removeItem("customerConsent")},k.prototype.setToken=function(t,e){b||(this.token=t,this.tokenExpiry=e,localStorage.setItem("customerToken",t),localStorage.setItem("customerTokenExpiry",e+""),m.init({customerToken:t}))},k.prototype.loadToken=function(){if(!b){var t=localStorage.getItem("customerToken"),e=localStorage.getItem("customerTokenExpiry");t&&e?this.setToken(t,parseInt(e)):this.clearLocalTokenData()}},k.prototype.clearLocalTokenData=function(){localStorage.removeItem("customerToken"),localStorage.removeItem("customerTokenExpiry"),this.token=void 0,this.tokenExpiry=void 0},k.prototype.clearLocalData=function(){this.clearLocalTokenData(),this.customer=void 0,m.init({customerToken:""}),this.clearCaptchaToken()},k.prototype.clearCaptchaToken=function(){this._captchaToken=null},k.prototype.getCaptcha=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),this.isCaptchaRequired?(window.grecaptcha.execute(),[4,this.waitUntilCaptchaTokenInitialized()]):[3,2];case 1:e.sent(),window.grecaptcha.reset(),e.label=2;case 2:return[3,4];case 3:return t=e.sent(),console.log("Get captcha error",t),[3,4];case 4:return[2]}}))}))},k}();export{k as IkasCustomerStore};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "6.1.0-beta.61",
3
+ "version": "6.1.0-beta.63",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -21,11 +21,11 @@
21
21
  "swiper": "11.0.6"
22
22
  },
23
23
  "devDependencies": {
24
- "@ikas/storefront-api": "^6.1.0-beta.61",
25
- "@ikas/storefront-config": "^6.1.0-beta.61",
26
- "@ikas/storefront-model-functions": "^6.1.0-beta.61",
27
- "@ikas/storefront-models": "^6.1.0-beta.61",
28
- "@ikas/storefront-providers": "^6.1.0-beta.61",
24
+ "@ikas/storefront-api": "^6.1.0-beta.63",
25
+ "@ikas/storefront-config": "^6.1.0-beta.63",
26
+ "@ikas/storefront-model-functions": "^6.1.0-beta.63",
27
+ "@ikas/storefront-models": "^6.1.0-beta.63",
28
+ "@ikas/storefront-providers": "^6.1.0-beta.63",
29
29
  "@ikas/localized-address": "1.0.0-beta.6",
30
30
  "@adyen/adyen-web": "^5.57.0",
31
31
  "@rollup/plugin-commonjs": "^22.0.0",
@@ -60,11 +60,11 @@
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@ikas/localized-address": "1.0.0-beta.6",
63
- "@ikas/storefront-api": "^6.1.0-beta.61",
64
- "@ikas/storefront-config": "^6.1.0-beta.61",
65
- "@ikas/storefront-model-functions": "^6.1.0-beta.61",
66
- "@ikas/storefront-models": "^6.1.0-beta.61",
67
- "@ikas/storefront-providers": "^6.1.0-beta.61",
63
+ "@ikas/storefront-api": "^6.1.0-beta.63",
64
+ "@ikas/storefront-config": "^6.1.0-beta.63",
65
+ "@ikas/storefront-model-functions": "^6.1.0-beta.63",
66
+ "@ikas/storefront-models": "^6.1.0-beta.63",
67
+ "@ikas/storefront-providers": "^6.1.0-beta.63",
68
68
  "mobx": "^6.1.3",
69
69
  "mobx-react-lite": "^3.1.5",
70
70
  "next": "12.2.0",