1import{p as I,j as e,r}from"./index-CJSs1J5s.js";import{I as A,a as z,b as q}from"./input-otp-sIEYvxmp.js";import{L as x}from"./loader-circle-DVv_Wuji.js";import{S as B}from"./shield-check-Dn7jiNoP.js";import{P as F}from"./printer-BrB33ta4.js";import{E as M}from"./eye-off-D5W7cY-F.js";import{E as _}from"./eye-obe56eMt.js";import{L as Y}from"./log-out-C34Q5Lur.js";import{D as R}from"./download-CfMC0Vt2.js";import"./minus-Vtvle_tr.js";const Z="[email protected]";async function T(m,l){const f=await m.blob(),p=(m.headers.get("Content-Disposition")??"").match(/filename="([^"]+)"/),C=p?p[1]:l,d=URL.createObjectURL(f),s=document.createElement("a");s.href=d,s.download=C,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(d)}function G(){const{login:m,loginTotp:l}=I(),[f,S]=r.useState(""),[p,C]=r.useState(!1),[d,s]=r.useState(""),[c,u]=r.useState(!1),[h,i]=r.useState(null),[b,n]=r.useState(""),[P,k]=r.useState(!1),[v,y]=r.useState(""),E=async o=>{o.preventDefault(),s(""),u(!0);try{const g=await m({email:Z,password:f});if(g.twoFactorRequired){i(g.challengeToken),n(""),u(!1);return}}catch{s("Incorrect password. Please try again."),u(!1)}},D=async o=>{if(o.preventDefault(),!(!h||b.length!==6)){s(""),u(!0);try{await l(h,b)}catch{s("Invalid code. Please try again."),n(""),u(!1)}}},L=async o=>{o.preventDefault();const g=v.trim();if(!(!h||!g)){s(""),u(!0);try{await l(h,g)}catch{s("Invalid code. Please try again."),y(""),u(!1)}}};return h?e.jsx("div",{className:"min-h-screen flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8 bg-secondary/30",children:e.jsxs("div",{className:"max-w-md w-full space-y-8 bg-card p-10 rounded-3xl shadow-xl shadow-black/5 border border-border/60",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mx-auto w-12 h-12 bg-primary rounded-xl flex items-center justify-center text-primary-foreground shadow-lg shadow-primary/25 mb-6",children:e.jsx(B,{className:"w-7 h-7"})}),e.jsx("h2",{className:"text-3xl font-display font-bold text-foreground",children:"Two-factor code"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Enter the six-digit code from your authenticator app."})]}),P?e.jsxs("form",{autoComplete:"off",className:"mt-8 space-y-6",onSubmit:L,children:[d&&e.jsx("div",{className:"p-4 rounded-xl bg-destructive/10 text-destructive text-sm font-medium border border-destructive/20",children:d}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold text-foreground mb-1.5",htmlFor:"totp-vendor-recovery",children:"Recovery code"}),e.jsx("input",{id:"totp-vendor-recovery",type:"text",autoComplete:"off",spellCheck:!1,className:"w-full px-4 py-3 rounded-xl bg-background border border-border text-foreground focus:outline-none focus:border-primary focus:ring-4 focus:ring-primary/10 transition-all duration-200",placeholder:"xxxx-xxxx-xxxx-xxxx-xxxx",value:v,onChange:o=>y(o.target.value),autoFocus:!0})]}),e.jsx("button",{type:"submit",disabled:c||!v.trim(),className:"w-full flex justify-center py-3.5 px-4 border border-transparent rounded-xl shadow-lg shadow-primary/20 text-sm font-semibold text-primary-foreground bg-primary hover:bg-primary/90 focus:outline-none focus:ring-4 focus:ring-primary/20 disabled:opacity-70 disabled:cursor-not-allowed transition-all duration-200",children:c?e.jsx(x,{className:"w-5 h-5 animate-spin"}):"Verify"}),e.jsx("button",{type:"button",onClick:()=>{k(!1),y(""),s("")},className:"w-full text-center text-xs font-medium text-muted-foreground hover:text-foreground transition-colors",children:"Use an authenticator code instead"}),e.jsx("button",{type:"button",onClick:()=>{i(null),n(""),y(""),k(!1),s("")},className:"w-full text-center text-xs font-medium text-muted-foreground hover:text-foreground transition-colors",children:"Back to sign in"})]}):e.jsxs("form",{autoComplete:"off",className:"mt-8 space-y-6",onSubmit:D,children:[d&&e.jsx("div",{className:"p-4 rounded-xl bg-destructive/10 text-destructive text-sm font-medium border border-destructive/20",children:d}),e.jsx("div",{className:"flex justify-center",children:e.jsx(A,{autoComplete:"one-time-code",id:"totp-vendor-code",inputMode:"numeric",maxLength:6,name:"totp-code",onChange:o=>
1n(o.replace(/\D/g,"")),pattern:"[0-9]*",value:b,autoFocus:!0,children:e.jsx(z,{children:[0,1,2,3,4,5].map(o=>e.jsx(q,{index:o},o))})})}),e.jsx("button",{type:"submit",disabled:c||b.length!==6,className:"w-full flex justify-center py-3.5 px-4 border border-transparent rounded-xl shadow-lg shadow-primary/20 text-sm font-semibold text-primary-foreground bg-primary hover:bg-primary/90 focus:outline-none focus:ring-4 focus:ring-primary/20 disabled:opacity-70 disabled:cursor-not-allowed transition-all duration-200",children:c?e.jsx(x,{className:"w-5 h-5 animate-spin"}):"Verify"}),e.jsx("button",{type:"button",onClick:()=>{k(!0),n(""),s("")},className:"w-full text-center text-xs font-medium text-muted-foreground hover:text-foreground transition-colors",children:"Use a recovery code instead"}),e.jsx("button",{type:"button",onClick:()=>{i(null),n(""),s("")},className:"w-full text-center text-xs font-medium text-muted-foreground hover:text-foreground transition-colors",children:"Back to sign in"})]})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8 bg-secondary/30",children:e.jsxs("div",{className:"max-w-md w-full space-y-8 bg-card p-10 rounded-3xl shadow-xl shadow-black/5 border border-border/60",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mx-auto w-12 h-12 bg-primary rounded-xl flex items-center justify-center text-primary-foreground shadow-lg shadow-primary/25 mb-6",children:e.jsx(F,{className:"w-7 h-7"})}),e.jsx("h2",{className:"text-3xl font-display font-bold text-foreground",children:"Print Vendor Portal"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Enter the vendor password to access mirror cling files."})]}),e.jsxs("form",{className:"mt-8 space-y-6",onSubmit:E,children:[d&&e.jsx("div",{className:"p-4 rounded-xl bg-destructive/10 text-destructive text-sm font-medium border border-destructive/20",children:d}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold text-foreground mb-1.5",htmlFor:"vendor-password",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{id:"vendor-password",type:p?"text":"password",required:!0,autoFocus:!0,className:"w-full pl-4 pr-11 py-3 rounded-xl bg-background border border-border text-foreground focus:outline-none focus:border-primary focus:ring-4 focus:ring-primary/10 transition-all duration-200",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",value:f,onChange:o=>S(o.target.value)}),e.jsx("button",{type:"button",onClick:()=>C(o=>!o),"aria-label":p?"Hide password":"Show password",className:"absolute inset-y-0 right-3 flex items-center text-muted-foreground hover:text-foreground transition-colors",children:p?e.jsx(M,{className:"w-4 h-4"}):e.jsx(_,{className:"w-4 h-4"})})]})]}),e.jsx("button",{type:"submit",disabled:c,className:"w-full flex justify-center py-3.5 px-4 border border-transparent rounded-xl shadow-lg shadow-primary/20 text-sm font-semibold text-primary-foreground bg-primary hover:bg-primary/90 focus:outline-none focus:ring-4 focus:ring-primary/20 disabled:opacity-70 disabled:cursor-not-allowed transition-all duration-200",children:c?e.jsx(x,{className:"w-5 h-5 animate-spin"}):"Sign in"})]})]})})}function H(){const{logout:m}=I(),[l,f]=r.useState(null),[S,p]=r.useState([]),[C,d]=r.useState(!0),[s,c]=r.useState(""),[u,h]=r.useState(null),[i,b]=r.useState(""),[n,P]=r.useState(""),[k,v]=r.useState(!0),[y,E]=r.useState(""),[D,L]=r.useState(null),[o,g]=r.useState(!1);r.useEffect(()=>{let t=!1;return(async()=>{d(!0),c("");try{const a=await fetch("/api/vendor/orders");if(!a.ok)throw new Error(`listing failed (${a.status})`);const N=await a.json();t||p([...N.orders].sort((w,j)=>new Date(j.createdAt).getTime()-new Date(w.createdAt).getTime()))}catch{t||c("Could not load orders. Please try again.")}finally{t||d(!1)}})(),()=>{t=!0}},[]),r.useEffect(()=>{let t=!1;return(async()=>{v(!0),E("");try{const a=new URLSearchParams;i&&a.set("citySlug",i),n&&a.set("year",n);const N=a.toString(),w=await fetch(`/api/vendor/badges${N?`?${N}`:""}`);if(!w.ok)throw new Error(`listing failed (${w.status})`);const j=await w.json();if(t)return;f(j),!i&&j.cities.length>0&&b(j.cities[0].slug),!n&&j.years.length>0&&P(String(j.years[0]))}catch{t||E("Could not load the badge list. Please try again.")}finally{t||v(!1)}})(),()=>{t=!0}},[i,n]);const O=r.useMemo(()=>l?.badges??[],[l]),U=async t=>{L(t.fileName);try{const a=await fetch(`/api/vendor/badges/mirror/${encodeURIComponent(t.fileName)}`);if(!a.ok)throw new Error(String(a.status));await T(a,t.fileName)}catch{alert("Download failed. Please try again.")}finally{L(null)}},$=async()=>
1{if(!(!i||!n)){g(!0);try{const t=await fetch("/api/vendor/badges/zip",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({citySlug:i,year:Number(n)})});if(!t.ok)throw new Error(String(t.status));await T(t,`mirror-badges-${i}-${n}.zip`)}catch{alert("Zip download failed. Please try again.")}finally{g(!1)}}},V=async t=>{h(t.id),c("");try{const a=await fetch(`/api/vendor/orders/${encodeURIComponent(t.id)}/zip`);if(!a.ok)throw new Error(String(a.status));await T(a,`${t.id}.zip`)}catch{c(`Could not download "${t.name}". Please try again.`)}finally{h(null)}};return e.jsx("div",{className:"min-h-screen bg-secondary/30 py-10 px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:"max-w-3xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary rounded-xl flex items-center justify-center text-primary-foreground shadow-lg shadow-primary/25",children:e.jsx(F,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-display font-bold text-foreground",children:"Print Vendor Portal"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Mirror cling files (print-ready PDF with bleed)"})]})]}),e.jsxs("button",{onClick:()=>{m()},className:"inline-flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(Y,{className:"w-4 h-4"})," Sign out"]})]}),e.jsxs("section",{className:"bg-card rounded-2xl border border-border/60 shadow-sm mb-6 overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border/60",children:[e.jsx("h2",{className:"text-lg font-display font-bold text-foreground",children:"Orders"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Download complete, print-ready order packages."})]}),s&&e.jsx("div",{className:"mx-6 mt-5 p-3 rounded-xl bg-destructive/10 text-destructive text-sm font-medium border border-destructive/20",children:s}),e.jsx("div",{className:"divide-y divide-border/60",children:C?e.jsx("div",{className:"p-8 flex justify-center text-muted-foreground",children:e.jsx(x,{className:"w-5 h-5 animate-spin"})}):S.length===0?e.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:"No orders are available yet."}):S.map(t=>{const a=t.lines.reduce((N,w)=>N+w.qty,0);return e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-6 py-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:t.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[t.city," · ",t.year," · ",t.lines.length," ",t.lines.length===1?"design":"designs"," ·"," ",a," total"]})]}),e.jsxs("button",{type:"button",onClick:()=>{V(t)},disabled:u===t.id,className:"inline-flex shrink-0 items-center justify-center gap-2 py-2.5 px-4 rounded-xl text-sm font-semibold text-primary-foreground bg-primary hover:bg-primary/90 disabled:opacity-60 disabled:cursor-not-allowed shadow-lg shadow-primary/20 transition-all",children:[u===t.id?e.jsx(x,{className:"w-4 h-4 animate-spin"}):e.jsx(R,{className:"w-4 h-4"}),"Download order"]})]},t.id)})})]}),e.jsx("div",{className:"bg-card rounded-2xl border border-border/60 shadow-sm p-6 mb-6",children:e.jsxs("div",{className:"flex flex-wrap items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold text-foreground mb-1.5",htmlFor:"vendor-city",children:"City"}),e.jsx("select",{id:"vendor-city",value:i,onChange:t=>b(t.target.value),className:"px-4 py-2.5 rounded-xl bg-background border border-border text-foreground focus:outline-none focus:border-primary",children:(l?.cities??[]).map(t=>e.jsx("option",{value:t.slug,children:t.name},t.slug))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold text-foreground mb-1.5",htmlFor:"vendor-year",children:"Year"}),e.jsx("select",{id:"vendor-year",value:n,onChange:t=>P(t.target.value),className:"px-4 py-2.5 rounded-xl bg-background border border-border text-foreground focus:outline-none focus:border-primary",children:(l?.years??[]).map(t=>e.jsx("option",{value:String(t),children:t},t))})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs("button",{onClick:()=>{$()},disabled:o||O.length===0||!i||!n,className:"inline-flex items-center gap-2 py-2.5 px-5 rounded-xl text-sm font-semibold text-primary-foreground bg-primary hover:bg-primary/90 disabled:opacity-60 disabled:cursor-not-allowed shadow-lg shadow-primary/20 transition-all",children:[o?e.jsx(x,{className:"w-4 h-4 animate-spin"}):e.jsx(R,{className:"w-4 h-4"}),"Download All (",O.length,")"]})})]})}),y&&e.jsx("div",{className:"p-4 mb-6 rounded-xl bg-destructive/10 text-destructive text-sm font-medium border border-destructive/20",children:y}),e.jsx("div",{className:"bg-card rounded-2xl border border-border/60 shadow-sm divide-y divide-border/60",children:k?e.jsx("div",{className:"p-10 flex justify-center text-muted-foreground",children:e.jsx(x,{className:"w-6 h-6 animate-spin"})}):O.length===0?e.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:"No badges available for this city and year."}):O.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-4 px-6 py-3.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:t.categoryName}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:t.fileName})]}),e.jsxs("button",{onClick:()=>{U(t)},disabled:D===t.fileName,className:"inline-flex shrink-0 items-center gap-1.5 py-2 px-3.5 rounded-lg text-xs font-semibold text-foreground bg-secondary hover:bg-secondary/70 border border-border disabled:opacity-60 transition-colors",children:[D===t.fileName?e.jsx(x,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(R,{className:"w-3.5 h-3.5"}),"PDF"]})]},t.fileName))})]})})}function ae(){const{user:m,isLoading:l,logout:f}=I();return l?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-secondary/30",children:e.jsx(x,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):m?m.role!=="print_vendor"&&m.role!=="super_admin"?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-secondary/30 px-4",children:e.jsxs("div",{className:"max-w-md w-full bg-card p-10 rounded-3xl border border-border/60 text-center space-y-4",children:[e.jsx("h2",{className:"text-xl font-display font-bold text-foreground",children:"No vend
1or access"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This account does not have access to the print vendor portal."}),e.jsx("button",{onClick:()=>{f()},className:"inline-flex items-center gap-2 py-2.5 px-5 rounded-xl text-sm font-semibold text-primary-foreground bg-primary hover:bg-primary/90",children:"Sign out"})]})}):e.jsx(H,{}):e.jsx(G,{})}export{ae as VendorPortalPage};
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.