"use strict";(self.webpackChunkstorefront_credit=self.webpackChunkstorefront_credit||[]).push([[502],{9502:(e,t,l)=>{l.r(t),l.d(t,{default:()=>w});var i=l(4914),n=l.n(i),o=l(6672),r=l.n(o),a=l(5605);const c=["sku","featured_image","product_description","title","url","handle","product_type","product_title","discounts","variant_options","options_with_values","variant_title","vendor","image"],s=e=>{let t={...e};return t=(e=>{const t=a.GlobalStore.Get()._globalActions.Helpers[0].Utility;let l={...e};l.cart_token=l.token,delete l.token;let i=[];for(var n=0;nbtoa(unescape(encodeURIComponent(JSON.stringify(e)))))(t),t};var d=l(8330);const u={flits_credit_code_div:"CreditUsageComponent_flits_credit_code_div__MFp8z",flits_select_row:"CreditUsageComponent_flits_select_row__NCq4S",flits_select_arrow:"CreditUsageComponent_flits_select_arrow__33aZW",flits_input:"CreditUsageComponent_flits_input__7s91O"},p=e=>{var t,l;const i=e.availableSpentRules,o=a.GlobalStore.Get()._globalActions.Helpers[0].useTranslationLanguage,{t:r}=o();return n().createElement(n().Fragment,null,n().createElement("div",{className:"".concat(u.flits_select_row," ").concat(u.flits_cart_drp)},n().createElement("div",{className:u.flits_select_arrow},n().createElement("svg",{viewBox:"0 0 24 24",width:"14",height:"14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none",shapeRendering:"geometricPrecision"},n().createElement("path",{d:"M6 9l6 6 6-6"}))),n().createElement("select",{onChange:t=>{e.onChange(t.target.value)},className:"".concat(u.flits_want_to_use_credit," ").concat(u.flits_input)},n().createElement("option",{value:"-1"},r("flits.cart_page.select_credit_option","Select option to use store credit")),(null==i||null===(t=i.code)||void 0===t?void 0:t.rules)&&(null==i||null===(l=i.code)||void 0===l||null===(l=l.rules)||void 0===l?void 0:l.map((e=>{var t;return"refund_credit"===(null==e?void 0:e.credit_type)?(null==e?void 0:e.applicable_refund_credits)<=0?null:n().createElement("option",{value:null==e?void 0:e.rule.id,key:null==e?void 0:e.rule.id},r("flits.cart_page.store_credit_dropdown_text","Use store credit of {{ credit }}.",{credit:(parseFloat(null==e?void 0:e.applicable_refund_credits)/100).toFixed(2)})):(null==e?void 0:e.applicable_credits)<=0?null:n().createElement("option",{value:null==e?void 0:e.rule.id,key:null==e?void 0:e.rule.id},r("flits.cart_page.credit_cart_percentage","Use reward credit of {{ credit }} out of {{ total_credit }}.",{credit:(parseFloat(null==e?void 0:e.applicable_credits)/100).toFixed(2),total_credit:(parseFloat(null==i||null===(t=i.code)||void 0===t?void 0:t.total_credits)/100).toFixed(2)}))}))))))},m=(e,t)=>{const l=a.GlobalStore.Get()._globalActions.Helpers[0].Utility;let i={};Object.keys(e).length>0&&(i=e);let n=t.closest("form");if(!n){const e=t.getAttribute("data-flits-checkout-index");e&&(n=window.document.querySelector("[data-flits='store-credit-cart-form'][data-flits-checkout-index='"+e+"']"))}if(!n)return window.location.href="/checkout?"+new URLSearchParams(e).toString(),!0;let o=n.action,r=l.parseURL(o);Object.keys(i).forEach(((e,t)=>{let l=i[e],a=n.querySelector("[name='"+e+"']");if(a)a.value=l;else{let t=window.document.createElement("input");t.type="hidden",t.name=e,t.value=l,n.appendChild(t)}r.searchObject[e]?o=o.replace(e+"="+r.searchObject[e],l):o+=(-1!==o.indexOf("?")?"&":"?")+e+"="+l}));let c=window.document.createElement("input");c.type="hidden",c.name="checkout",c.value="true",n.appendChild(c),n.action=o;let s=window.document.createElement("button");s.setAttribute("flitsFormSubmitted",!0),n.dispatchEvent(new SubmitEvent("submit",{isTrusted:!0,bubbles:!0,cancelBubble:!1,cancelable:!0,composed:!1,submitter:s}))};function f(){return f=Object.assign?Object.assign.bind():function(e){for(var t=1;t{const t=e.appendedTo.getAttribute("data-flits-checkout-index"),l=window.document.querySelector("[data-flits='store-credit-added'][data-flits-checkout-index='"+t+"']"),o=window.document.querySelector("[data-flits='store-credit-cart-form'][data-flits-checkout-index='"+t+"']"),r=window.document.querySelector("[data-flits='store-credit-update-button'][data-flits-checkout-index='"+t+"']");let c=(0,d.useSelector)((e=>e.StoreFrontShopifyData.cartData));const v=a.GlobalStore.Get(),[_,b]=(0,i.useState)(-1),h=v._globalActions.Helpers[0].useTranslationLanguage,{t:w}=h(),g=e=>{return e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),!!(()=>{if(window.Zapiet){var e=!1;if(window.Zapiet.Widget.checkoutEnabled()&&(e=!0),!e)return!1}return!0})()&&(-1===_?(a.GlobalStore.Get()._globalActions.API[0].API.credit.delete_discounts({customer_hash:null===(t=window)||void 0===t||null===(t=t.flitsThemeAppExtensionObjects)||void 0===t||null===(t=t.customer)||void 0===t?void 0:t.customer_hash,token:null===(i=window)||void 0===i||null===(i=i.flitsThemeAppExtensionObjects)||void 0===i||null===(i=i.customer)||void 0===i?void 0:i.shop_token}),m({discount:"+"},l)):(e=>{var t,l;let{event:i,cartData:n,t:o,checkoutButton:r,selectedValue:c}=e;const d=a.GlobalStore.Get()._globalActions.API[0].API;let u=o("flits.cart_page.applying_credit_message","Applying credit please wait");"input"===r.tagName.toString().toLowerCase()?r.value=u:r.innerHTML=u,r.disabled=!0;let p=s(n);if(n.total_price<=0)return m({discount:"+"},r),!1;d.credit.apply_credit({customer_hash:null===(t=window)||void 0===t||null===(t=t.flitsThemeAppExtensionObjects)||void 0===t||null===(t=t.customer)||void 0===t?void 0:t.customer_hash,token:null===(l=window)||void 0===l||null===(l=l.flitsThemeAppExtensionObjects)||void 0===l||null===(l=l.customer)||void 0===l?void 0:l.shop_token,data:p,spent_rule_id:c}).then((e=>{e.status?m({discount:e.code},r):m({discount:"+"},r)})).catch((()=>{m({discount:"+"},r)}))})({event:e,cartData:c,t:w,checkoutButton:l,selectedValue:_}),!1);var t,i},E=e=>{e.target.setAttribute("data-flits-clicked","update-cart-btn")},k=e=>{const t=e.target.getAttribute("data-flits-clicked");t&&"update-cart-btn"===t||null==r||r.removeAttribute("data-flits-clicked")},A=e=>{if(e.submitter.getAttribute("flitsFormSubmitted"))return o.submit(),!0;if(window.document.querySelectorAll("[data-flits-clicked='update-cart-btn']").length>0)return!0;var t=null;return e.originalEvent&&e.originalEvent.submitter&&(t=e.originalEvent.submitter),t||"submit"!==document.activeElement.type||(t=document.activeElement),t||(t=l),!t||g(e)};return(0,i.useEffect)((()=>(null==l||l.addEventListener("click",g),null==r||r.addEventListener("click",E),window.document.addEventListener("click",k),null==o||o.addEventListener("submit",A),()=>{null==l||l.removeEventListener("click",g),null==r||r.removeEventListener("click",E),window.document.removeEventListener("click",k),null==o||o.removeEventListener("submit",A)}))),n().createElement(n().Fragment,null,n().createElement("div",{className:u.flits_credit_code_div},n().createElement(p,f({},e,{onChange:e=>{b(parseInt(e))}}))))},_=["input[name='checkout']","button[name='checkout']","[href$='checkout']"],b=["input[name='update']","button[name='update']","[href$='update']"],h=()=>{const[e,t]=(0,i.useState)(null);let l=(0,d.useSelector)((e=>e.StoreFrontShopifyData.cartData));const o=a.GlobalStore.Get()._globalActions.Helpers[0].Utility;if((0,i.useEffect)((()=>{var e;const i=null===(e=window)||void 0===e||null===(e=e.flitsThemeAppExtensionObjects)||void 0===e||null===(e=e.customer)||void 0===e?void 0:e.customer_id;-1!==l&&null!=i&&-1!==i&&"-1"!==i&&(async()=>{const e=await(async e=>{try{var t,l;if(e.total_price<=0)return;const i=a.GlobalStore.Get(),n=i._globalActions.API[0].API,o=i._globalActions.Helpers[0].SetLocalStorage,r=i._globalActions.Helpers[0].GetLocalStorage,c=s(e);if(r("lastLoadedCart")===c)return r("lastLoadedSpentRules");o("lastLoadedCart",c);const d={customer_hash:null===(t=window)||void 0===t||null===(t=t.flitsThemeAppExtensionObjects)||void 0===t?void 0:t.customerHash,token:null===(l=window)||void 0===l||null===(l=l.flitsThemeAppExtensionObjects)||void 0===l?void 0:l.shop_token,cart:c},u=await n.credit.get_available_rules(d);return o("lastLoadedSpentRules",u),u}catch(e){}})(l);t(e)})()}),[o,l]),(0,i.useEffect)((()=>{var e,t;"cart"===(null===(e=window)||void 0===e||null===(e=e.flitsThemeAppExtensionObjects)||void 0===e||null===(e=e.Metafields)||void 0===e?void 0:e.CREDIT_DISPLAY_ON)&&1===parseInt(null===(t=window)||void 0===t||null===(t=t.flitsThemeAppExtensionObjects)||void 0===t||null===(t=t.Metafields)||void 0===t?void 0:t.is_cart_code_automatic)&&_.forEach(((e,t)=>{window.document.querySelectorAll(e).forEach(((e,t)=>{if("store-credit-added"===e.getAttribute("data-flits"))return!0;if("none"===e.style.display||"hidden"===e.style.visibility)return!0;if("function"!=typeof e.addEventListener)return!0;let l=window.document.createElement("div");l.style.display="none",l.classList.add("flits-cart-automatic-code"),l.setAttribute("data-flits-checkout-index",t),e.parentElement.insertBefore(l,e),e.setAttribute("data-flits","store-credit-added"),e.setAttribute("data-flits-checkout-index",t),e.parentElement.setAttribute("data-flits-checkout-index",t),e.parentElement.setAttribute("data-flits","store-credit-parent");let i=e.closest("form");i||(i=document.getElementById(e.getAttribute("form"))),i&&(i.setAttribute("data-flits","store-credit-cart-form"),i.setAttribute("data-flits-checkout-index",t),b.forEach(((e,l)=>{let n=i.querySelector(e);if(n||(n=window.document.querySelector(e+"[form='cart']")),!n)return!0;n.setAttribute("data-flits","store-credit-update-button"),n.setAttribute("data-flits-checkout-index",t),n.setAttribute("data-flits-index",l)})))}))}))})),!e||null==e||null===(c=e.code)||void 0===c||null===(c=c.rules)||void 0===c||!c.length||(null==e||null===(u=e.code)||void 0===u||null===(u=u.rules)||void 0===u?void 0:u.length)<=0)return null;var c,u;const p=Array.from(window.document.querySelectorAll(".flits-cart-automatic-code"));return n().createElement(n().Fragment,null,p.map(((t,l)=>(t.style.display="block",r().createPortal(n().createElement(v,{availableSpentRules:e,appendedTo:t}),t)))))},w=function(e){return(0,i.useEffect)((()=>{const e=document.getElementsByClassName("flits_initial_loader");for(let t=0;t