"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[17],{36:function(e,t,o){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.CouponCheckbox=function({couponExpiration:e,couponCheckbox:t,couponApplied:o}){const{disableCheckbox:n,applyCoupon:p,timeLeft:r,status:f}=function({couponExpiration:e,couponCheckbox:t,couponApplied:o}){var n;const[i,a]=(0,s.useState)(o?"applied":"available"),l=Date.now()+1e3*(null!==(n=null==t?void 0:t.countdown_minutes)&&void 0!==n?n:0)*60,u=Math.round(((null!=e?e:l)-Date.now())/1e3),[p,{startCountdown:r}]=(0,d.useCountdown)({countStart:u});if(!t||(null==t?void 0:t.disable_checkbox)||p<=0)return{disableCheckbox:!0,timeLeft:0,status:"disabled",applyCoupon(){}};(0,s.useEffect)((()=>{if(null==t?void 0:t.countdown_minutes){if(!e){const e=new Date(l);(0,c.setCookie)("__orly_checkbox_exp",e.toISOString())}r()}}),[]);return{disableCheckbox:!1,applyCoupon:()=>{function e(){a("available"),alert("There was an error applying coupon, please try again.")}"available"===i&&(a("pending"),fetch(`/discount/${null==t?void 0:t.coupon_code_to_apply}`).then((t=>{[200,301,302].includes(t.status)?((0,c.setCookie)("__orly_checkbox_applied","applied"),a("applied")):e()})).catch((t=>{e()})))},timeLeft:p,status:i}}({couponExpiration:e,couponCheckbox:t,couponApplied:o}),h=(0,u.useIsHydrated)();return n?(0,i.jsx)(a.Fragment,{}):(0,i.jsxs)("div",{class:l.default.coupon,onClick:e=>{p()},children:[(0,i.jsx)("div",{class:l.default.couponLabel,children:"COUPON"}),(0,i.jsxs)("div",{class:l.default.details,children:[(0,i.jsx)("input",{type:"checkbox",disabled:"applied"!==f&&(!h||"pending"===f),class:l.default.checkbox,checked:"applied"===f,onClick:e=>{e.preventDefault(),p()}}),(0,i.jsxs)("div",{children:[(0,i.jsx)("div",{class:l.default.text,children:"applied"===f?null==t?void 0:t.checked_message:"pending"===f?"Coupon is being applied...":null==t?void 0:t.initial_message}),(0,i.jsxs)("div",{class:l.default.expireTime,children:[null==t?void 0:t.expires_message," ",(e=>{const t=Math.floor(e/3600),o=Math.floor(e%3600/60),n=e%60;return`${t.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`})(r)]})]})]})]})};const i=o(0),a=o(1),l=n(o(45)),s=o(3),u=o(20),c=o(207),d=o(42)},207:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.setCookie=function(e,t,o="/"){const n=new Date;n.setTime(n.getTime()+1728e5);const i="expires="+n.toUTCString();document.cookie=`${e}=${t}; ${i}; path=${o}`}},20:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useIsHydrated=function(){const[e,t]=(0,n.useState)(!1);return(0,n.useEffect)((()=>{t(!0)}),[]),e};const n=o(3)}}]);