import{a as ye}from"/build/_shared/chunk-7R6LDAXZ.js";import{a as ae}from"/build/_shared/chunk-AHLEFWWF.js";import{c as D}from"/build/_shared/chunk-QEDLJRLE.js";import{a as te}from"/build/_shared/chunk-V4GBZ5BH.js";import{a as C}from"/build/_shared/chunk-BXGM2W2G.js";import{b as Z,c as ee,e as J}from"/build/_shared/chunk-RDYUL7YF.js";import{b as fe,c as be}from"/build/_shared/chunk-IQDEUVFL.js";import{a as ue,b as q}from"/build/_shared/chunk-3RWUHEQO.js";import{d as S}from"/build/_shared/chunk-G5WX4PPA.js";var l=S(ue());var se=S(ue()),I=S(ye());var m=S(q()),Be={iconStyle:"solid",style:{base:{iconColor:"black",color:"black",fontWeight:500,fontSize:"16px",border:"1px solid #000",padding:"10px"},invalid:{iconColor:"red",color:"red"}}},Re=({createCustomerId:_,savedCard:h,handlePurchaseCard:W,addNewCreditCard:Q,addCreditModal:f,showStripeCard:x,stripePayments:re,updateCard:j,validateForm:p})=>{let V=(0,I.useStripe)(),A=(0,I.useElements)(),{stripeLoader:z,setStripeLoader:k,setWalletPurchase:O,setWalletPayment:$,setCardElements:L}=D(),[M,y]=(0,se.useState)(""),[Y,g]=(0,se.useState)(!1),{setUpdateModal:i}=D(),G=()=>{let b=A.getElement(I.CardElement);b&&b.clear()},c=async b=>{if(g(!0),b.preventDefault(),!p()&&!f&&!j&&!x||f&&h&&h.length===0&&!p())return;let{error:F,paymentMethod:w}=await V.createPaymentMethod({type:"card",card:A.getElement(I.CardElement)});if(F)y(F.message),console.error(F.message),k(!1),g(!1);else try{let{id:v}=w;v&&h&&h.length===0&&!f&&!j?_(v):x?Q(v):W(v),i(!1),g(!1)}catch(v){k(!1),g(!1),console.error(v,"stripe error")}},T=fe();return(0,m.jsxs)("form",{onSubmit:c,className:"w-full",children:[(0,m.jsx)("div",{className:"border border-solid border-black",children:(0,m.jsx)(I.CardElement,{onReady:b=>L(b),onChange:()=>y(""),options:Be,className:"my-5 mx-2 sm:mx-5"})}),M&&(0,m.jsx)("div",{className:"text-red-700 font-karla text-[14px] mt-2",children:M}),(0,m.jsxs)("div",{className:`md:flex grid ${h?"md:justify-center":"md:justify-between"}  justify-normal  w-full gap-[10px] items-center my-[16px]`,children:[!h&&(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(J,{text:"Previous",onClickFunction:()=>{window.scrollTo({top:0,behavior:"smooth"}),O(!0),$(!1)},backArrow:!0,className:"!bg-[#1b5299] w-full   !h-[55px]  !py-[16px] !px-[30px] uppercase md:text-[16px] text-[12px]"})}),(0,m.jsx)("div",{onClick:()=>{k(!0)},className:"flex items-center justify-center w-full max-w-[300px] !mt-0 ",children:(0,m.jsx)("button",{type:"submit",className:"!bg-[#EF6E6E] text-white font-bold dsgsdgsgsd uppercase md:text-[16px] text-[12px] flex justify-center items-center h-[55px]  w-full !rounded-0 !py-[16px]  transition duration-400 !px-[30px] max-w-[300px] ",children:(T.pathname==="/pages/simply-noted-plans"||T.pathname==="/account")&&!f&&!x&&!j?"Complete Purchase":!f&&!x&&j?"Update Card":(x||f)&&(Y?"Adding Card...":"Add Card")})})]})]})},xe=Re;var ge=S(ye());var e=S(q()),qe=({StripeKey:_,finalPrice:h,setWalletPurchase:W,setWalletPayment:Q,amount:f,selectedPlan:x,packageProduct:re,subscriptionProduct:j,subscriptionTitle:p,subscriptionPriceId:V,stripePayments:A})=>{let z=Stripe(_),[k,O]=(0,l.useState)(!0),[$,L]=(0,l.useState)(!0),[M,y]=(0,l.useState)(!1),[Y,g]=(0,l.useState)(!1),[i,G]=(0,l.useState)({}),[c,T]=(0,l.useState)([]),[b,F]=(0,l.useState)(!1),[w,v]=(0,l.useState)(""),[N,U]=(0,l.useState)(""),[n,he]=(0,l.useState)({}),{setCartCountVal:we,setIsCartUpdated:ve}=D(),{setActiveTab:Ne,loaderTitle:oe,setLoaderTitle:Se,setStripeLoader:Ce,setAccountTabName:Ie,setIsStripeDataUpdated:ke}=D(),H,K,ne,Ee=re?.replace(/[^0-9]/g,""),Pe=j?.replace(/[^0-9]/g,""),je=()=>{O(!k),L(!1)},Ae=()=>{L(!$),O(!1)},Fe=be(),[s,de]=(0,l.useState)({name:"",email:"",address:{line1:"",line2:"",city:"",state:"",country:"USA"},paymentMethodId:""});async function De(t){try{y(!0);let r=await(await fetch(`${C}/stripe/create-customer?customerId=${w}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name||"",email:s.email||"","address[line1]":s.address.line1||"","address[line2]":s.address.line2||"","address[city]":s.address.city||"","address[state]":s.address.state||"","address[country]":s.address.country||"",paymentMethodId:t||""})})).json();r&&(r.paymentMethodId=[r.paymentMethodId],U(t),p==="Free"?R(p,r,!0,t):await me(r))}catch{y(!1)}}async function Oe(t){try{y(!0);let r=await(await fetch(`${C}/stripe/add-new-payment-method?customerId=${w}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentMethodId:t})})).json(),d=localStorage.getItem("customerId");await ie(d),setTimeout(()=>{y(!1),F(!b)},[500])}catch{y(!1)}}async function ie(t){try{let r=await(await fetch(`${C}/stripe/customer-data?customerId=${t}`)).json();r&&(he(r.customer),T(r.payments))}catch{}}(0,l.useEffect)(()=>{H=localStorage.getItem("customerId"),K=localStorage.getItem("SNFullName"),ne=localStorage.getItem("SnEmail");let t=localStorage.getItem("firstName"),a=localStorage.getItem("lastName");v(H),ie(H),s.name=K||t+" "+a,s.email=ne},[]),(0,l.useEffect)(()=>{s.address.line1=n&&n.address?.line1,s.address.line2=n&&n.address?.line2,s.address.state=n&&n.address?.state,s.address.city=n&&n.address?.city},[n]);let E=t=>{let{name:a,value:r}=t.target;a.startsWith("address.")?de(d=>({...d,address:{...d.address,[a.substring(8)]:r},paymentMethodId:N||""})):de(d=>({...d,[a]:r})),G(d=>({...d,[a]:""}))},le=()=>{let t=!0,a={};s.name.trim()||(a.name="Name is required",t=!1);let r=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;if((!s.email.trim()||!r.test(s.email))&&(a.email="Email is required and must be valid",t=!1),s.address?.line1||(a.addressLine1="Address is required",t=!1),s.address.city||(a.city="City is required",t=!1),s.address.country||(a.country="Country is required",t=!1),s.address.state||(a.state="State is required",t=!1),G(a),!t){let d=Object.keys(a)[0],o=document.getElementById(d);o&&o.focus()}return t||(O(!0),Ce(!1)),t},ce=ae?.countries?.find(t=>t.country===s.address.country);function $e(t){let a=/(\d*\.?\d+)% Discount/,r=/([\d,]+) Standard Cards/,d=t?.match(a),o=d?parseFloat(d[1]):null,P=t?.match(r),u=null;P&&(u=parseInt(P[1]?.replace(/,/g,""),10));let Te=o!==null?o.toString():null,Ue=u!==null?u.toString():null;return{discount:Te,cards:Ue}}let{discount:B,cards:X}=$e(x),me=async t=>{try{let a={subscriptionPriceId:V,subscriptionName:p},r=`${C}/stripe/create-subscription?customerId=${w}`,d=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok)throw new Error("Failed to create subscription");let o=await d.json();if(o.redirectUrl){let P=await z.confirmCardPayment(o.client_secret);P?.error?g(!1):(o.status=P.paymentIntent.status,R(o,t))}else R(o,t)}catch(a){g(!1),y(!1),console.error("Error:",a)}};function Le(){let t=`${C}/api/storefront/cart-items/delete?customerId=${w}`;fetch(t,{method:"POST"}).then(a=>{if(!a.ok)throw new Error("Network response was not ok");return a.json()}).then(a=>{a.result.success&&(we(0),ve(!0))}).catch(a=>{console.error("Error deleting cart item:",a)})}let pe=async(t,a)=>{let r={paymentMethodId:N||a?.paymentMethodId[0],packageDiscount:Number(B),packageQuantity:Number(X),packagePrice:f,description:x,packageProduct:Ee,subscriptionName:p,subscriptionProduct:Pe,isSubscriptionOnly:!0,isAutorenew:!0},d=`${C}/stripe/package-payment?customerId=${w}`;await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}).then(o=>{if(!o.ok)throw new Error("Network response was not ok");return o.json()}).then(o=>{localStorage.setItem("packageDiscount",JSON.stringify(B)),localStorage.setItem("selectedPlan",x),localStorage.setItem("amount",f),o&&(Le(),Se("Payment completed successfully... "),setTimeout(()=>{Fe("/account",{state:{activeTab:4,accountTabName:"Manage Plans"}}),g(!1),ke(!0)},2e3),setTimeout(()=>{Ne(4),Ie("Manage Plans")},2200))}).catch(o=>{console.error("Error:",o)})},R=(t,a,r,d)=>{let o;p==="Free"?o={subscriptionName:p,packageDiscount:String(B),packageQuantity:String(X),packagePrice:String(f),isAutorenew:!0,paymentOnly:!0}:o={subscriptionId:t.subscriptionId,subscriptionName:p,packageDiscount:String(B),paymentOnly:!1,packageQuantity:String(X),packagePrice:String(f),isAutorenew:!0,subscriptionStartDate:t.subscriptionStartDate,subscriptionEndDate:t.subscriptionEndDate,subscriptionStatus:t.status==="succeeded"?"active":t.status,isSubscriptionOnly:!0};let P=`${C}/stripe/payment-save?customerId=${w}`;fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)}).then(u=>{if(console.log("response",u),!u.ok)throw new Error("Network response was not ok");return u.json()}).then(u=>{console.log("data",u),pe(u,a)}).catch(u=>{console.error("Error:",u)})},Me=()=>{c&&c.length>0&&U(c[0].paymentId)};return(0,l.useEffect)(()=>{Me()},[c]),(0,e.jsxs)("div",{className:"w-full  relative max-w-[1440px] mt-[24px] mx-auto px-[24px]",children:[Y&&(0,e.jsx)("div",{className:"fixed top-0 left-0 w-full h-full bg-black opacity-80 flex justify-center items-center z-50",children:(0,e.jsx)(te,{textColor:"text-white",title:oe||"Processing your payment securely. Please wait a moment."})}),(0,e.jsxs)("div",{className:`w-full
          p-[20px]  border border-solid border-black mt-[14px] max-w-[640px] mx-auto`,children:[(0,e.jsxs)("div",{className:"flex items-center justify-between cursor-pointer",onClick:je,children:[(0,e.jsx)("span",{className:"font-bold  md:text-[20px] text-[17px] text-[#001a5f]",children:"Billing Address"}),(0,e.jsx)("span",{className:"",children:k||i.length>0?(0,e.jsx)(ee,{}):(0,e.jsx)(Z,{})})]}),(0,e.jsx)("div",{className:`overflow-hidden
         ${k||i.length>0?"max-h-[800px] transition-max-height ":"max-h-0"}
        `,children:(0,e.jsx)("div",{className:"rounded",children:(0,e.jsxs)("div",{className:"w-full max-w-[650px]  mx-auto mt-3",children:[(0,e.jsxs)("div",{className:"grid-rows-2 lg:flex grid gap-3",children:[(0,e.jsxs)("div",{className:"w-full",children:[(0,e.jsx)("label",{className:"font-bold",htmlFor:"",children:"Full Name"}),(0,e.jsx)("input",{type:"text",id:"firstName",name:"name",disabled:!0,value:s.name,onChange:t=>E(t),className:"mt-2 border rounded-md border-solid border-black p-3 w-[100%]"}),i.name&&(0,e.jsx)("p",{className:"text-red-500 mt-[2px] text-[14px] font-semibold italic",children:i.name})]}),(0,e.jsxs)("div",{className:"w-full",children:[(0,e.jsx)("label",{className:"font-bold",htmlFor:"",children:"Email"}),(0,e.jsx)("input",{id:"email",disabled:!0,name:"email",type:"text",value:s.email,onChange:t=>E(t),className:"mt-2 border  rounded-md border-solid border-black p-3 w-[100%]"}),i.email&&(0,e.jsx)("p",{className:"text-red-500 mt-[2px] text-[14px] font-semibold italic",children:i.email})]})]}),(0,e.jsxs)("div",{className:"mt-2",children:[(0,e.jsx)("label",{htmlFor:"",className:"font-bold",children:"Address"}),(0,e.jsx)("input",{id:"address1",name:"address.line1",type:"text",placeholder:"Address",required:!0,disabled:n&&n?.address?.line1,value:s.address.line1,onChange:t=>{i.addressLine1="",E(t)},className:"mt-2 border rounded-md border-solid border-black p-3 w-[100%]"}),i.addressLine1&&(0,e.jsx)("p",{className:"text-red-500  mt-[2px] text-[14px] font-semibold italic",children:i.addressLine1})]}),(0,e.jsxs)("div",{className:"mt-2",children:[(0,e.jsx)("label",{htmlFor:"",className:"font-bold",children:"Apartment,suite,etc"}),(0,e.jsx)("input",{id:"address2",name:"address.line2",type:"text",disabled:n&&n.address?.line2,placeholder:"Address 2",value:s.address.line2,onChange:t=>E(t),className:"mt-2 border rounded-md border-solid border-black p-3 w-[100%]"})]}),(0,e.jsxs)("div",{className:"mt-2",children:[(0,e.jsx)("label",{htmlFor:"",className:"font-bold",children:"City"}),(0,e.jsx)("input",{id:"city",name:"address.city",type:"text",required:!0,placeholder:"City",disabled:n&&n.address?.city,value:s.address.city,onChange:t=>{i.city="",E(t)},className:"mt-2 border rounded-md border-solid border-black p-3 w-[100%]"}),i.city&&(0,e.jsx)("p",{className:"text-red-500 mt-[2px] text-[14px] font-semibold italic",children:i.city})]}),(0,e.jsxs)("div",{className:"grid-rows-2 mt-2 lg:flex grid gap-3",children:[(0,e.jsxs)("div",{className:"w-full",children:[(0,e.jsx)("label",{className:"block text-gray-700 font-bold mb-2",htmlFor:"country",children:"Country"}),(0,e.jsx)("select",{onChange:t=>E(t),value:s.address.country,itemID:"country",name:"address.country",disabled:n&&n.address?.country,id:"country",className:"appearance-none rounded-md border h-[46px] w-full  border-solid border-black p-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline",children:ae.countries.map(t=>(0,e.jsx)("option",{value:t.country,children:t.country},t.country))})]}),(0,e.jsxs)("div",{className:"w-full",children:[(0,e.jsx)("label",{className:"block text-gray-700  font-bold mb-2",htmlFor:"state",children:"State"}),(0,e.jsxs)("select",{onChange:t=>{i.state="",E(t)},disabled:n&&n.address?.state,value:s.address.state,name:"address.state",className:`appearance-none rounded-md border h-[46px]  w-full  border-solid border-black p-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline  ${i.state?"border-red-500":""}`,id:"state",children:[(0,e.jsx)("option",{value:"",children:"Select a state"}),ce&&ce.states.map(t=>(0,e.jsx)("option",{value:t,children:t},t))]}),i.state&&(0,e.jsx)("p",{className:"text-red-500 mt-[2px] text-[14px] font-semibold italic",children:i.state})]})]})]})})}),(0,e.jsx)("div",{className:"border-b border-solid border-black mt-[12px]"}),(0,e.jsxs)("div",{className:"mt-4  rounded",children:[(0,e.jsxs)("div",{className:"flex items-center border-b border-solid border-black pb-[15px] justify-between mb-3  cursor-pointer",onClick:Ae,children:[(0,e.jsx)("span",{className:"font-bold md:text-[20px] text-[17px] text-[#001a5f]",children:"Credit Card Information"}),(0,e.jsx)("span",{className:"",children:$?(0,e.jsx)(ee,{}):(0,e.jsx)(Z,{})})]}),(0,e.jsx)("div",{className:`overflow-hidden
            ${$?"max-h-[800px] transition-max-height":"max-h-0"}
          `,children:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(ge.Elements,{stripe:z,children:[c&&c.map((t,a)=>(0,e.jsx)("label",{htmlFor:"item-index-"+a,className:N===t.paymentId?"bg-[#ffdada] cursor-pointer border border-solid border-[#dbdbdb] rounded-md p-[1rem] mt-1 mb-2 flex justify-between ":"bg-[#f5fffa]  border border-solid border-[#dbdbdb] rounded-md p-[1rem] mt-1 mb-2 flex justify-between  cursor-pointer",children:(0,e.jsxs)("div",{className:"flex justify-start items-center text-[14px] font-bold ",children:[(0,e.jsx)("input",{id:"item-index-"+a,type:"radio",onChange:()=>U(t.paymentId),name:"action",checked:N===t.paymentId,className:"mr-2"}),(0,e.jsxs)("span",{className:"mr-[17rem] tracking-wide",children:["**********",t.cardLast4Number]}),(0,e.jsxs)("span",{children:[t.cardExpMonth,"/",t.cardExpYear]})]})},a)),c&&(0,e.jsx)("div",{className:"savedCard flex items-start justify-between mb-2 ",children:(0,e.jsx)("div",{children:(0,e.jsx)("button",{className:"bg-[#1b5299] w-[200px] text-[#fff] p-2 rounded",onClick:()=>{F(!b)},children:"Add New Card"})})}),M&&(0,e.jsx)(te,{title:"Adding Card..",color:"#ef6e6e"}),(!c||b)&&(0,e.jsx)("div",{className:"p-4",children:(0,e.jsx)(xe,{addNewCreditCard:Oe,setPaymentMethodId:U,createCustomerId:De,savedCard:c&&c.length>0?c:[],paymentPurchase:pe,validateForm:le,stripePayments:A,setloader:y,showStripeCard:b})})]}),(0,e.jsxs)("div",{className:"flex justify-between font-bold   text-[#001a5f] border-y border-[#cfcfcf] p-[10px] items-center w-full",children:[(0,e.jsx)("div",{children:"Total"}),(0,e.jsxs)("div",{children:["$",h]})]}),A&&A.length>0&&(0,e.jsxs)("div",{className:"md:flex grid md:justify-between justify-normal  w-full gap-[10px] items-center my-[16px]",children:[(0,e.jsx)(J,{text:"Previous",onClickFunction:()=>{window.scrollTo({top:0,behavior:"smooth"}),W(!0),Q(!1)},backArrow:!0,className:"!bg-[#EF6E6E] w-full !h-[55px]  !py-[16px] !px-[30px] uppercase md:text-[16px] text-[12px]"}),(0,e.jsx)("button",{type:"submit",onClick:()=>{le()&&(g(!0),p==="Free"?R(p,N,!0):me(N))},className:"!bg-[#1b5299] w-full !h-[55px] text-[white] font-bold rounded-lg  !px-[30px] uppercase md:text-[16px] text-[12px]",children:"Complete Purchase"})]})]})}),(0,e.jsxs)("div",{className:" border-2 text-[12px] mt-[15px] bg-white text-left p-[10px] border-solid border-[#324879]",children:[(0,e.jsx)("span",{children:"Custom cards and international postage may cost extra. You will receive the same level of discount on custom cards."}),(0,e.jsx)("br",{}),(0,e.jsx)("br",{}),(0,e.jsx)("span",{children:"By making this purchase, you agree to allow us to automatically renew your prepaid package when your balance drops below $100 and to renew your subscription at the end of your subscription period. Both your subscription and prepaid package can be changed later from your Account area."})]})]})]})]})},ot=qe;export{xe as a,ot as b};
