1var J=Object.defineProperty,Q=Object.defineProperties;var U=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var Y=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var L=(r,l,d)=>l in r?J(r,l,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[l]=d,I=(r,l)=>{for(var d in l||(l={}))Y.call(l,d)&&L(r,d,l[d]);if(O)for(var d of O(l))z.call(l,d)&&L(r,d,l[d]);return r},F=(r,l)=>Q(r,U(l));var P=(r,l,d)=>new Promise((C,b)=>{var u=m=>{try{f(d.next(m))}catch(y){b(y)}},S=m=>{try{f(d.throw(m))}catch(y){b(y)}},f=m=>m.done?C(m.value):Promise.resolve(m.value).then(u,S);f((d=d.apply(r,l)).next())});import{c as V,c5 as Z,u as G,r as h,j as e,Q as D,R as K,B as X,L as M,s as W,bz as ee,aQ as c,an as n,a7 as se,bw as ae,c7 as re,c8 as te,a2 as de,t as g,bF as le,ab as ie}from"./index-COtfmzs3.js";import{C as N,a as v,b as w,c as k}from"./card-DmFvQBRw.js";import{S as ce}from"./sparkles-quRC4bwK.js";import{C as ne}from"./credit-card-B_Ivl4kp.js";/** 2 * @license lucide-react v0.487.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const oe=[["path",{d:"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z",key:"q3az6g"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 17.5v-11",key:"1jc1ny"}]],me=V("receipt",oe);function be(){const{cartItems:r,cartCount:l,clearCart:d}=Z(),C=G(),[b,u]=h.useState(!1),[S,f]=h.useState(!1),[m,y]=h.useState(""),[t,R]=h.useState(()=>{const s=localStorage.getItem("checkout_address");if(s)try{return JSON.parse(s)}catch(x){console.error("Error parsing saved address",x)}return{customerInfo:{name:"",email:"",mobile:""},shippingAddress:{addressLine:"",city:"",state:"",pincode:"",country:"India"},billingAddress:{addressLine:"",city:"",state:"",pincode:"",country:"India"}}});h.useEffect(()=>{localStorage.setItem("checkout_address",JSON.stringify(t))},[t]);const[p,H]=h.useState(!0),q=localStorage.getItem("user"),E=q?JSON.parse(q):null,A=r.reduce((s,x)=>s+parseInt(x.price)*x.quantity,0),i=(s,x,a)=>{R(o=>F(I({},o),{[s]:F(I({},o[s]),{[x]:a})}))},$=s=>P(null,null,function*(){if(s.preventDefault(),r.length===0){g.error("Your cart is empty");return}u(!0);for(const a of r)try{const{ok:o,data:_}=yield le.getProduct(a.productId);if(o&&_.success){const j=_.data;if(j.isVariable&&a.variantId){const B=j.variants.find(T=>T._id===a.variantId);if(B&&(B.quantity||0)<a.quantity){g.error(`Only ${B.quantity||0} units of ${a.title} (${a.variantName}) available`),u(!1);return}}else if((j.quantity||0)<a.quantity){g.error(`Only ${j.quantity||0} units of ${a.title} available`),u(!1);return}}}catch(o){console.error("Error validating stock:",o)}const x={user:E?E._id||E.id:void 0,items:r.map(a=>({productId:a.productId,productType:a.type||"book",title:a.title,price:parseInt(a.price),quantity:a.quantity,image:a.image,variantId:a.variantId,variantName:a.variantName})),customerInfo:t.customerInfo,shippingAddress:t.shippingAddress,billingAddress:p?t.shippingAddress:t.billingAddress,totalAmount:A,paymentMethod:"COD",paymentId:"COD-"+Math.random().toString(36).substring(7).toUpperCase()};try{const{ok:a,data:o}=yield ie.createOrder(x);a&&o.success?(g.success("Order placed successfully!"),y(o.data._id),f(!0),d()):g.error(o.message||"Failed to place order")}catch(a){g.error("An error occurred during checkout")}finally{u(!1)}});return S?e.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center p-4",children:e.jsxs(D.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},className:"max-w-md w-full bg-white rounded-3xl shadow-xl p-8 text-center space-y-6",children:[e.jsx("div",{className:"w-20 h-20 bg-green-100 text-green-600 rounded-full flex items-center justify-center mx-auto",children:e.jsx(K,{className:"w-10 h-10"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-black text-gray-900",children:"Order Confirmed!"}),e.jsxs("p",{className:"text-gray-500 mt-2",children:["Your order ORD-",m.toString().slice(-6).toUpperCase()," has been placed successfully. A confirmation email has been sent to ",t.customerInfo.email,"."]})]}),e.jsx("div",{className:"pt-4",children:e.jsx(X,{onClick:()=>C("/"),className:"w-full bg-[#373081] hover:bg-[#2a2463] text-white rounded-xl py-6 font-bold",children:"Return to Home"})})]})}):e.jsx("div",{className:"min-h-screen bg-gray-50 pb-20 pt-10",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(M,{to:"/",className:"text-gray-500 hover:text-[#E94B64] transition-colors flex items-center gap-2 text-sm font-medium mb-2",children:[e.jsx(W,{className:"w-4 h-4"}),"Back to Store"]}),e.jsxs("h1",{className:"text-4xl font-black text-gray-900 tracking-tight flex items-center gap-3",children:["Checkout ",e.jsx(ce,{className:"w-8 h-8 text-[#E94B64]"})]})]}),e.jsxs("div",{className:"hidden md:flex items-center gap-4 bg-white p-2 rounded-2xl border border-gray-100 shadow-sm",children:[e.jsx("div",{className:"flex -sp
6ace-x-2",children:[1,2,3].map(s=>e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-white bg-[#F3F4F6] flex items-center justify-center text-[10px] font-bold text-gray-400",children:s},s))}),e.jsx("span",{className:"text-xs font-bold text-gray-400 uppercase tracking-widest px-2",children:"Secure Checkout"})]})]}),e.jsxs("form",{onSubmit:$,className:"grid grid-cols-1 lg:grid-cols-12 gap-10",children:[e.jsxs("div",{className:"lg:col-span-8 space-y-8",children:[e.jsxs(N,{className:"rounded-3xl border-none shadow-sm overflow-hidden",children:[e.jsx(v,{className:"bg-white border-b border-gray-50 p-6",children:e.jsxs(w,{className:"flex items-center gap-3 text-xl font-black",children:[e.jsx("div",{className:"w-10 h-10 bg-blue-50 text-blue-600 rounded-xl flex items-center justify-center",children:e.jsx(ee,{className:"w-5 h-5"})}),"Customer Details"]})}),e.jsx(k,{className:"p-6",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"name",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"Full Name"}),e.jsx(n,{id:"name",required:!0,placeholder:"Enter your full name",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.customerInfo.name,onChange:s=>i("customerInfo","name",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"email",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"Email Address"}),e.jsx(n,{id:"email",type:"email",required:!0,placeholder:"[email protected]",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.customerInfo.email,onChange:s=>i("customerInfo","email",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"mobile",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"Mobile Number"}),e.jsx(n,{id:"mobile",required:!0,placeholder:"+91 XXXXX XXXXX",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.customerInfo.mobile,onChange:s=>i("customerInfo","mobile",s.target.value)})]})]})})]}),e.jsxs(N,{className:"rounded-3xl border-none shadow-sm overflow-hidden",children:[e.jsx(v,{className:"bg-white border-b border-gray-50 p-6",children:e.jsxs(w,{className:"flex items-center gap-3 text-xl font-black",children:[e.jsx("div",{className:"w-10 h-10 bg-green-50 text-green-600 rounded-xl flex items-center justify-center",children:e.jsx(se,{className:"w-5 h-5"})}),"Shipping Address"]})}),e.jsx(k,{className:"p-6",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"md:col-span-2 space-y-2",children:[e.jsx(c,{htmlFor:"s_address",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"Full Address"}),e.jsx(n,{id:"s_address",required:!0,placeholder:"House No, Street, Landmark",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.shippingAddress.addressLine,onChange:s=>i("shippingAddress","addressLine",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"s_city",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"City"}),e.jsx(n,{id:"s_city",required:!0,placeholder:"City",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.shippingAddress.city,onChange:s=>i("shippingAddress","city",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"s_state",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"State"}),e.jsx(n,{id:"s_state",required:!0,placeholder:"State",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.shippingAddress.state,onChange:s=>i("shippingAddress","state",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"s_pincode",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"Pincode"}),e.jsx(n,{id:"s_pincode",required:!0,placeholder:"6-digit Pincode",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#
6E94B64] py-6",value:t.shippingAddress.pincode,onChange:s=>i("shippingAddress","pincode",s.target.value)})]})]})})]}),e.jsxs(N,{className:"rounded-3xl border-none shadow-sm overflow-hidden",children:[e.jsx(v,{className:"bg-white border-b border-gray-50 p-6",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs(w,{className:"flex items-center gap-3 text-xl font-black",children:[e.jsx("div",{className:"w-10 h-10 bg-purple-50 text-purple-600 rounded-xl flex items-center justify-center",children:e.jsx(me,{className:"w-5 h-5"})}),"Billing Address"]}),e.jsxs("div",{className:"flex items-center space-x-2 bg-gray-50 px-4 py-2 rounded-xl border border-gray-100",children:[e.jsx(ae,{id:"sameAsShipping",checked:p,onCheckedChange:s=>H(s),className:"rounded-md border-[#E94B64] data-[state=checked]:bg-[#E94B64]"}),e.jsx("label",{htmlFor:"sameAsShipping",className:"text-xs font-bold text-gray-600 uppercase tracking-wider cursor-pointer",children:"Same as Shipping"})]})]})}),e.jsx(re,{children:!p&&e.jsx(D.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:e.jsx(k,{className:"p-6",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"md:col-span-2 space-y-2",children:[e.jsx(c,{htmlFor:"b_address",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"Full Address"}),e.jsx(n,{id:"b_address",required:!p,placeholder:"House No, Street, Landmark",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.billingAddress.addressLine,onChange:s=>i("billingAddress","addressLine",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"b_city",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"City"}),e.jsx(n,{id:"b_city",required:!p,placeholder:"City",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.billingAddress.city,onChange:s=>i("billingAddress","city",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"b_state",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"State"}),e.jsx(n,{id:"b_state",required:!p,placeholder:"State",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.billingAddress.state,onChange:s=>i("billingAddress","state",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{htmlFor:"b_pincode",className:"text-sm font-bold text-gray-700 uppercase tracking-wider",children:"Pincode"}),e.jsx(n,{id:"b_pincode",required:!p,placeholder:"6-digit Pincode",className:"rounded-xl border-gray-200 focus:ring-[#E94B64] focus:border-[#E94B64] py-6",value:t.billingAddress.pincode,onChange:s=>i("billingAddress","pincode",s.target.value)})]})]})})})})]})]}),e.jsx("div",{className:"lg:col-span-4 space-y-6",children:e.jsxs(N,{className:"rounded-3xl border-none shadow-sm overflow-hidden sticky top-24",children:[e.jsx(v,{className:"bg-white border-b border-gray-50 p-6",children:e.jsxs(w,{className:"flex items-center gap-3 text-xl font-black",children:[e.jsx(te,{className:"w-5 h-5 text-[#E94B64]"}),"Order Summary"]})}),e.jsxs(k,{className:"p-6",children:[e.jsx("div",{className:"space-y-4 max-h-[300px] overflow-y-auto pr-2 scrollbar-hide",children:r.map(s=>e.jsxs("div",{className:"flex gap-4 group",children:[e.jsx("div",{className:"w-16 h-16 bg-gray-50 rounded-xl flex-shrink-0 p-2 border border-gray-100",children:e.jsx("img",{src:s.image,alt:s.title,className:"w-full h-full object-contain mix-blend-multiply"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-xs font-bold text-gray-900 line-clamp-1",children:s.title}),e.jsxs("div",{className:"flex items-center justify-between mt-1",children:[e.jsxs("span",{className:"text-[10px] font-bold text-gray-400",children:["Qty: ",s.quantity]}),e.jsxs("span",{className:"text-sm font-black text-[#E94B64]",children:["â¹",parseInt(s.price)*s.quantity]})]})]})]},s.id))}),e.jsxs("div",{className:"mt-6 pt-6 border-t border-gray-100 space-y-3",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500 font-medium",children:"Subtotal"}),e.jsxs("span",{className:"text-gray-900 font-bold",children:["â¹",A]}
6)]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-500 font-medium",children:"Shipping"}),e.jsx("span",{className:"text-green-600 font-bold",children:"FREE"})]}),e.jsxs("div",{className:"flex justify-between items-center pt-3 border-t border-gray-50",children:[e.jsx("span",{className:"text-lg font-black text-gray-900",children:"Total"}),e.jsxs("span",{className:"text-2xl font-black text-[#E94B64]",children:["â¹",A]})]})]}),e.jsxs("div",{className:"mt-8 space-y-4",children:[e.jsxs("div",{className:"p-4 bg-orange-50 border border-orange-100 rounded-2xl flex items-start gap-3",children:[e.jsx(ne,{className:"w-5 h-5 text-orange-600 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black text-orange-900 uppercase tracking-wider",children:"Payment Method"}),e.jsx("p",{className:"text-xs text-orange-700 font-medium mt-1",children:"Cash on Delivery (Standard)"})]})]}),e.jsx(X,{type:"submit",disabled:b||r.length===0,className:"w-full bg-[#E94B64] hover:bg-[#D43F57] text-white rounded-2xl py-8 text-lg font-black shadow-xl shadow-[#E94B64]/20 transition-all group",children:b?"Placing Order...":e.jsxs(e.Fragment,{children:["Place Your Order",e.jsx(de,{className:"w-5 h-5 ml-2 group-hover:translate-x-1 transition-transform"})]})}),e.jsxs("p",{className:"text-[10px] text-gray-400 text-center font-medium",children:["By placing an order, you agree to our ",e.jsx(M,{to:"/terms",className:"text-[#E94B64] underline",children:"Terms of Service"})]})]})]})]})})]})]})})}export{be as CheckoutPage};
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.