1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5979],{35979:(e,t,a)=>{a.d(t,{CustomerProvider:()=>c,c:()=>u});var l=a(95155),r=a(12115);function s(){let e=new Date().toISOString().slice(0,10);return{profile:{name:"",email:"",phone:"",joined:e},addresses:[],cards:[],wallet:{balance:0,txns:[]},refills:[],orders:[],refunds:[],exchanges:[],tickets:[],chat:[{id:"m1",from:"store",text:"Hi \uD83D\uDC4B Welcome to Express Rx Online support. How can we help?",date:e}],security:{twoFA:{enabled:!1,method:"email",secret:""}},loyalty:{points:0,lifetimePoints:0,referralCode:"",referrals:[],history:[],redeemed:[],freeMedClaimed:0}}}let n=(0,r.createContext)(null),o="expressrxonline_customer",i="expressrxonline_customer_auth";function d(e){try{let t=JSON.parse(localStorage.getItem(o)||"{}")?.profile||{};fetch("/api/customer-request/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({customer:t.name,email:t.email,...e}),keepalive:!0}).catch(()=>{})}catch{}}function c(e){let{children:t}=e,[a,c]=(0,r.useState)(!1),[u,m]=(0,r.useState)(s),[p,f]=(0,r.useState)(!1);(0,r.useEffect)(()=>{try{let e=localStorage.getItem(o);e&&m({...s(),...JSON.parse(e)}),c("1"===localStorage.getItem(i))}catch{}f(!0)},[]),(0,r.useEffect)(()=>{if(p)try{localStorage.setItem(o,JSON.stringify(u))}catch{}},[u,p]),(0,r.useEffect)(()=>{let e=()=>{try{let e=localStorage.getItem(o);if(e){let t=JSON.parse(e);m(e=>({...e,chat:t.chat??e.chat,tickets:t.tickets??e.tickets,wallet:t.wallet??e.wallet,refunds:t.refunds??e.refunds,exchanges:t.exchanges??e.exchanges}))}}catch{}};return window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)},[]);let w=(0,r.useCallback)((e,t)=>{let a,l=e.trim().toLowerCase();if(!l||!t)return!1;try{a=JSON.parse(localStorage.getItem("expressrxonline_accounts")||"{}")[l]}catch{return!1}if(!a||a.pending||!a.password||t!==a.password)return!1;let r=a;return m(e=>{let t=e.profile.email&&e.profile.email.toLowerCase()!==l?s():e;return{...t,profile:{...t.profile,name:r.name||t.profile.name,email:l,phone:r.phone||t.profile.phone,joined:r.joined||t.profile.joined}}}),localStorage.setItem(i,"1"),c(!0),!0},[]),y=(0,r.useCallback)(()=>{localStorage.removeItem(i);try{localStorage.removeItem(o)}catch{}m(s()),c(!1)},[]),g=(0,r.useCallback)(e=>m(t=>({...t,profile:e})),[]),h=(0,r.useCallback)(e=>m(t=>({...t,security:e})),[]),S=(0,r.useCallback)(e=>{let t="";return m(a=>{if(a.loyalty.points<e.cost)return a;t=`MC-${Math.random().toString(36).slice(2,6).toUpperCase()}${Math.random().toString(36).slice(2,6).toUpperCase()}`;let l=new Date().toISOString().slice(0,10),r="cash"===e.type;return{...a,loyalty:{...a.loyalty,points:a.loyalty.points-e.cost,history:[{id:`lh${Date.now()}`,date:l,type:"redeem",points:-e.cost,note:`Redeemed ${e.title}`},...a.loyalty.history],redeemed:[{id:`rd${Date.now()}`,title:e.title,code:t,date:l,cost:e.cost},...a.loyalty.redeemed]},wallet:r?{balance:+(a.wallet.balance+e.value).toFixed(2),txns:[{id:`w${Date.now()}`,date:l,type:"credit",amount:e.value,note:`Reward: ${e.title}`},...a.wallet.txns]}:a.wallet}}),t},[]),x=(0,r.useCallback)(e=>m(t=>({...t,loyalty:{...t.loyalty,referrals:[{name:e.trim(),status:"pending",date:new Date().toISOString().slice(0,10)},...t.loyalty.referrals]}})),[]),C=(0,r.useCallback)(e=>m(t=>{let a=new Date().toISOString().slice(0,10);return{...t,loyalty:{...t.loyalty,freeMedClaimed:t.loyalty.freeMedClaimed+1,history:[{id:`lh${Date.now()}`,date:a,type:"redeem",points:0,note:`Claimed free medication (up to $${e})`},...t.loyalty.history]},wallet:{balance:+(t.wallet.balance+e).toFixed(2),txns:[{id:`w${Date.now()}`,date:a,type:"credit",amount:e,note:"Refer-4-friends free medication reward"},...t.wallet.txns]}}}),[]),b=(0,r.useCallback)(e=>m(t=>{let a=t.addresses.some(t=>t.id===e.id)?t.addresses.map(t=>t.id===e.id?e:t):[...t.addresses,e];return e.default&&(a=a.map(t=>({...t,default:t.id===e.id}))),{...t,addresses:a}}),[]),k=(0,r.useCallback)(e=>m(t=>({...t,addresses:t.addresses.filter(t=>t.id!==e)})),[]),I=(0,r.useCallback)(e=>m(t=>{let a=t.cards.some(t=>t.id===e.id)?t.cards.map(t=>
1t.id===e.id?e:t):[...t.cards,e];return e.default&&(a=a.map(t=>({...t,default:t.id===e.id}))),{...t,cards:a}}),[]),O=(0,r.useCallback)(e=>m(t=>({...t,cards:t.cards.filter(t=>t.id!==e)})),[]),D=(0,r.useCallback)(e=>m(t=>({...t,refills:t.refills.map(t=>t.id===e.id?e:t)})),[]),$=(0,r.useCallback)(e=>{d({type:"refund",orderId:e.orderId,amount:e.amount,reason:e.reason}),m(t=>({...t,refunds:[{...e,status:"requested"},...t.refunds]}))},[]),v=(0,r.useCallback)(e=>{d({type:"exchange",orderId:e.orderId,item:e.item,reason:e.reason}),m(t=>({...t,exchanges:[e,...t.exchanges]}))},[]),E=(0,r.useCallback)(e=>{m(t=>{let a=t.orders.find(t=>t.id===e);if(!a)return t;try{let e=JSON.parse(localStorage.getItem("expressrxonline_cart")||"[]");a.items.filter(e=>!/shipping/i.test(e.name)).forEach(t=>{let a=t.name.toLowerCase().replace(/[^a-z0-9]+/g,"-"),l=e.find(e=>e.slug===a);l?l.qty+=t.qty:e.push({slug:a,name:t.name,price:t.price,qty:t.qty})}),localStorage.setItem("expressrxonline_cart",JSON.stringify(e))}catch{}return t})},[]),N=(0,r.useCallback)((e,t)=>{d({type:"ticket",subject:e,message:t}),m(a=>({...a,tickets:[{id:`t${Date.now()}`,subject:e,date:new Date().toISOString().slice(0,10),status:"open",replies:[{from:"you",text:t,date:new Date().toISOString().slice(0,10)}]},...a.tickets]}))},[]),_=(0,r.useCallback)((e,t)=>m(a=>({...a,tickets:a.tickets.map(a=>a.id===e?{...a,status:"open",replies:[...a.replies,{from:"you",text:t,date:new Date().toISOString().slice(0,10)}]}:a)})),[]),J=(0,r.useCallback)(e=>{d({type:"chat",message:e}),m(t=>({...t,chat:[...t.chat,{id:`m${Date.now()}`,from:"customer",text:e,date:new Date().toISOString().slice(0,10)}]}))},[]),F=(0,r.useCallback)(e=>{let t=e.trim().toUpperCase();if(/^[A-Z]{2,4}GIFT-/.test(t))try{let e=JSON.parse(localStorage.getItem("expressrxonline_giftcards")||"[]"),a=e.findIndex(e=>e.code.toUpperCase()===t&&e.balance>0);if(a>=0){let l=+Number(e[a].balance).toFixed(2);return e[a].balance=0,localStorage.setItem("expressrxonline_giftcards",JSON.stringify(e)),m(e=>({...e,wallet:{balance:+(e.wallet.balance+l).toFixed(2),txns:[{id:`w${Date.now()}`,date:new Date().toISOString().slice(0,10),type:"credit",amount:l,note:`Gift card ${t}`},...e.wallet.txns]}})),`$${l.toFixed(2)} gift card added to your wallet.`}return"That gift card is invalid or has already been redeemed."}catch{return"Couldn't redeem that gift card â please try again."}let a="Invalid code.";return m(e=>{let l="WELCOME10"===t?10:5*("SAVE5"===t);return l?(a=`$${l.toFixed(2)} added to your wallet.`,{...e,wallet:{balance:e.wallet.balance+l,txns:[{id:`w${Date.now()}`,date:new Date().toISOString().slice(0,10),type:"credit",amount:l,note:`Redeemed ${t}`},...e.wallet.txns]}}):e}),a},[]),M=(0,r.useCallback)((e,t)=>m(a=>({...a,wallet:{balance:a.wallet.balance+e,txns:[{id:`w${Date.now()}`,date:new Date().toISOString().slice(0,10),type:"credit",amount:e,note:t},...a.wallet.txns]}})),[]),j=(0,r.useCallback)((e,t)=>{d({type:"wallet",amount:e,note:t}),m(a=>({...a,wallet:{...a.wallet,txns:[{id:`w${Date.now()}`,date:new Date().toISOString().slice(0,10),type:"pending",amount:e,note:t},...a.wallet.txns]}}))},[]),q=(0,r.useCallback)(()=>m(s()),[]);return(0,l.jsx)(n.Provider,{value:{authed:a,login:w,logout:y,data:u,setProfile:g,setSecurity:h,redeemReward:S,addReferral:x,claimFreeMed:C,saveAddress:b,deleteAddress:k,saveCard:I,deleteCard:O,setRefill:D,requestRefund:$,requestExchange:v,reorder:E,createTicket:N,replyTicket:_,sendChat:J,redeemWallet:F,addWalletFunds:M,requestWalletFunds:j,resetAll:q},children:t})}function u(){let e=(0,r.useContext)(n);if(!e)throw Error("useCustomer must be used within CustomerProvider");return e}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.