1import{d4 as _,ax as A,e4 as G,e5 as H,r,j as e,bQ as $,L as O,K as D,J as y,as as p,df as z,cI as K,cf as Q,cg as Y,ch as Z,ci as ee,cj as se,N as te,av as re,aI as b}from"./index-CpeGhXo5.js";import{a as ae,P as S}from"./Panel-Cf_wAUzv.js";import{mapRevenueRows as oe,REVENUE_IMPORT_FIELDS as M,downloadSampleCsv as le,parseCSV as P,autoMapRevenueHeaders as ne,REVENUE_SAMPLE_CSV as de}from"./financeImportParse-DTb6d-yn.js";import{F as ie,S as ce}from"./FinanceEmployeeReferenceButton-BGuo0qvJ.js";import{a as me}from"./employeeImportParse-C0zECibb.js";import"./excelUtils-B6c4w-tr.js";import"./financeEmployeeDisplay-CYwTzdnu.js";function je(){const l=_(),g=A(),x=G(s=>s.addJob),[f,{isLoading:C}]=H(),[a,n]=r.useState(1),[u,R]=r.useState("file"),[j,F]=r.useState([]),[d,V]=r.useState([]),[h,U]=r.useState(""),[v,B]=r.useState(""),[i,I]=r.useState({}),E=r.useRef(null),N=(s,t,o)=>{F(s),V(t),U(o),I(ne(s))},X=async s=>{if(!s)return;const t=s.name.split(".").pop()?.toLowerCase();if(t==="csv"){const o=await s.text(),{headers:L,rows:m}=P(o);N(L,m,s.name),n(2);return}if(t==="xlsx"||t==="xls"){const o=await s.arrayBuffer(),m=me(o)[0];if(!m?.headers.length){b.error("No data found in workbook");return}N(m.headers,m.rows,s.name),n(2);return}b.error("Use CSV, XLSX, or XLS")},q=()=>{if(!v)return;const{headers:s,rows:t}=P(de);N(s,t,"Google Sheet · Revenue"),n(2)},{valid:c,invalid:w}=r.useMemo(()=>oe(j,d,i),[j,d,i]),J=r.useMemo(()=>c.slice(0,5),[c]),T=r.useMemo(()=>M.filter(s=>s.required).every(s=>i[s.key]),[i]),W=async()=>{try{const s=await f({rows:c,fileName:h||"Revenue import"}).unwrap();x({id:s.jobId,type:"finance-revenue-import",title:h||"Revenue import",status:"queued",progress:0,total:s.total,importPath:`${l}/revenue/import`}),b.success("Import started in background. Track progress in the panel at bottom right."),g(`${l}/revenue`)}catch(s){b.error(s?.data?.message||s?.message||"Import failed")}};return e.jsxs("div",{className:"p-3 flex flex-col gap-3 min-h-full overflow-auto",children:[e.jsx(ae,{title:"Import Revenue Data",subtitle:"Download the sample template, fill columns, then upload â duplicates are skipped automatically",accent:"mod-revenue",actions:e.jsxs(e.Fragment,{children:[e.jsx(ie,{variant:"compact"}),e.jsxs("button",{onClick:()=>le("revenue"),className:"h-7 px-2.5 rounded-[4px] border border-border bg-card hover:bg-accent text-[11px] font-medium inline-flex items-center gap-1.5",children:[e.jsx($,{className:"w-3.5 h-3.5"})," Sample template"]}),e.jsxs(O,{to:`${l}/revenue`,className:"h-7 px-2.5 rounded-[4px] border border-border bg-card hover:bg-accent text-[11px] font-medium inline-flex items-center gap-1.5",children:[e.jsx(D,{className:"w-3.5 h-3.5"})," Back"]})]})}),e.jsx("div",{className:"flex items-center gap-2 bg-card border border-border rounded-[6px] px-3 py-2",children:[{n:1,label:"Source"},{n:2,label:"Map columns"},{n:3,label:"Review & Import"}].map(({n:s,label:t},o)=>e.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[e.jsx("div",{className:p("w-6 h-6 rounded-full grid place-items-center text-[11px] font-semibold",a>=s?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:a>s?e.jsx(y,{className:"w-3.5 h-3.5"}):s}),e.jsx("div",{className:p("text-[12px]",a===s?"font-semibold":"text-muted-foreground"),children:t}),o<2&&e.jsx("div",{className:"flex-1 h-px bg-border"})]},s))}),a===1&&e.jsxs(S,{title:"Step 1 · Choose source",accent:"mod-revenue",children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground px-1 mb-3",children:["Download ",e.jsx("strong",{children:"Employee reference"})," for your org's Employee ID + exact names. When filling employee or sales person columns, use both values from that file â leave blank if not applicable."]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 p-1",children:[e.jsxs("button",{onClick:()=>R("file"),className:p("rounded-[6px] border p-4 text-left transition-colors",u==="file"?"border-primary bg-primary/5":"border-border hover:bg-accent"),children:[e.jsx(z,{className:"w-5 h-5 text-primary mb-2"}),e.jsx("div",{className:"text-[13px] font-semibold",children:"Upload CSV / Excel"}),e.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:"CSV, XLSX, or XLS"})]}),e.jsxs("button",{onClick:()=>R("sheets"),className:p("rounded-[6px] border p-4 text-left transition-colors",u==="sheets"?"border-primary bg-primary/5":"border-border hover:bg-accent"),children:[e.jsx(ce,{className:"w-5 h-5 text-emerald-600 mb-2"}),e.jsx("div",{className:"text-[13px] font-semibold",children:"Google Sheets"}),e.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:"Paste a public sheet URL"})]})]}),u==="file"&&e.jsxs("div",{className:"mt-3 p-1",children:[e.jsx("input",{ref:E,type:"file",accept:".csv,.xlsx,.xls,text/csv",className:"hidden",onChange:s=>X(s.target.files?.[0])}),e.jsxs("div",{onClick:()=>E.current?.click(),className:"cursor-pointer border border-dashed border-border rounded-[6px] p-6 text-center hover:bg-accent/40",children:[e.jsx(K,{className:"w-6 h-6 mx-auto text-muted-foreground"}),e.jsx("div",{className:"text-[12px] mt-2 font-medium",children:"Click to choose a file"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Download template first for correct columns"})]}),h&&e.jsxs("div",{className:"mt-2 text-[11px] text-emerald-600 inline-flex items-center gap-1.5",children:[e.jsx(y,{className:"w-3.5 h-3.5"})," ",h," · ",d.length," rows"]})]}),u==="sheets"&&e.jsxs("div",{className:"mt-3 p-1 space-y-2",children:[e.jsx("input",{value:v,onCh
1ange:s=>B(s.target.value),placeholder:"https://docs.google.com/spreadsheets/d/â¦",className:"h-8 px-2 w-full rounded-[4px] border border-border bg-background text-[12px]"}),e.jsx("button",{onClick:q,disabled:!v,className:"h-8 px-3 rounded-[4px] bg-primary text-primary-foreground text-[12px] font-medium disabled:opacity-40",children:"Load preview"})]})]}),a===2&&e.jsx(S,{title:"Step 2 · Map columns",accent:"mod-revenue",children:e.jsx("div",{className:"grid gap-2 p-1 max-h-[420px] overflow-y-auto",children:M.map(s=>e.jsxs("div",{className:"grid grid-cols-[1fr,1fr] gap-2 items-center",children:[e.jsxs("span",{className:"text-[11px] font-medium",children:[s.label,s.required&&e.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),e.jsxs(Q,{value:i[s.key]??"",onValueChange:t=>I(o=>({...o,[s.key]:t})),children:[e.jsx(Y,{className:"h-8 text-[11px]",children:e.jsx(Z,{placeholder:"Select column"})}),e.jsx(ee,{children:j.map(t=>e.jsx(se,{value:t,className:"text-[11px]",children:t},t))})]})]},s.key))})}),a===3&&e.jsxs(S,{title:"Step 3 · Review & Import",accent:"mod-revenue",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 p-1",children:[e.jsx(k,{label:"Total rows",value:d.length,tone:"neutral"}),e.jsx(k,{label:"Will import",value:c.length,tone:"positive"}),e.jsx(k,{label:"Skipped / invalid",value:w.length,tone:"warning"})]}),w.length>0&&e.jsxs("p",{className:"text-[10px] text-amber-700 px-1 mt-2",children:[w.length," row(s) will not be imported due to validation errors (missing fields or employee name/ID mismatch)."]}),e.jsx("div",{className:"mt-3 px-1 overflow-auto",children:e.jsxs("table",{className:"w-full text-[11px] border border-border rounded-[4px]",children:[e.jsx("thead",{className:"bg-muted/60",children:e.jsx("tr",{children:["Date","Invoice","Client","Employee","Emp ID","Gross"].map(s=>e.jsx("th",{className:"text-left px-2 py-1 font-semibold text-[10px] uppercase text-muted-foreground",children:s},s))})}),e.jsx("tbody",{children:J.map((s,t)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-2 py-1",children:s.entryDate}),e.jsx("td",{className:"px-2 py-1",children:s.invoiceNo}),e.jsx("td",{className:"px-2 py-1",children:s.clientName}),e.jsx("td",{className:"px-2 py-1",children:s.employeeName||"â"}),e.jsx("td",{className:"px-2 py-1 font-mono",children:s.employeeEmpCode||"â"}),e.jsx("td",{className:"px-2 py-1",children:s.gross})]},t))})]})})]}),e.jsxs("div",{className:"flex items-center justify-between bg-card border border-border rounded-[6px] px-3 py-2",children:[e.jsxs("button",{disabled:a===1,onClick:()=>n(s=>s>1?s-1:s),className:"h-8 px-3 rounded-[4px] border border-border text-[12px] font-medium inline-flex items-center gap-1.5 disabled:opacity-40",children:[e.jsx(D,{className:"w-3.5 h-3.5"})," Back"]}),a<3?e.jsxs("button",{onClick:()=>n(s=>s+1),disabled:a===1&&d.length===0||a===2&&!T,className:"h-8 px-3 rounded-[4px] bg-primary text-primary-foreground text-[12px] font-medium inline-flex items-center gap-1.5 disabled:opacity-40",children:["Continue ",e.jsx(te,{className:"w-3.5 h-3.5"})]}):e.jsxs("button",{disabled:c.length===0||C,onClick:W,className:"h-8 px-3 rounded-[4px] bg-emerald-600 text-white text-[12px] font-medium inline-flex items-center gap-1.5 disabled:opacity-40",children:[C?e.jsx(re,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(y,{className:"w-3.5 h-3.5"}),"Start background import"]})]})]})}function k({label:l,value:g,tone:x}){const f=x==="positive"?"text-emerald-600 bg-emerald-500/10 border-emerald-500/30":x==="warning"?"text-amber-600 bg-amber-500/10 border-amber-500/30":"text-foreground bg-muted border-border";return e.jsxs("div",{className:p("rounded-[6px] border p-3",f),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider opacity-80",children:l}),e.jsx("div",{className:"text-[20px] font-bold font-data tabular-nums",children:g})]})}export{je as ImportWizardPage};
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.