1import{r as o,j as e,A as W,m as T,X,U as G,F as V,d as J}from"./index-BLshS733.js";const ee=({isOpen:R,onClose:E,onImport:M,currency:K})=>{const[Q,p]=o.useState(null),[$,f]=o.useState(!1),[x,l]=o.useState("idle"),[Y,c]=o.useState(""),[y,v]=o.useState([]),[m,b]=o.useState([]),g=o.useRef(null),N=()=>{p(null),l("idle"),c(""),v([]),b([]),g.current&&(g.current.value="")},u=()=>{N(),E()},P=s=>{s.preventDefault(),f(!0)},q=()=>{f(!1)},B=s=>{if(s.preventDefault(),f(!1),s.dataTransfer.files&&s.dataTransfer.files[0]){const a=s.dataTransfer.files[0];a.type==="text/csv"||a.name.endsWith(".csv")?(p(a),k(a)):(c("Please upload a CSV file"),l("error"))}},H=s=>{if(s.target.files&&s.target.files[0]){const a=s.target.files[0];a.type==="text/csv"||a.name.endsWith(".csv")?(p(a),k(a)):(c("Please upload a CSV file"),l("error"))}},k=s=>{l("processing"),c(""),b([]);const a=new FileReader;a.onload=O=>{var F;try{const h=((F=O.target)==null?void 0:F.result).split(` 2`).filter(r=>r.trim()!=="");if(h.length<2)throw new Error("CSV file is empty or invalid");const j=h[0].split(",").map(r=>r.trim().toLowerCase()),C=["date","name","category","amount","type"].filter(r=>!j.includes(r));if(C.length>0)throw new Error(`Missing required columns: ${C.join(", ")}`);const S=[],i=[];for(let r=1;r<h.length;r++){const D=h[r].split(",");if(D.length!==j.length){i.push(`Row ${r+1}: Column count mismatch`);continue}const t={};let d=!1;j.forEach((U,z)=>{var A;const n=((A=D[z])==null?void 0:A.trim())||"";switch(U){case"date":/^\d{4}-\d{2}-\d{2}$/.test(n)||(i.push(`Row ${r+1}: Invalid date format. Expected YYYY-MM-DD, got "${n}"`),d=!0),t.date=n;break;case"name":n||(i.push(`Row ${r+1}: Name is required`),d=!0),t.name=n;break;case"category":t.category=n||"Uncategorized";break;case"amount":const I=parseFloat(n);isNaN(I)&&(i.push(`Row ${r+1}: Invalid amount "${n}"`),d=!0),t.amount=I;break;case"type":n!=="income"&&n!=="expense"&&(i.push(`Row ${r+1}: Type must be "income" or "expense", got "${n}"`),d=!0),t.type=n;break;case"accountid":t.accountId=n||void 0;break;case"comments":t.comments=n||void 0;break;default:break}}),!d&&t.amount&&t.type&&(t.type==="income"&&t.amount<0?t.amount=Math.abs(t.amount):t.type==="expense"&&t.amount>0&&(t.amount=-Math.abs(t.amount))),d||S.push(t)}if(i.length>0){b(i),l("error");return}v(S),l("success")}catch(w){c(w.message||"Failed to parse CSV file"),l("error")}},a.onerror=()=>{c("Failed to read file"),l("error")},a.readAsText(s)},L=()=>{y.length>0&&(M(y),u())};return e.jsx(W,{children:R&&e.jsx(T.div,{className:"fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50",initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},children:e.jsxs(T.div,{className:"bg-white dark:bg-[#242424] rounded-lg p-6 w-full max-w-md",initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-[#F5F5F5]",children:"Import Transactions"}),e.jsx("button",{onClick:u,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-[#2A2A2A] text-gray-500 dark:text-[#888888]",children:e.jsx(X,{className:"h-5 w-5"})})]}),x==="idle"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${$?"border-[#007BFF] bg-[#007BFF]/10":"border-gray-300 dark:border-gray-600 hover:border-[#007BFF]"}`,onDragOver:P,onDragLeave:q,onDrop:B,onClick:()=>{var s;return(s=g.current)==null?void 0:s.click()},children:[e.jsx(G,{className:"h-12 w-12 mx-auto text-gray-400 dark:text-[#888888] mb-4"}),e.jsx("p",{className:"text-gray-700 dark:text-[#F5F5F5] font-medium mb-1",children:"Drag & drop your CSV file"}),e.jsx("p",{className:"text-gray-500 dark:text-[#888888] text-sm mb-4",children:"or click to browse files"}),e.jsx("p",{className:"text-gray-400 dark:text-[#888888] text-xs",children:"Supported format: CSV"}),e.jsx("input",{type:"file",ref:g,className:"hidden",accept:".csv,text/csv",onChange:H})]}),e.jsxs("div",{className:"bg-gray-100 dark:bg-[#1A1A1A] rounded-lg p-4",children:[e.jsxs("h3",{className:"font-medium text-gray-900 dark:text-[#F5F5F5] mb-2 flex items-center",children:[e.jsx(V,{className:"h-4 w-4 mr-2"}),"CSV Format Requirements"]}),e.jsxs("ul",{className:"text-sm text-gray-600 dark:text-[#888888] space-y-1",children:[e.jsx("li",{children:"⢠Required columns: Date, Name, Category, Amount, Type"}),e.jsx("li",{children:"⢠Date format: YYYY-MM-DD"}),e.jsx("li",{children:"⢠Amount: Numeric values (positive or negative)"}),e.jsx("li",{children:'⢠Type: "income" or "expense"'}),e.jsx("li",{children:"⢠Optional columns: AccountId, Comments"})]})]})]}),x==="processing"&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"inline-block animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-[#007BFF] mb-4"}),e.jsx("p",{className:"text-gray-700 dark:text-[#F5F5F5] font-medium",children:"Processing your CSV file..."}),e.jsx("p",{className:"text-gray-500 dark:text-[#888888] text-sm",children:"Validating data and preparing transactions"})]}),x==="success"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center py-4",children:[e.jsx("div",{className:"inline-flex items-center justify-center h-12 w-12 rounded-full bg-green-100 dark:bg-green-900/30 mb-4",children:e.jsx(V,{className:"h-6 w-6 text-green-600 dark:text-green-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-[#F5F5F5] mb-1",children:"File Parsed Successfully"}),e.jsxs("p",{className:"text-gray-600 dark:text-[#888888]",children:["Found ",y.length," valid transactions"]})]}),e.jsxs("div",{className:"bg-green-50 dark:bg-green-900/20 rounded-lg p-4",children:[e.jsx("h4",{className:"font-medium text-green-800 dark:text-green-200 mb-2",children:"Ready to Import"}),e.jsx("p",{className:"text-green-700 dark:text-green-300 text-sm",children:"All transactions have been validated and are ready to be imported into your account."})]}),e.jsxs("div",{className:"flex space-x-3",children:[e.jsx("button",{onClick:u,className:"flex-1 py-2 px-4 bg-gray-200 dark:bg-gray-600 hover:bg-gray-300 dark:hover:bg-gray-500 text-gray-900 dark:text-[#F5F5F5] rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{onClick:L,className:"flex-1 py-2 px-4 bg-[#007BFF] hover:bg-[#0056b3] text-white rounded-lg transition-colors",children:"Import Transactions"})]})]}),(x==="error"||m.length>0)&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"text-center py-4",children:[e.jsx("div",{className:"inline-flex items-center justify-center h-12 w-12 rounded-full bg-red-100 dark:bg-red-900/30 mb-4",children:e.jsx(J,{className:"h-6 w-6 text-red-600 dark:text-red-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-[#F5F5F5] mb-1",children:"Import Failed"}),e.jsx("p",{className:"text-gray-600 dark:text-[#888888]",children:Y||"Please fix the following issues:"})]}),m.length>0&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 rounded-lg p-4 max-h-40 overflow-y-auto",children:[e.jsx("h4",{className:"font-medium text-red-800 dark:text-red-200 mb-2",children:"Validation Errors"}),e.jsxs("ul",{className:"text-red-700 dark:text-red-300 text-sm space-y-1",children:[m.slice(0,10).map((s,a)=>e.jsxs("li",{className:"flex items-start",children:[e.jsx("span",{className:"mr-2",children:"â¢"}),e.jsx("span",{children:s})]},a)),m.length>10&&e.jsxs("li",{className:"font-medium",children:["... and ",m.length-10," more errors"]})]})]}),e.jsxs("div",{className:"flex space-x-3",children:[e.jsx("button",{onClick:N,className:"flex-1 py-2 px-4 bg-gray-200 dark:bg-gray-600 hover:bg-gray-300 dark:hover:bg-gray-500 text-gray-900 dark:text-[#F5F5F5] rounded-lg transition-colors",children:"Try Again"}),e.jsx("button",{onClick:u,className:"flex-1 py-2 px-4 bg-[#007BFF] hover:bg-[#0056b3] text-white rounded-lg transition-colors",children:"Close"})]})]})]})})})};export{ee 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.