1import{e as E,b as J,p as W,v as Z,r as n,f as C,i as P,j as e,o as F,B as l,X as ee,I as se,aO as ae,F as te,K as re}from"./index-QiiZ-xPT.js";import{C as o,b as p,c as u,d as h,a as d}from"./card-DkXabqFf.js";import{L as A}from"./label-BA9Xin3m.js";import{T as ie}from"./textarea-Bd1mcSz8.js";import{P as ne}from"./progress-DXmmueuD.js";import{B as f}from"./badge-IOHUIid2.js";import{S as le}from"./separator-CYvreNsY.js";import{L as T}from"./lock-NaFetfNF.js";import{U}from"./upload-CAzUZUXS.js";import{F as B}from"./file-iWAV_ydE.js";import{D as oe}from"./download-D-fGOqS3.js";import{C as K}from"./clock-Jb0c5sRN.js";import{F as de}from"./file-spreadsheet-BnlNt_wA.js";import{C as ce}from"./circle-alert-BZ1suj-l.js";import{f as z}from"./format-B1OombNw.js";import"./en-US-BddybvhD.js";const me=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],xe=E("archive",me);const pe=[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],ue=E("cloud-upload",pe);function q(a){const r=a.toLowerCase();return["csv","xlsx","xls"].includes(r)?e.jsx(de,{className:"h-5 w-5 text-green-500"}):["zip","tar","gz"].includes(r)?e.jsx(xe,{className:"h-5 w-5 text-purple-500"}):e.jsx(te,{className:"h-5 w-5 text-blue-500"})}function I(a){return a<1024?a+" B":a<1024*1024?(a/1024).toFixed(1)+" KB":(a/(1024*1024)).toFixed(1)+" MB"}function he(a){switch(a){case"uploaded":return e.jsxs(f,{variant:"default",className:"bg-green-600",children:[e.jsx(re,{className:"h-3 w-3 mr-1"})," Uploaded"]});case"processing":return e.jsxs(f,{variant:"secondary",children:[e.jsx(K,{className:"h-3 w-3 mr-1"})," Processing"]});case"failed":return e.jsxs(f,{variant:"destructive",children:[e.jsx(ce,{className:"h-3 w-3 mr-1"})," Failed"]});default:return e.jsx(f,{variant:"outline",children:a})}}function Ae(){const[,a]=J(),{toast:r}=W(),$=Z(),[_,j]=n.useState(!1),[i,c]=n.useState(null),[D,k]=n.useState(""),[g,m]=n.useState(0),{data:N,isLoading:R}=C({queryKey:["/api/auth/user"]}),{data:y,isLoading:Y}=C({queryKey:["/api/data-portal/access"],enabled:!!N}),{data:S=[],isLoading:O}=C({queryKey:["/api/data-portal/uploads"],enabled:!!N&&y?.hasAccess}),v=P({mutationFn:async s=>{const t=new FormData;t.append("file",s),t.append("description",D);const b=await fetch("/api/data-portal/upload",{method:"POST",body:t,credentials:"include"});if(!b.ok){const X=await b.json();throw new Error(X.message||"Upload failed")}return b.json()},onSuccess:()=>{r({title:"Upload successful",description:"Your file has been securely uploaded."}),c(null),k(""),m(0),$.invalidateQueries({queryKey:["/api/data-portal/uploads"]})},onError:s=>{r({title:"Upload failed",description:s.message,variant:"destructive"}),m(0)}}),M=P({mutationFn:async s=>(await ae("GET",`/api/data-portal/download/${s}`)).json(),onSuccess:s=>{window.open(s.url,"_blank")},onError:()=>{r({title:"Download failed",description:"Could not generate download link",variant:"destructive"})}}),w=n.useCallback(s=>{s.preventDefault(),s.stopPropagation(),s.type==="dragenter"||s.type==="dragover"?j(!0):s.type==="dragleave"&&j(!1)},[]),Q=n.useCallback(s=>{s.preventDefault(),s.stopPropagation(),j(!1),s.dataTransfer.files&&s.dataTransfer.files[0]&&c(s.dataTransfer.files[0])},[]),G=s=>{s.target.files&&s.target.files[0]&&c(s.target.files[0])},H=()=>{if(i){m(10);const s=setInterval(()=>{m(t=>t>=90?(clearInterval(s),t):t+10)},200);v.mutate(i)}};if(R||Y)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(F,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!N)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-900 to-slate-800",children:e.jsxs(o,{className:"max-w-md w-full mx-4",children:[e.jsxs(p,{className:"text-center",children:[e.jsx(T,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx(u,{children:"Sign In Required"}),e.jsx(h,{children:"Please sign in to access the data portal"})]}),e.jsx(d,{children:e.jsx(l,{className:"w-full",onClick:()=>a("/login"),"data-testid":"button-login",children:"Sign In"})})]})});if(!y?.hasAccess)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-900 to-slate-800",children:e.jsxs(o,{className:"max-w-md w-full mx-4",children:[e.jsxs(p,{className:"text-center",children:[e.jsx(T,{className:"h-12 w-12 mx-auto text-red-500 mb-4"}),e.jsx(u,{children:"Access Restricted"}),e.jsx(h,{children:"You don't have permission to upload data. Please contact your administrator to request access."})]}),e.jsx(d,{children:e.jsx(l,{variant:"outline",className:"w-full",onClick:()=>a("/dashboard"),"data-testid":"button-back-dashboard",children:"Back to Dashboard"})})]})});const x=y.access,L=x.allowedTypes||[],V=Math.round((x.maxFileSize||104857600)/1024/1024);return e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-slate-900 to-slate-800 py-12",children:e.jsxs("div",{className:"container mx-auto px-4 max-w-4xl",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold text-white mb-2",children:"Data Portal"}),e.jsx("p",{className:"text-slate-400",children:"Securely upload your data files to Living Corporate"})]}),e.jsxs("div",{className:"grid gap-6",children:[e.jsxs(o,{children:[e.jsxs(p,{children:[e.jsxs(u,{className:"flex items-center gap-2",children:[e.jsx(ue,{className:"h-5 w-5"}),"Upload Files"]}),e.jsxs(h,{children:["Drag and drop files or click to browse. Max size: ",V,"MB. Allowed types: ",L.join(", ")
1]})]}),e.jsx(d,{children:e.jsx("div",{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${_?"border-primary bg-primary/10":"border-muted-foreground/25 hover:border-muted-foreground/50"}`,onDragEnter:w,onDragLeave:w,onDragOver:w,onDrop:Q,"data-testid":"dropzone",children:i?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[q(i.name.split(".").pop()||""),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-medium",children:i.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:I(i.size)})]}),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>c(null),"data-testid":"button-remove-file",children:e.jsx(ee,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"max-w-md mx-auto space-y-4",children:[e.jsxs("div",{children:[e.jsx(A,{htmlFor:"description",children:"Description (optional)"}),e.jsx(ie,{id:"description",placeholder:"Add a description for this upload...",value:D,onChange:s=>k(s.target.value),className:"mt-1","data-testid":"input-description"})]}),g>0&&g<100&&e.jsx(ne,{value:g,className:"h-2"}),e.jsx(l,{className:"w-full",onClick:H,disabled:v.isPending,"data-testid":"button-upload",children:v.isPending?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}),"Uploading..."]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"h-4 w-4 mr-2"}),"Upload File"]})})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(U,{className:"h-12 w-12 mx-auto text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-medium",children:"Drop files here"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"or click to browse"})]}),e.jsx(se,{type:"file",className:"hidden",id:"file-upload",onChange:G,accept:L.map(s=>`.${s}`).join(","),"data-testid":"input-file"}),e.jsx(A,{htmlFor:"file-upload",className:"cursor-pointer",children:e.jsx(l,{variant:"secondary",asChild:!0,children:e.jsx("span",{children:"Select File"})})})]})})})]}),e.jsxs(o,{children:[e.jsxs(p,{children:[e.jsxs(u,{className:"flex items-center gap-2",children:[e.jsx(B,{className:"h-5 w-5"}),"Your Uploads"]}),e.jsx(h,{children:"Files you've uploaded to the data portal"})]}),e.jsx(d,{children:O?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):S.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(B,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No uploads yet"})]}):e.jsx("div",{className:"space-y-3",children:S.map((s,t)=>e.jsxs("div",{children:[t>0&&e.jsx(le,{className:"my-3"}),e.jsxs("div",{className:"flex items-center gap-4",children:[q(s.fileType),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate","data-testid":`text-filename-${s.id}`,children:s.originalName}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("span",{children:I(s.fileSize)}),e.jsx("span",{children:"â¢"}),e.jsx("span",{children:z(new Date(s.uploadedAt),"MMM d, yyyy h:mm a")})]}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[he(s.status),e.jsx(l,{variant:"ghost",size:"sm",onClick:()=>M.mutate(s.id),disabled:M.isPending,"data-testid":`button-download-${s.id}`,children:e.jsx(oe,{className:"h-4 w-4"})})]})]})]},s.id))})})]}),x.expiresAt&&e.jsx(o,{className:"border-yellow-500/50 bg-yellow-500/5",children:e.jsxs(d,{className:"flex items-center gap-3 py-4",children:[e.jsx(K,{className:"h-5 w-5 text-yellow-500"}),e.jsxs("p",{className:"text-sm",children:["Your upload access expires on"," ",e.jsx("strong",{children:z(new Date(x.expiresAt),"MMMM d, yyyy")})]})]})})]})]})})}export{Ae 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.