1import{r as i,j as e}from"./vendor-react-CubF7Ysi.js";import{u as A,bK as Y,af as N,ak as v,aO as Z,aA as O,R as ee,B as j,ag as D,ai as L,a1 as U,al as te,I,e as se}from"./index-yVRJ_DrD.js";import{L as C}from"./label-27wMobMv.js";import{C as W}from"./circle-x-BKj9kgFZ.js";import{P as ae}from"./package-search-CCozKOLp.js";import"./vendor-supabase-C5Zeq6fY.js";import"./vendor-query-BtJS4VZ-.js";import"./vendor-motion-DUPVpWKG.js";import"./vendor-stripe-BNgkNZiY.js";const ne=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,re=new Set(["neu","übermittelt","in_druck","stornierungsanfrage","teilstorniert"]),ie=new Set(["in_auslieferung","zugestellt"]);function le(){try{return crypto.randomUUID()}catch{return`wd-${Date.now()}-${Math.round(Math.random()*1e9)}`}}async function $(t,g){var x,l,h;const{data:c,error:d}=await se.functions.invoke(t,{body:g});if(d){const y=((x=d==null?void 0:d.context)==null?void 0:x.status)??500;let u=null;try{u=await((h=(l=d==null?void 0:d.context)==null?void 0:l.json)==null?void 0:h.call(l))}catch{}return{data:u,status:y}}return{data:c,status:200}}function de(){var M;const{t,i18n:g}=A("withdrawal"),[c]=Y(),d=(M=g.language)!=null&&M.startsWith("en")?"en":"de",[x,l]=i.useState("identify"),[h,y]=i.useState(""),[u,F]=i.useState(""),[E,R]=i.useState(null),[r,S]=i.useState(null),[f,P]=i.useState([]),[B,q]=i.useState(""),[k,T]=i.useState(""),[w,b]=i.useState(!1),[p,o]=i.useState(null),[_,z]=i.useState(null),V=i.useMemo(le,[]),H=r&&f.length===r.items.length?"full":"partial";i.useEffect(()=>{const s=c.get("ref"),n=c.get("code"),a=c.get("email");a&&F(a),n&&y(n.toUpperCase()),s&&R(s),(s||n)&&a&&G({ref:s,code:n,email:a})},[]);function K(s){return t(s===404?"errors.notFound":s===429?"errors.rateLimited":"errors.generic")}async function G(s){if(!ne.test(s.email)||!s.ref&&!s.code){o(t("errors.missingFields"));return}b(!0),o(null);const{data:n,status:a}=await $("withdrawal-lookup",{ref:s.ref||void 0,code:s.code||void 0,email:s.email});if(b(!1),a!==200||!(n!=null&&n.ok)){o(K(a));return}const m=n.order;if(S(m),R(m.publicRef),T(s.email),m.windowExpired){l("expired");return}P(m.items.map(Q=>Q.id)),l("review")}function X(s){P(n=>n.includes(s)?n.filter(a=>a!==s):[...n,s])}async function J(){if(!r)return;b(!0),o(null);const{data:s,status:n}=await $("withdrawal-submit",{ref:E,code:h||r.orderCode,email:u,scope:H,orderItemIds:f,reasonDetail:B||void 0,contactEmail:k||u,idempotencyKey:V,locale:d});if(b(!1),n!==200||!(s!=null&&s.ok)){if(n===422){l("expired");return}o(K(n));return}z({withdrawalCode:s.withdrawalCode}),l("done")}if(x==="done"&&_&&r){const s=r.items.filter(m=>f.includes(m.id)),n=s.some(m=>ie.has(m.status)),a=s.some(m=>re.has(m.status));return e.jsx(N,{children:e.jsxs(v,{className:"pt-6 space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx(Z,{className:"h-12 w-12 text-emerald-600 mx-auto"}),e.jsx("h2",{className:"text-xl font-semibold",children:t("done.heading")}),e.jsx("p",{className:"text-muted-foreground",children:e.jsx(O,{i18nKey:"done.body",ns:"withdrawal",values:{email:k||u},components:{strong:e.jsx("strong",{})}})}),e.jsx("p",{className:"font-medium",children:t("done.reference",{code:_.withdrawalCode})})]}),a&&e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border p-4",children:[e.jsx(W,{className:"h-5 w-5 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t("done.cancelTitle")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("done.cancelBody")})]})]}),n&&e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-amber-300/60 bg-amber-50 p-4",children:[e.jsx(ee,{className:"h-5 w-5 text-amber-600 mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t("done.returnTitle")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("done.returnBody")})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("done.refundNote")})]})})}if(x==="expired"){const s=r!=null&&r.withdrawalDeadline?new Date(r.withdrawalDeadline).toLocaleDateString(d==="en"?"en-GB":"de-DE",{day:"2-digit",month:"2-digit",year:"numeric"}):null;return e.jsx(N,{children:e.jsxs(v,{className:"pt-6 space-y-4",children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx(W,{className:"h-12 w-12 text-muted-foreground mx-auto"}),e.jsx("h2",{className:"text-xl font-semibold",children:t("expired.heading")}),e.jsx("p",{className:"text-muted-foreground",children:t("expired.body")}),s&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t("expired.deadline",{date:s})})]}),e.jsx("div",{className:"rounded-lg border bg-muted/40 p-4 text-sm text-muted-foreground",children:t("expired.contact")}),e.jsx("div",{className:"flex justify-center",children:e.jsx(j,{variant:"ghost",onClick:()=>{o(null),S(null),l("identify")},children:t("expired.back")})})]})})}if(x==="confirm"&&r)return e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(L,{children:t("confirm.heading")})}),e.jsxs(v,{className:"space-y-5",children:[e.jsx("p",{children:e.jsx(O,{i18nKey:H==="full"?"confirm.summaryFull":"confirm.summaryPartial",ns:"withdrawal",values:{code:r.orderCode,count:f.length},components:{strong:e.jsx("strong",{})}})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("confirm.notice")}),p&&e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:p}),e.jsxs("div",{className:"flex flex-col-reverse sm:flex-row gap-3 sm:justify-between",children:[e.jsx(j,{variant:"ghost",onClick:()=>{o(null),l("review")},disabled:w,children:t("confirm.back")}),e.jsx(j,{onClick:J,disabled:w,children:w?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"h-4 w-4 mr-2 animate-spin"}),t("confirm.submitting")]}):t("confirm.submit")})]})]})]});if(x==="review"&&r){const s=new Date(r.createdAt).toLocaleDateString(d==="en"?"en-GB":"de-DE",{day:"2-digit",month:"2-digit",year:"numeric"}),n=r.items.length>1;return e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(L,{children:t("review.heading")})}),e.jsxs(v,{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg bg-muted/50 p-4 text-sm space-y-1",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("review.orderLabel"),":"]})," ",e.jsxs("span",{className:"font-medium",children:["#",r.orderCode]})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("review.dateLabel"),":"]})," ",s]}),r.withdrawalDeadline&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[t("review.deadlineLabel"),":"]})," ",new Date(r.withdrawalDeadline).toLocaleDateString(d==="en"?"en-GB":"de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:t(n?"review.selectItemsHint":"review.itemsLabel")}),e.jsx("ul",{className:"space-y-2",children:r.items.map(a=>e.jsx("li",{children:e.jsxs("label",{className:"flex items-start gap-3 rounded-lg border p-3 cursor-pointer",children:[n&&e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 accent-primary",checked:f.includes(a.id),onChange:()=>X(a.id)}),e.jsxs("span",{className:"flex-1 text-sm",children:[e.jsx("span",{className:"font-medium",children:a.title}),a.variant?e.jsxs("span",{className:"text-muted-foreground",children:[" · ",a.variant]}):null,e.jsxs("span",{className:"text-muted-foreground",children:[" · Ã",a.quantity]})]})]})},a.id))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"wd-reason",children:t("review.reasonLabel")}
1),e.jsx(te,{id:"wd-reason",value:B,onChange:a=>q(a.target.value),placeholder:t("review.reasonPlaceholder"),rows:3,maxLength:2e3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"wd-contact",children:t("review.contactLabel")}),e.jsx(I,{id:"wd-contact",type:"email",value:k,onChange:a=>T(a.target.value)})]}),p&&e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:p}),e.jsxs("div",{className:"flex flex-col-reverse sm:flex-row gap-3 sm:justify-between",children:[e.jsx(j,{variant:"ghost",onClick:()=>{o(null),S(null),l("identify")},children:t("review.changeOrder")}),e.jsx(j,{onClick:()=>{if(f.length===0){o(t("errors.selectItems"));return}o(null),l("confirm")},children:t("review.trigger")})]})]})]})}return e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(L,{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-5 w-5"}),t("identify.heading")]})}),e.jsxs(v,{className:"space-y-5",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t("identify.intro")}),e.jsxs("form",{className:"space-y-4",onSubmit:s=>{s.preventDefault(),G({ref:E,code:h,email:u})},children:[!E&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"wd-code",children:t("identify.codeLabel")}),e.jsx(I,{id:"wd-code",value:h,onChange:s=>y(s.target.value.toUpperCase()),placeholder:t("identify.codePlaceholder"),autoComplete:"off"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{htmlFor:"wd-email",children:t("identify.emailLabel")}),e.jsx(I,{id:"wd-email",type:"email",value:u,onChange:s=>F(s.target.value),placeholder:t("identify.emailPlaceholder"),autoComplete:"email"})]}),p&&e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:p}),e.jsx(j,{type:"submit",className:"w-full",disabled:w,children:w?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"h-4 w-4 mr-2 animate-spin"}),"â¦"]}):t("identify.submit")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("identify.hint")})]})]})]})}function ge(){const{t}=A("withdrawal");return i.useEffect(()=>{const g=document.title;document.title=`${t("meta.title")} · lilcomp`;const c=document.createElement("meta");return c.name="robots",c.content="noindex,nofollow",document.head.appendChild(c),()=>{document.title=g,c.remove()}},[t]),e.jsx("main",{className:"min-h-screen bg-background flex items-start justify-center px-4 py-10 sm:py-16",children:e.jsxs("div",{className:"w-full max-w-lg space-y-6",children:[e.jsxs("header",{className:"text-center space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold",children:t("meta.title")}),e.jsx("p",{className:"text-muted-foreground",children:t("meta.subtitle")})]}),e.jsx(de,{}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:t("legalHint")})]})})}export{ge as default}; 2//# sourceMappingURL=WithdrawalForm-syynbKs6.js.map
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.