1import{r as n,X as ye,a as j,j as e,x as ae,A}from"./app-Mnt2IEGe.js";import{G as fe}from"./GuestLayout-BYnLiqFZ.js";import"./ApplicationLogo-JvKRx6b1.js";import"./x-B1Pn9Kmg.js";import"./message-circle-D4MbkUVn.js";import"./phone-DSAsYLtt.js";import"./chevron-down-BlAiga6f.js";import"./user-ad0RTXxq.js";import"./package-CT4joqbC.js";import"./map-pin-BuVEKMGp.js";import"./truck-CpGakV_6.js";import"./shopping-cart-DokKNEt4.js";import"./search-BeXkNHdv.js";import"./clock-Dnho5FNh.js";import"./shield-Da3uiB5y.js";import"./mail-Ce-sk81h.js";const h=F=>`â¹${Number(F).toFixed(2)}`,be=[{value:"razorpay",label:"Razorpay (Card / UPI / Netbanking)"}];function De({items:F=[],pricing:i={},gifts:re=[]}){var Z,ee,se;const[a,y]=n.useState({customer_name:"",customer_email:"",customer_phone:"",shipping_address:"",city:"",state:"",pincode:"",notes:"",payment_method:"razorpay",create_account:!1,password:"",password_confirmation:"",apply_wallet:!1}),[o,T]=n.useState({}),[$,N]=n.useState(""),[I,M]=n.useState(!1),w=Number((i==null?void 0:i.shipping)??0),le={...i,shipping:w,payable:(i==null?void 0:i.payable)??Number((i==null?void 0:i.total)??0)+w},[r,ne]=n.useState(le),[U,de]=n.useState(re),[f,oe]=n.useState((i==null?void 0:i.next_offer)||null),[R,q]=n.useState(!1),[_,B]=n.useState(""),[L,k]=n.useState(""),[V,P]=n.useState(""),[W,C]=n.useState(!1),{props:u}=ye(),[H,ie]=n.useState([]),[Q,X]=n.useState(null),g=!!((Z=u==null?void 0:u.auth)!=null&&Z.user),c=(u==null?void 0:u.wallet)||null,J=c?Number(c.balance??0):0;c&&Number(c.limit??0);const z=c?Number(c.max_applicable??0):0;c!=null&&c.mode,c&&Number(c.value??0);const K=Number((r==null?void 0:r.payable)??Number((r==null?void 0:r.total)??0)+w),S=n.useMemo(()=>{if(!a.apply_wallet||!c)return 0;const s=Math.min(J,z);return!Number.isFinite(s)||s<=0?0:Number(s.toFixed(2))},[a.apply_wallet,c,J,z]),ce=n.useMemo(()=>{const s=K-S;return Number.isFinite(s)?Number(Math.max(0,s).toFixed(2)):0},[K,S]),D=s=>{s&&(de(s.gifts||[]),oe(s.next_offer||null),ne({...s,shipping:w,payable:Number(s.total||0)+w}))},E=r==null?void 0:r.coupon,Y=(r==null?void 0:r.discounts)||[],p=s=>y({...a,[s.target.name]:s.target.value});n.useEffect(()=>{var l;const s=(l=u==null?void 0:u.auth)==null?void 0:l.user;s&&y(t=>({...t,customer_name:s.name||t.customer_name,customer_email:s.email||t.customer_email,customer_phone:s.phone||t.customer_phone,shipping_address:s.address||t.shipping_address,city:s.city||t.city,state:s.state||t.state,pincode:s.pincode||t.pincode})),(async()=>{try{const{data:t}=await j.get("/cart/summary");D(t)}catch{}})(),s&&(async()=>{try{const{data:t}=await j.get("/account/addresses/list"),m=(t==null?void 0:t.addresses)||[];ie(m);const x=m.find(b=>b.is_default)||m[0];x&&(X(x.id),y(b=>({...b,customer_name:x.name,customer_phone:x.phone||"",shipping_address:x.address,city:x.city,state:x.state,pincode:x.pincode})))}catch{}})()},[]),n.useEffect(()=>{g||y(s=>s.apply_wallet?{...s,apply_wallet:!1}:s)},[g]),n.useEffect(()=>{g&&z<=0&&y(s=>s.apply_wallet?{...s,apply_wallet:!1}:s)},[g,z]);const me=()=>new Promise((s,l)=>{if(window.Razorpay)return s();const t=document.createElement("script");t.src="https://checkout.razorpay.com/v1/checkout.js",t.onload=()=>s(),t.onerror=l,document.body.appendChild(t)}),xe=async s=>{var l,t;if(s.preventDefault(),!!_.trim()){C(!0),k(""),P("");try{const{data:m}=await j.post("/cart/coupon",{code:_.trim()});m!=null&&m.summary&&D(m.summary),P("Coupon applied successfully."),B("")}catch(m){k(((t=(l=m.response)==null?void 0:l.data)==null?void 0:t.error)||"Unable to apply coupon")}finally{C(!1)}}},pe=async()=>{var s,l;C(!0),k(""),P("");try{const{data:t}=await j.delete("/cart/coupon");t!=null&&t.summary&&D(t.summary)}catch(t){k(((l=(s=t.response)==null?void 0:s.data)==null?void 0:l.error)||"Unable to remove coupon")}finally{C(!1)}},ue=async s=>{var l,t,m,x,b;s.preventDefault(),M(!0),T({}),N("");try{const{data:d}=await j.post("/checkout",a);if(!d.success)return;if(d.razorpay){await me();const v={key:d.razorpay.key,amount:d.razorpay.amount,currency:d.razorpay.currency,name:d.razorpay.name,order_id:d.razorpay.order_id,prefill:d.razorpay.prefill,handler:async function(G){try{q(!0);const O=await j.post("/payment/razorpay/verify",{order_number:d.order_number,razorpay_order_id:G.razorpay_order_id,razorpay_payment_id:G.razorpay_payment_id,razorpay_signature:G.razorpay_signature});if(O.data.success){typeof window<"u"&&window.dispatchEvent(new CustomEvent("cart:updated",{detail:{count:0}}));const he=route("order.confirmation",O.data.order_number||d.order_number);A.visit(he)}}catch{N("Payment verification failed. Please go to order details to retry payment."),setTimeout(()=>{A.visit(route("order.confirmation",d.order_number))},2e3)}finally{q(!1)}},modal:{ondismiss:function(){M(!1),N("Payment cancelled. Please complete your payment to confirm the order."),setTimeout(()=>{A.visit(route("order.confirmation",d.order_number))},1e3)}},theme:{color:"#2563eb"}};new window.Razorpay(v).open();return}typeof window<"u"&&window.dispatchEvent(new CustomEvent("cart:updated",{detail:{count:0}})),A.visit(route("order.confirmation",d.order_number))}catch(d){const v=((t=(l=d.response)==null?void 0:l.data)==null?void 0:t.error)||((x=(m=d.response)==null?void 0:m.data)==null?void 0:x.message)||"";if(((b=d.response)==null?void 0:b.status)===422){const te=d.response.data.errors||{};T(te),v&&N(v)}else N(v||"Failed to place order")}finally{M(!1)}};return e.jsx(fe,{children:e.jsx("div",{className:"bg-slate-100",children:e.jsxs("div",{className:"max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-12 space-y-8",children:[e.jsx("div",{className:"flex items-center justify-between text-sm text-slate-500 rounded-3xl p-4 bg-white shadow",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{href:"/",className:"hover:text-primary",children:"Home"}),e.jsx("span",{children:"»"}),e.jsx("span",{className:"font-semibold text-slate-700",children:"Checkout Page"})]})}),e.jsxs("form",{onSubmit:ue,className:"grid lg:grid-cols-[2fr_1fr] gap-8",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"bg-white border border-slate-200 rounded-3xl shadow-sm p-6 space-y-4",children:[e.jsx("h1",{className:"text-xl font-semibold text-slate-900",children:"Customer Details"}),H.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-800",children:"Saved addresses"}),e.jsx("a",{href:route("account.addresses"),className:"text-xs font-semibold text-primary",children:"Manage"})]}),e.jsx("div",{className:"space-y-2",children:H.map(s=>e.jsxs("label",{className:`flex items-start gap-3 rounded-2xl border px-4 py-3 text-sm ${Q===s.id?"border-indigo-400 bg-indigo-50/60":"border-slate-200 bg-white"}`,children:[e.jsx("input",{type:"radio",name:"saved_address",className:"mt-1",checked:Q===s.id,onChange:()=>{X(s.id),y(l=>({...l,customer_name:s.name,customer_phone:s.phone||"",shipping_address:s.address,city:s.city,state:s.state,pincode:s.pincode}))}}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-slate-900",children:[s.name," ",s.is_default?e.jsx("span",{className:"text-xs text-primary",children:"(Default)"}):null]}),e.jsx("p",{className:"text-xs text-slate-500",children:s.address}),e.jsxs("p",{className:"text-xs text-slate-500",children:[s.city,", ",s.state," ","- ",s.pincode,s.phone?` ⢠${s.phone}`:""]})]})]},s.id))})]}),!g&&e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50 p-4 space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-800",children:"Checkout options"}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-slate-600",children:[e.jsx("input",{type:"checkbox",name:"create_account",checked:a.create_account,onChange:s=>y({...a,create_account:s.target.checked})}),e.jsx("span",{children:"Create an account for faster checkout next time"})]}),a.create_account&&e.jsxs("div",{className:"grid md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Password"}),e.jsx("input",{type:"password",name:"password",value:a.password,onChange:p,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"}),o.password&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:o.password})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Confirm password"}),e.jsx("input",{type:"password",name:"password_confirmation",value:a.password_confirmation,onChange:p,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"})]})]}),e.jsxs("p",{className:"text-xs text-slate-500",children:["Already have an account?"," ",e.jsx(ae,{href:route("login"),className:"text-primary font-semibold",children:"Login"})]})]})]}),e.jsxs("section",{className:"bg-white border border-slate-200 rounded-3xl shadow-sm p-6 space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-900",children:"Billing Details"}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Full name"}),e.jsx("input",{name:"customer_name",value:a.customer_name,onChange:p,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"}),o.customer_name&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:o.customer_name})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Email"}),e.jsx("input",{type:"email",name:"customer_email",value:a.customer_email,onChange:p,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"}),o.customer_email&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:o.customer_email})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Phone"}),e.jsx("input",{name:"customer_phone",value:a.customer_phone,onChange:p,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"}),o.customer_phone&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:o.customer_phone})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Pincode"}),e.jsx("input",{name:"pincode",value:a.pincode,onChange:p,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"}),o.pincode&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:o.pincode})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"City"}),e.jsx("input",{name:"city",value:a.city,onChange:p,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"}),o.city&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:o.city})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"State"}),e.jsx("input",{name:"state",value:a.state,onChange:p,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"}),o.state&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:o.state})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Address"}),e.jsx("textarea",{name:"shipping_address",value:a.shipping_address,onChange:p,rows:3,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2"}),o.shipping_address&&e.jsx("p",{className:"text-xs text-red-600 mt-1",children:o.shipping_address})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs uppercase tracking-wide text-slate-400",children:"Order notes"}),e.jsx("textarea",{name:"notes",value:a.notes,onChange:p,rows:3,className:"mt-1 w-full rounded-xl border border-slate-200 px-3 py-2",placeholder:"Add any instructions for delivery"})]})]})]}),e.jsxs("aside",{className:"space-y-6",children:[e.jsxs("section",{className:"bg-white border border-slate-200 rounded-3xl shadow-sm p-6 space-y-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-900",children:"Summary"}),e.jsxs("div",{className:"space-y-3 max-h-64 overflow-auto pr-1 text-sm",children:[F.map(s=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-12 w-12 rounded-2xl bg-slate-100 overflow-hidden",children:e.jsx("img",{src:s.primary_image||"/img/haslab-logo.png",alt:s.name,className:"h-full w-full object-cover"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-slate-800",children:s.name}),e.jsxs("p",{className:"text-xs text-slate-500",children:["Qty ",s.quantity]})]})]}),e.jsx("span",{className:"font-semibold text-slate-900",children:h(s.price*s.quantity)})]},s.key)),U&&U.map((s,l)=>e.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm text-emerald-600",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-12 w-12 rounded-2xl bg-emerald-50 overflow-hidden",children:e.jsx("img",{src:s.primary_image||"/img/haslab-logo.png",alt:s.name,className:"h-full w-full object-cover"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:s.name}),e.jsxs("p",{className:"text-xs uppercase tracking-wide",children:["Free Gift Ã"," ",s.quantity]})]})]}),e.jsx("span",{className:"font-semibold",children:"FREE"})]},`g-${l}`))]}),f&&e.jsxs("div",{className:"rounded-2xl border border-indigo-100 bg-indigo-50 p-3 text-xs text-indigo-700",children:["Add"," ",e.jsx("span",{className:"font-semibold",children:h(f.amount_to_add)})," ","more to unlock"," ",e.jsx("span",{className:"font-semibold",children:((ee=f.reward)==null?void 0:ee.kind)==="discount"?f.reward.discount_type==="flat"?h(f.reward.discount_value):`${Number(f.reward.discount_value||0).toFixed(0)}% off`:((se=f.reward)==null?void 0:se.name)||f.title}),"."]}),e.jsxs("div",{className:"space-y-3 text-sm text-slate-600",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Sub-total"}),e.jsx("span",{className:"font-semibold text-slate-900",children:h((r==null?void 0:r.subtotal)||0)})]}),Y.length>0&&e.jsx("div",{className:"space-y-1 text-emerald-600",children:Y.map(s=>e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:s.title}),e.jsxs("span",{children:["-",h(s.amount)]})]},s.offer_id))}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Shipping"}),e.jsx("span",{children:h((r==null?void 0:r.shipping)||0)})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("input",{type:"text",placeholder:"Coupon code",className:"flex-1 border rounded-xl px-3 py-2 text-sm uppercase",value:_,onCh
1ange:s=>B(s.target.value.toUpperCase()),disabled:!!E}),E?e.jsx("button",{type:"button",onClick:pe,className:"px-4 py-2 rounded-full border text-slate-600",disabled:W,children:"Remove"}):e.jsx("button",{type:"button",onClick:xe,className:"px-4 py-2 rounded-full bg-indigo-600 text-white",disabled:W||!_.trim(),children:"Apply"})]}),E&&e.jsxs("p",{className:"text-xs text-emerald-700",children:[E.code," applied â saved"," ",h((r==null?void 0:r.coupon_discount)||0)]}),L&&e.jsx("p",{className:"text-xs text-red-600",children:L}),V&&e.jsx("p",{className:"text-xs text-emerald-600",children:V})]}),S>0&&e.jsxs("div",{className:"flex justify-between text-sm text-emerald-600",children:[e.jsx("span",{children:"Wallet applied"}),e.jsxs("span",{children:["-",h(S)]})]}),e.jsxs("div",{className:"flex justify-between text-base font-semibold text-slate-900 border-t border-slate-200 pt-2",children:[e.jsx("span",{children:"Total amount"}),e.jsx("span",{children:h(ce)})]}),a.payment_method==="razorpay"&&e.jsx("div",{className:"text-xs text-primary bg-indigo-50 rounded-2xl p-2",children:"Pay online & get 5% cashback (up to â¹200) credited to your wallet after payment."})]})]}),e.jsxs("section",{className:"bg-white border border-slate-200 rounded-3xl shadow-sm p-6 space-y-3 text-sm",children:[e.jsx("h3",{className:"text-base font-semibold text-slate-900",children:"Payment Method"}),e.jsx("div",{className:"space-y-2",children:be.map(s=>e.jsxs("label",{className:`flex items-center justify-between gap-3 rounded-2xl border px-4 py-3 ${a.payment_method===s.value?"border-indigo-500 bg-indigo-50/60":"border-slate-200 bg-white"}`,children:[e.jsx("span",{className:"text-slate-700 font-medium",children:s.label}),e.jsx("input",{type:"radio",name:"payment_method",value:s.value,checked:a.payment_method===s.value,onChange:l=>y({...a,payment_method:l.target.value})})]},s.value))}),a.payment_method==="razorpay"?e.jsxs("div",{className:"text-xs text-indigo-700 bg-indigo-50 rounded-2xl p-3 space-y-1",children:[e.jsx("p",{children:"Pay online via cards, UPI, and wallets. Get 5% cashback (up to â¹200) credited to your wallet automatically."}),R&&e.jsx("p",{className:"text-amber-600 font-semibold",children:"Verifying payment⦠please wait."})]}):e.jsx("p",{className:"text-xs text-slate-500",children:"We will share payment instructions once you place the order."})]}),$&&e.jsx("div",{className:"rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm font-medium text-rose-600",children:$}),e.jsxs("section",{className:"bg-white border border-slate-200 rounded-3xl shadow-sm p-6 space-y-4 text-xs text-slate-500",children:[e.jsxs("p",{children:["By placing an order you agree to our"," ",e.jsx("a",{href:route("policy.terms"),className:"text-primary font-semibold",children:"Terms"}),","," ",e.jsx("a",{href:route("policy.privacy"),className:"text-primary font-semibold",children:"Privacy Policy"}),", and"," ",e.jsx("a",{href:route("policy.refund"),className:"text-primary font-semibold",children:"Refund & Cancellation Policy"}),"."]}),e.jsx("button",{type:"submit",disabled:I||R,className:"inline-flex w-full justify-center rounded-full bg-indigo-600 px-6 py-3 text-sm font-semibold text-white shadow hover:bg-indigo-700 disabled:bg-indigo-300",children:R?"Verifying paymentâ¦":I?"Placingâ¦":"Place Order"})]})]})]})]})})})}export{De as default};
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.