1import{j as e,B as j,a1 as E,T as k,z as W,R as c,U as h,V as _,W as y,al as De,a8 as Me,a9 as ke,aa as Ie,ab as P,ac as a,a3 as $,ak as Be,e as I,Z as Le,ag as Re,S as G,a0 as Z,ai as Fe,af as Ee}from"./vendor-mui-DFXKyM2E.js";import{a as We,u as J,n as w,c as B,o as Ke,I as Ve}from"./index-DGSpuRBj.js";import{u as Oe,a as d,L as He}from"./vendor-react-CrXZvyk_.js";import{u as Qe,C as X,c as Ue,e as Ye,b as C}from"./vendor-form-Df9-JY-v.js";import{N as ze}from"./NavHeader-BROh2czj.js";import{P as K}from"./index-CEAOSh_Q.js";import{C as $e}from"./Countries-CTDmd1_2.js";import{f as Ge}from"./Memberships-bRzBLWWy.js";import{c as Ze}from"./Orders-LpAsvTrD.js";import{f as Je}from"./Promotions-CUdrRC69.js";import{f as Xe}from"./Users-B12Mx37p.js";import{B as ei,Q as ii,C as ee,a as ri}from"./64x64-vi-vnpay-CICwzdxR.js";import"./vendor-redux-Bi3kFs4E.js";import"./vendor-utils-BFUpClQh.js";import"./Home-CqZgsyW_.js";import"./useDebouncedValue-CkrckZR6.js";const si=Ue().shape({billing_name:C().required("Full name is required"),billing_phone:C().required("Phone number is required"),billing_email:C().email("Invalid email").required("Email is required"),billing_country:C().required("Country is required"),billing_city:C().required("City is required"),billing_district:C().required("District is required"),billing_ward:C().required("Ward is required"),billing_address:C().required("Address is required"),payment_status:Ye().oneOf(["pending","success","failed","refunded"]).required("Payment status is required")}),_i=()=>{const{showMessage:m,startProgress:ie,completeProgress:re,currentLanguage:se}=We(),{t:i}=J(),te=Oe(),{register:f,handleSubmit:ne,control:V,setValue:ti,watch:le,formState:{errors:s,isSubmitting:ae}}=Qe({resolver:Ke(si),defaultValues:{billing_name:"",billing_phone:"",billing_email:"",billing_country:"",billing_city:"",billing_district:"",billing_ward:"",billing_address:"",payment_status:"pending",send_email:!1}}),oe=le("payment_status"),[de,O]=d.useState(!1),[L,ce]=d.useState(null),[o,A]=d.useState([]),[me,H]=d.useState(!1),[T,q]=d.useState("vietqr"),[D,M]=d.useState(!1),[b,R]=d.useState(null),[ue,he]=d.useState(0),[Q,pe]=d.useState(0),[be,xe]=d.useState(0),[ge,je]=d.useState(0),[x,U]=d.useState(null),[ye,Y]=d.useState(!1);d.useEffect(()=>{},[oe]);async function fe(r){try{O(!0),ie();const l={...r,language:se,payment_method:T,payment_type:D,billing_subtotal:Q,promotion_id:b?.id,user_id:L?.id,send_email:r.send_email?1:0,cart:o},n=await Ze(l);if(n&&!n.error){const{data:t}=n;m("success",i("Data updated successfully!")),t?.id&&te("/admin/orders/"+t.id)}else m("error",i("Failed to create order.")+(n?.error||""))}catch{m("error",i("An error occurred, please try again later!"))}finally{O(!1),re(!0)}}const _e={position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:400,bgcolor:"background.paper",border:"2px solid #000",boxShadow:24,pt:2,px:4,pb:3},we=()=>{Y(!0)},z=()=>{Y(!1),U(null)};d.useEffect(()=>{let r=0,l=0,n=0,t=0;Array.isArray(o)&&o.length>0&&o.forEach(g=>{const{loyalty_amount:p,promotion_amount:u,subtotal:N,total:v}=g;t+=p||0,n+=u||0,r+=N||0,l+=v||0}),he(l),je(t),pe(r),xe(n)},[o]);function Ce(r){R(r);let l=!1;if(r&&Array.isArray(o)&&o.length>0){let n=o.map(t=>{if(r.for_all_memberships||Array.isArray(r.memberships)&&r.memberships.some(p=>p.id===t.membership?.id)){const p=r.promotion_amount,u=Number(t.subtotal)*p/100;t={...t,promotion_id:r.id,promotion:r,promotion_amount:u,total:Number(t.subtotal)-Number(t.loyalty_amount)-u},l=!0}else t={...t,promotion_id:null,promotion:null,promotion_amount:null,total:Number(t.subtotal)-Number(t.loyalty_amount)};return t});l?(A(n),m("success",i("Promotion code successfully applied!"))):(m("error",i("This code is not valid for any items in cart.")),R(null),A(o.map(t=>({...t,promotion_amount:null,promotion_id:null,promotion:null,total:0}))))}else r?(m("error",i("This code is not valid.")),R(null)):(A(o.map(n=>({...n,promotion_amount:null,promotion_id:null,promotion:null,total:0}))),m("success",i("Promotion code removed.")))}function Pe(r){if(r.preventDefault(),!x)return m("error",i("Please select a membership to add!"));if(o.some(S=>S?.membership?.id===x?.id))return m("error",i("Membership is already in cart!"));let n=1,t;const g=x?.membership_loyalty;Array.isArray(g)&&g.length>0&&(t=g[0]);const p=x.regular_price;let u=0,N=0,v=p*n,F=v;if(t){const S=t?.discount_percent;u=v*S/100,F-=u}b&&(b.for_all_memberships||Array.isArray(b.memberships)&&b.memberships.some(qe=>qe.id===x.id))&&(N=v*b.promotion_amount/100,F-=N);const Ne={membership_id:x.id,membership:x,loyalty:t?.loyalty||null,loyalty_id:t?.id||null,promotion:b||null,promotion_id:b?.
1id||null,loyalty_amount:u,promotion_amount:N,quantity:n,subtotal:v,total:F};A(S=>[...S,Ne]),z(),m("success",i("Membership added to cart!"))}function ve(r){H(r),setTimeout(()=>{A(l=>l.filter((n,t)=>t!==r)),H(!1),m("success",i("Item removed from cart."))},300)}const Se=[{id:"id",numeric:!1,disablePadding:!1,label:"ID"},{id:"membership",numeric:!1,disablePadding:!1,label:"Membership"},{id:"subtotal",numeric:!1,disablePadding:!1,label:"Subtotal"},{id:"loyalty_amount",numeric:!1,disablePadding:!1,label:"Loyalty"},{id:"promotion_amount",numeric:!1,disablePadding:!1,label:"Promotion"},{id:"total",numeric:!1,disablePadding:!1,label:"Total"},{id:"actions",numeric:!1,disablePadding:!1,label:"Actions"}];function Ae(r){const{t:l}=J();return e.jsx(Ee,{children:e.jsx(P,{children:Se.map(n=>e.jsx(a,{align:n.numeric?"right":"left",padding:n.disablePadding?"none":"normal",children:e.jsx("p",{className:"font-bold",children:l(n.label)})},n.id))})})}const Te=({indexKey:r,rowData:l})=>{const{membership:n,subtotal:t,total:g,loyalty_amount:p,promotion_amount:u}=l;return e.jsxs(P,{hover:!0,role:"checkbox",tabIndex:-1,className:"!text-sm",sx:{cursor:"pointer"},children:[e.jsxs(a,{children:[e.jsx("p",{children:r+1})," "]}),e.jsx(a,{children:e.jsx(G,{direction:"row",spacing:2,alignItems:"center",children:e.jsx(He,{to:"/admin/memberships/"+n?.id,children:e.jsx("p",{children:n?.title})})})}),e.jsx(a,{children:e.jsx("p",{children:t?w(t)+"â«":"-"})}),e.jsx(a,{children:e.jsx("p",{children:p?w(p)+"â«":"-"})}),e.jsx(a,{children:e.jsx("p",{children:u?w(u)+"â«":"-"})}),e.jsx(a,{children:g?w(g)+"â«":"-"}),e.jsx(a,{sx:{width:120},children:e.jsx(Z,{loading:me===r,onClick:()=>ve(r),children:e.jsx(Ve,{})})})]},r)};return e.jsxs(d.Fragment,{children:[e.jsxs(j,{sx:{width:"100%"},children:[e.jsx(ze,{title:i("Create Order"),breadcrumb:[{title:i("Create Order")}],backLink:"/admin/orders"}),e.jsx(j,{component:"form",onSubmit:ne(fe),children:e.jsxs(E,{container:!0,spacing:5,children:[e.jsxs(E,{item:!0,xs:12,lg:8,children:[e.jsx(k,{sx:{textTransform:"uppercase",fontWeight:600,mb:2},children:i("Billing information")}),e.jsxs(W,{sx:{p:3,mb:3},children:[e.jsxs(c,{sx:{width:"100%",mb:3},error:!!s.billing_name,required:!0,children:[e.jsx(h,{children:"Your full name"}),e.jsx(_,{...f("billing_name"),error:!!s.billing_name}),s.billing_name&&e.jsx(y,{children:s.billing_name.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-5",children:[e.jsxs(c,{sx:{width:"100%",mb:3},error:!!s.billing_phone,required:!0,children:[e.jsx(h,{children:i("Phone number")}),e.jsx(_,{...f("billing_phone"),error:!!s.billing_phone}),s.billing_phone&&e.jsx(y,{children:s.billing_phone.message})]}),e.jsxs(c,{sx:{width:"100%",mb:3},error:!!s.billing_email,required:!0,children:[e.jsx(h,{children:i("Email address")}),e.jsx(_,{...f("billing_email"),error:!!s.billing_email}),s.billing_email&&e.jsx(y,{children:s.billing_email.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-5",children:[e.jsxs(c,{sx:{width:"100%",mb:3},error:!!s.billing_country,children:[e.jsx(h,{children:i("Country")}),e.jsx(X,{name:"billing_country",control:V,render:({field:r})=>e.jsx(De,{...r,options:$e,onChange:(l,n)=>r.onChange(n),value:r.value,renderInput:l=>e.jsx(_,{...l,error:!!s.billing_country,inputProps:{...l.inputProps}})})}),s.billing_country&&e.jsx(y,{children:s.billing_country.message})]}),e.jsxs(c,{sx:{width:"100%",mb:3},error:!!s.billing_city,children:[e.jsx(h,{children:i("Billing City")}),e.jsx(_,{...f("billing_city"),error:!!s.billing_city}),s.billing_city&&e.jsx(y,{children:s.billing_city.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-5",children:[e.jsxs(c,{sx:{width:"100%",mb:3},error:!!s.billing_district,children:[e.jsx(h,{children:i("Billing District")}),e.jsx(_,{...f("billing_district"),error:!!s.billing_district}),s.billing_district&&e.jsx(y,{children:s.billing_district.message})]}),e.jsxs(c,{sx:{width:"100%",mb:3},error:!!s.billing_ward,children:[e.jsx(h,{children:i("Billing Ward")}),e.jsx(_,{...f("billing_ward"),error:!!s.billing_ward}),s.billing_ward&&e.jsx(y,{children:s.billing_ward.message})]})]}),e.jsxs(c,{sx:{width:"100%",mb:3},error:!!s.billing_address,children:[e.jsx(h,{children:i("Billing address")}),e.jsx(_,{...f("billing_address"),error:!!s.billing_address}),s.billing_address&&e.jsx(y,{children:s.billing_address.message})]})]}),e.jsx(k,{sx:{textTransform:"uppercase",fontWeight:600,mb:2},children:i("Cart")}),e.jsx(W,{sx:{width:"100%",overflow:"hidden",mb:3},children:e.jsx(Me,{sx:{maxHeight:640,maxWidth:"calc(100vw - 54px)"},children:e.jsxs(ke,{stickyHeader:!0,"aria-label":"sticky table",size:"medium",children:[e.jsx(Ae,{numSelected:0,rowCount:o?.length}),e.jsxs(Ie,{children:[Array.isArray(o)&&o.length>0?o.map((r,l)=>e.jsx(Te,{indexKey:l,rowData:r},l)):e.jsx(P,{children:e.jsx(a,{colSpan:7,align:"center",children:i("No items in cart")})}),e.jsxs(P,{children:[e.jsx(a,{rowSpan:4,colSpan:3,sx:{borderBottom:"none"}}),e.jsx(a,{colSpan:2,children:e.jsx("strong",{children:i("Subtotal")})}),e.jsxs(a,{colSpan:2,align:"right",children:[w(Q),"â«"]})]}),e.jsxs(P,{children:[e.jsx(a,{colSpan:2,children:e.jsx("strong",{children:i("Loyalty")})}),e.jsxs(a,{colSpan:2,align:"right",children:[w(ge),"â«"]})]}),e.jsxs(P,{children:[e.jsx(a,{colSpan:2,children:e.jsx("strong",{children:i("Promotion")})}),e.jsxs(a,{colSpan:2,align:"right",children:[w(be),"â«"]})]}),e.jsxs(P,{children:[e.jsx(a,{colSpan:2,children:e.jsx("strong",{children:i("Total")})}),e.jsxs(a,{colSpan:2,align:"right",children:[w(ue),"â«"]})]})]})]})})}),e.jsx(j,{sx:{textAlign:"right",mb:2},children:e.jsx($,{variant:"contained",color:"secondary",sx:{borderRadius:0},onClick:we,children:i("Add to Cart")})})]}),e.jsx(E,{item:!0,xs:12,lg:4,children:e.jsxs("div",{className:"sticky top-0",children:[e.jsxs(j,{sx:{mb:3},children:[e.jsx(k,{sx:{textTransform:"uppercase",fontWeight:600,mb:2},children:i("Payment method")}),e.jsx(W,{sx:{p:3,mb:3},children:e.jsxs(c,{sx:{width:"100%"},children:[e.jsxs("div",{onClick:()=>{q("vietqr"),M(!1)},className:B({"flex gap-3 cursor-pointer bg-white rounded border-slate-200 mb-3 py-1 px-2 items-center":!0,"bg-green-50 border !border-green-600 text-green-600 shadow":T==="vietqr"}),children:[e.jsx("div",{className:"flex-1",children:e.jsx("p",{children:i("Bank transfer")})}
1),e.jsx("div",{children:e.jsx("img",{width:34,height:34,src:ei,alt:"Bank icon"})})]}),e.jsxs("div",{onClick:()=>{q("vnpay"),M("VNPAYQR")},className:B({"flex gap-3 cursor-pointer bg-white rounded border-slate-200 mb-3 py-1 px-2 items-center":!0,"bg-green-50 border !border-green-600 text-green-600 shadow":T==="vnpay"&&D==="VNPAYQR"}),children:[e.jsx("div",{className:"flex-1",children:e.jsx("p",{children:i("Payment code scanning application supported by VNPAY")})}),e.jsx("div",{children:e.jsx("img",{width:34,height:34,src:ii,alt:"VNPay QR icon"})})]}),e.jsxs("div",{onClick:()=>{q("vnpay"),M("VNBANK")},className:B({"flex gap-3 cursor-pointer bg-white rounded border-slate-200 mb-3 py-1 px-2 items-center":!0,"bg-green-50 border !border-green-600 text-green-600 shadow":T==="vnpay"&&D==="VNBANK"}),children:[e.jsx("div",{className:"flex-1",children:e.jsx("p",{children:i("Domestic card and bank account")})}),e.jsx("div",{children:e.jsx("img",{width:34,height:34,src:ee,alt:"ATM icon"})})]}),e.jsxs("div",{onClick:()=>{q("vnpay"),M("INTCARD")},className:B({"flex gap-3 cursor-pointer bg-white rounded border-slate-200 mb-3 py-1 px-2 items-center":!0,"bg-green-50 border !border-green-600 text-green-600 shadow":T==="vnpay"&&D==="INTCARD"}),children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{children:i("International payment card")}),e.jsx("img",{src:ri,alt:"Credit line"})]}),e.jsx("div",{children:e.jsx("img",{width:34,height:34,src:ee,alt:"Credit card icon"})})]})]})})]}),e.jsxs(j,{sx:{mb:3},children:[e.jsx(h,{children:i("Payment status")}),e.jsx(X,{name:"payment_status",control:V,render:({field:r})=>e.jsxs(Be,{...r,fullWidth:!0,error:!!s.payment_status,children:[e.jsx(I,{value:"pending",children:i("Transaction Pending")}),e.jsx(I,{value:"success",children:i("Transaction Successful")}),e.jsx(I,{value:"failed",children:i("Transaction Failed")}),e.jsx(I,{value:"refunded",children:i("Refunded")})]})}),s.payment_status&&e.jsx(y,{sx:{color:"red"},children:s.payment_status.message})]}),e.jsxs(j,{sx:{mb:3},children:[e.jsx(h,{children:"Promotion"}),e.jsx(K,{name:"promotion",defaultData:b,getApi:Je,onChange:r=>Ce(r),optionKey:"promotion_code",valueKey:"id",previewKey:"title"})]}),e.jsxs(j,{sx:{mb:1},children:[e.jsx(h,{children:"User"}),e.jsx(K,{name:"user",defaultData:L,getApi:Xe,required:!0,onChange:r=>ce(r),optionKey:"email",valueKey:"id",previewKey:"title"})]}),e.jsx(c,{sx:{width:"100%",mb:3},children:e.jsx(Le,{control:e.jsx(Re,{...f("send_email")}),label:i("Send the order confirmation email to the customer")})}),e.jsx(c,{children:e.jsx(G,{direction:"row",alignItems:"center",spacing:3,children:e.jsx(Z,{variant:"contained",color:"primary",type:"submit",loading:de||ae,disabled:o.length===0,children:i("Create order")})})})]})})]})})]}),e.jsx(Fe,{open:ye,onClose:z,"aria-labelledby":"add-membership-modal-title","aria-describedby":"add-membership-modal-description",children:e.jsxs(j,{sx:{..._e,width:400},children:[e.jsx(k,{id:"add-membership-modal-title",sx:{fontWeight:600,fontSize:24,textTransform:"uppercase"},children:i("Add to cart")}),e.jsxs("form",{onSubmit:Pe,children:[e.jsx(j,{sx:{mb:1},children:e.jsx(K,{name:"membership",defaultData:x,getApi:Ge,defautSearchParams:{user_id:L?.id},onChange:r=>U(r),optionKey:"title",valueKey:"id",previewKey:"id"})}),e.jsx(c,{sx:{mt:2,width:"100%"},children:e.jsx($,{variant:"contained",sx:{borderRadius:0,background:"#000",width:"100%"},type:"submit",disabled:!x,children:i("Submit")})})]})]})})]})};export{_i 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.