@fileflow/sdk 0.1.24 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,7 +53,7 @@
53
53
  *
54
54
  * This source code is licensed under the ISC license.
55
55
  * See the LICENSE file in the root directory of this source tree.
56
- */const $t=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],Nt=w.createLucideIcon("trash-2",$t),Ae={sessionId:null,status:"idle",step:"upload",schema:null,file:null,fileName:null,fileSize:null,headers:[],rows:[],totalRows:0,sampleRows:[],mappings:[],unmappedSource:[],unmappedTarget:[],validationResults:null,errorsByRow:new Map,isLoading:!1,error:null,editingCell:null,editedRows:new Set};function Mt(e,o){var r;const t=[],n=(e==null?void 0:e.trim())||"";if(o.required&&!n)return t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"required",message:`${o.label} is required`}),t;if(!n)return t;switch(o.type){case"email":{if(!/^[^\s@]+@[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/.test(n))t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"type",message:"Invalid email format"});else{const i=(r=n.split("@")[1])==null?void 0:r.toLowerCase(),a={"gmial.com":"gmail.com","gmal.com":"gmail.com","gmai.com":"gmail.com","gamil.com":"gmail.com","gnail.com":"gmail.com","gmail.co":"gmail.com","gmail.cm":"gmail.com","gmil.com":"gmail.com","gmaill.com":"gmail.com","yaho.com":"yahoo.com","yahooo.com":"yahoo.com","yahoo.co":"yahoo.com","hotmal.com":"hotmail.com","hotmial.com":"hotmail.com","hotmai.com":"hotmail.com","hotmail.co":"hotmail.com","outlok.com":"outlook.com","outloo.com":"outlook.com","outlook.co":"outlook.com"};i&&a[i]&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:"warning",validatorType:"type",message:`Possible typo: did you mean @${a[i]}?`,suggestion:`${n.split("@")[0]}@${a[i]}`})}break}case"url":/^https?:\/\/.+/.test(n)||t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"type",message:"Invalid URL format"});break;case"integer":/^-?\d+$/.test(n)||t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"type",message:"Must be a whole number"});break;case"number":case"float":/^-?\d+(\.\d+)?$/.test(n)||t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"type",message:"Must be a valid number"});break;case"phone":n.replace(/\D/g,"").length<10&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:"warning",validatorType:"type",message:"Invalid phone number"});break}if(o.validators)for(const s of o.validators){const i=s.severity==="info"?"warning":s.severity||"error",a=s.params||{};switch(s.type){case"minLength":{const f=a.value??0;n.length<f&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be at least ${f} characters`});break}case"maxLength":{const f=a.value??1/0;n.length>f&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be at most ${f} characters`});break}case"min":{const f=parseFloat(n),d=a.value??-1/0;!isNaN(f)&&f<d&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be at least ${d}`});break}case"max":{const f=parseFloat(n),d=a.value??1/0;!isNaN(f)&&f>d&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be at most ${d}`});break}case"pattern":{const f=a.regex??a.pattern??".*";new RegExp(f).test(n)||t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||"Format is invalid"});break}case"enum":{const f=a.values||[];f.map(p=>p.toLowerCase()).includes(n.toLowerCase())||t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be one of: ${f.slice(0,5).join(", ")}${f.length>5?"...":""}`});break}case"custom":{const f=a.validatorName;if(f==="commaSeparatedEnum"){const d=a.allowedValues||[],p=n.split(",").map(u=>u.trim().toLowerCase()).filter(u=>u),g=d.map(u=>u.toLowerCase()),c=p.filter(u=>!g.includes(u));c.length>0&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Invalid values: ${c.join(", ")}. Must be comma-separated values from: ${d.slice(0,5).join(", ")}${d.length>5?"...":""}`})}if(f==="commaSeparatedEmails"){const p=n.split(",").map(g=>g.trim()).filter(g=>g).filter(g=>!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(g));p.length>0&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:`Invalid email(s): ${p.join(", ")}`})}break}}}return t}function ce(e,o,t){var x;const n=[];for(const v of e)for(const C of t){if(!C.targetKey)continue;const R=o.columns.find(V=>V.key===C.targetKey);if(!R)continue;const $=v.data[C.targetKey]||v.data[C.sourceColumn]||"",_=Mt(String($),R);for(const V of _)n.push({...V,rowIndex:v.rowIndex})}const r=((x=o.options)==null?void 0:x.uniqueKeys)||[];for(const v of r){const C=t.find($=>$.targetKey===v);if(!C)continue;const R=new Map;for(const $ of e){const _=String($.data[v]||$.data[C.sourceColumn]||"").toLowerCase().trim();if(!_)continue;const V=R.get(_)||[];V.push($.rowIndex),R.set(_,V)}for(const[$,_]of R.entries())if(_.length>1)for(const V of _.slice(1))n.push({rowIndex:V,columnKey:v,value:$,severity:"warning",validatorType:"unique",message:`Duplicate ${v} value`})}const s=new Map;for(const v of n){const C=s.get(v.rowIndex)||[];C.push(v),s.set(v.rowIndex,C)}const i=n.filter(v=>v.severity==="error").length,a=n.filter(v=>v.severity==="warning").length,f=n.filter(v=>v.severity==="info").length,d=new Set(n.filter(v=>v.severity==="error").map(v=>v.rowIndex)),p=e.length,g=p-d.size,c={};for(const v of n){c[v.columnKey]||(c[v.columnKey]={columnKey:v.columnKey,errorCount:0,warningCount:0,infoCount:0,mostCommonError:void 0});const C=c[v.columnKey];v.severity==="error"?C.errorCount++:v.severity==="warning"?C.warningCount++:C.infoCount++,C.mostCommonError||(C.mostCommonError=v.message)}const u={};for(const v of n)u[v.validatorType]=(u[v.validatorType]||0)+1;const m=[];for(const v of r){const C=t.find($=>$.targetKey===v);if(!C)continue;const R=new Map;for(const $ of e){const _=String($.data[v]||$.data[C.sourceColumn]||"").toLowerCase().trim();if(!_)continue;const V=R.get(_)||[];V.push($.rowIndex),R.set(_,V)}for(const[$,_]of R.entries())_.length>1&&m.push({columnKey:v,value:$,rowIndices:_})}const h={byColumn:c,byType:u,duplicates:m.length>0?m:void 0};return{validationResults:{isValid:i===0,totalRows:p,validRows:g,errorCount:i,warningCount:a,infoCount:f,errors:n,summary:h},errorsByRow:s}}const ee=w.create((e,o)=>({...Ae,setSchema:t=>e({schema:t}),setSessionId:t=>e({sessionId:t}),setFile:t=>e({file:t,fileName:t.name,fileSize:t.size,error:null}),setParsedData:t=>e({headers:t.headers,rows:t.rows,totalRows:t.totalRows,sampleRows:t.sampleRows}),setMappings:t=>e({mappings:t}),updateMapping:(t,n)=>e(r=>({mappings:r.mappings.map(i=>i.sourceColumn===t?{...i,targetKey:n,isAutoMapped:!1}:i)})),setUnmapped:(t,n)=>e({unmappedSource:t,unmappedTarget:n}),setValidationResults:t=>{const n=new Map;for(const r of t.errors){const s=n.get(r.rowIndex)||[];s.push(r),n.set(r.rowIndex,s)}e({validationResults:t,errorsByRow:n})},revalidate:()=>{const t=o();if(!t.schema||!t.validationResults)return;const{validationResults:n,errorsByRow:r}=ce(t.rows,t.schema,t.mappings);e({validationResults:n,errorsByRow:r})},setStep:t=>e({step:t}),nextStep:()=>{const t=["upload","mapping","validation","review","complete"],n=t.indexOf(o().step);n<t.length-1&&e({step:t[n+1]})},previousStep:()=>{const t=["upload","mapping","validation","review","complete"],n=t.indexOf(o().step);n>0&&e({step:t[n-1]})},startEditing:(t,n)=>e({editingCell:{rowIndex:t,columnKey:n}}),stopEditing:()=>e({editingCell:null}),updateCell:(t,n,r)=>{const s=o(),i=[...s.rows],a=i.find(d=>d.rowIndex===t);a&&(a.data={...a.data,[n]:String(r)});const f=new Set(s.editedRows);if(f.add(t),e({rows:i,editedRows:f,editingCell:null}),s.schema&&s.validationResults){const{validationResults:d,errorsByRow:p}=ce(i,s.schema,s.mappings);e({validationResults:d,errorsByRow:p})}},deleteRow:t=>{const n=o(),s=n.rows.filter(i=>i.rowIndex!==t).map((i,a)=>({...i,rowIndex:a}));if(e({rows:s,totalRows:s.length}),n.schema&&n.validationResults){const{validationResults:i,errorsByRow:a}=ce(s,n.schema,n.mappings);e({validationResults:i,errorsByRow:a})}},setStatus:t=>e({status:t}),setLoading:t=>e({isLoading:t}),setError:t=>e({error:t}),reset:()=>e(Ae)})),Oe=({onFileSelect:e,maxSize:o=50*1024*1024,acceptedTypes:t=[".csv",".xlsx",".xls"]})=>{const{file:n,fileName:r,fileSize:s,setFile:i,error:a,setError:f,isLoading:d}=ee(),p=b.useCallback((x,v)=>{if(v.length>0){f("Invalid file type or file too large");return}if(x.length>0){const C=x[0];i(C),e==null||e(C)}},[e,i,f]),{getRootProps:g,getInputProps:c,isDragActive:u}=w.useDropzone({onDrop:p,accept:{"text/csv":[".csv"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"],"application/vnd.ms-excel":[".xls"]},maxSize:o,multiple:!1,disabled:d}),m=x=>x<1024?`${x} B`:x<1024*1024?`${(x/1024).toFixed(1)} KB`:`${(x/(1024*1024)).toFixed(1)} MB`,h=x=>{x.stopPropagation(),ee.getState().reset()};return n?l.jsx("div",{className:"ff-p-4 ff-rounded-xl ff-border",style:{backgroundColor:"var(--ff-success-light)",borderColor:"var(--ff-success)"},children:l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-3",children:[l.jsx("div",{className:"ff-p-2 ff-rounded-lg",style:{backgroundColor:"rgba(41, 142, 51, 0.15)"},children:l.jsx(yt,{className:"ff-w-6 ff-h-6",style:{color:"var(--ff-success)"}})}),l.jsxs("div",{className:"ff-flex-1 ff-min-w-0",children:[l.jsx("p",{className:"ff-font-medium ff-truncate",style:{color:"var(--ff-success-dark)"},children:r}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-success)"},children:m(s||0)})]}),l.jsx("button",{onClick:h,className:"ff-p-1.5 ff-rounded-full ff-transition-colors",style:{color:"var(--ff-success)"},"aria-label":"Remove file",children:l.jsx(w.X,{className:"ff-w-5 ff-h-5"})})]})}):l.jsxs("div",{className:"ff-space-y-6",children:[l.jsxs("div",{...g(),className:w.clsx("ff-dropzone",u&&"ff-dropzone-active",d&&"ff-opacity-50 ff-cursor-not-allowed"),children:[l.jsx("input",{...c()}),l.jsx("div",{className:"ff-dropzone-icon-wrapper",children:l.jsx(w.Upload,{className:"ff-dropzone-icon"})}),l.jsx("h3",{className:"ff-dropzone-text",children:u?"Drop your file here":"Upload your file"}),l.jsx("p",{className:"ff-dropzone-hint",children:"Drag and drop or click to select"}),l.jsx("label",{className:"ff-inline-block",children:l.jsx("span",{className:w.clsx("ff-btn ff-btn-primary",d&&"ff-opacity-50 ff-cursor-wait"),children:d?"Processing...":"Choose file"})}),l.jsxs("p",{className:"ff-dropzone-formats",children:["Supports ",t.join(", ")," up to ",m(o)]})]}),a&&l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2 ff-p-4 ff-rounded-lg ff-text-sm",style:{backgroundColor:"var(--ff-error-light)",color:"var(--ff-error)"},children:[l.jsx(w.CircleAlert,{className:"ff-w-4 ff-h-4 ff-flex-shrink-0"}),l.jsx("p",{children:a})]})]})},Te=({onMappingChange:e})=>{const{mappings:o,schema:t,unmappedSource:n,updateMapping:r}=ee(),s=(t==null?void 0:t.columns)||[],i=(g,c)=>{const u=c===""?null:c;r(g,u),e==null||e(g,u)},a=g=>g>=.85?"var(--ff-success)":g>=.6?"var(--ff-warning)":"var(--ff-error)",f=g=>g>=.85?"High":g>=.6?"Medium":"Low",p=new Set(o.filter(g=>g.targetKey!==null).map(g=>g.targetKey));return l.jsxs("div",{className:"ff-space-y-4",children:[l.jsxs("div",{className:"ff-mapping-header",children:[l.jsxs("div",{children:[l.jsx("h3",{className:"ff-mapping-title",children:"Column Mapping"}),l.jsx("p",{className:"ff-mapping-subtitle",children:"Match your file columns to the expected fields"})]}),l.jsxs("div",{className:"ff-mapping-legend",children:[l.jsxs("span",{className:"ff-mapping-legend-item",children:[l.jsx("span",{className:"ff-mapping-legend-dot",style:{backgroundColor:"var(--ff-success)"}}),l.jsx("span",{style:{color:"var(--ff-text-secondary)"},children:"Mapped"})]}),l.jsxs("span",{className:"ff-mapping-legend-item",children:[l.jsx("span",{className:"ff-mapping-legend-dot",style:{backgroundColor:"var(--ff-warning)"}}),l.jsx("span",{style:{color:"var(--ff-text-secondary)"},children:"Review"})]}),l.jsxs("span",{className:"ff-mapping-legend-item",children:[l.jsx("span",{className:"ff-mapping-legend-dot",style:{backgroundColor:"var(--ff-gray-70)"}}),l.jsx("span",{style:{color:"var(--ff-text-secondary)"},children:"Unmapped"})]})]})]}),l.jsx("div",{className:"ff-space-y-2",children:o.map(g=>{s.find(m=>m.key===g.targetKey);const c=g.targetKey!==null,u=g.confidence>=.85;return l.jsxs("div",{className:w.clsx("ff-mapping-row",c&&u&&"ff-mapping-row-success",c&&!u&&"ff-mapping-row-warning"),children:[l.jsx("div",{className:"ff-flex-1",children:l.jsx("div",{className:"ff-mapping-source",children:g.sourceColumn})}),l.jsx("div",{className:"ff-mapping-arrow",children:l.jsx(ut,{className:"ff-w-5 ff-h-5"})}),l.jsx("div",{className:"ff-flex-1 ff-mapping-target",children:l.jsxs("select",{value:g.targetKey||"",onChange:m=>i(g.sourceColumn,m.target.value),className:"ff-input",children:[l.jsx("option",{value:"",children:"-- Do not import --"}),s.map(m=>l.jsxs("option",{value:m.key,disabled:p.has(m.key)&&g.targetKey!==m.key,children:[m.label," (",m.type,")",m.required?" *":""]},m.key))]})}),l.jsx("div",{className:"ff-mapping-status",children:c?u?l.jsx(dt,{className:"ff-w-5 ff-h-5",style:{color:"var(--ff-success)"}}):l.jsx(mt,{className:"ff-w-5 ff-h-5",style:{color:"var(--ff-warning)"}}):l.jsx("span",{className:"ff-w-5 ff-h-5"})}),g.confidence>0&&l.jsxs("div",{className:"ff-confidence",style:{color:a(g.confidence)},children:[l.jsxs("span",{children:[Math.round(g.confidence*100),"%"]}),l.jsxs("span",{style:{color:"var(--ff-text-muted)"},children:["(",f(g.confidence),")"]})]})]},g.sourceColumn)})}),(()=>{const g=s.filter(c=>c.required&&!p.has(c.key));return g.length>0?l.jsxs("div",{className:"ff-flex ff-items-start ff-gap-2 ff-p-4 ff-rounded-lg",style:{backgroundColor:"var(--ff-warning-light)",borderColor:"var(--ff-warning)"},children:[l.jsx(w.CircleAlert,{className:"ff-w-5 ff-h-5 ff-flex-shrink-0 ff-mt-0.5",style:{color:"var(--ff-warning)"}}),l.jsxs("div",{children:[l.jsx("p",{className:"ff-text-sm ff-font-medium",style:{color:"var(--ff-warning-dark)"},children:"Required fields not mapped"}),l.jsx("p",{className:"ff-text-sm ff-mt-1",style:{color:"var(--ff-warning)"},children:g.map(c=>c.label).join(", ")})]})]}):null})()]})};/**
56
+ */const $t=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],Nt=w.createLucideIcon("trash-2",$t),Ae={sessionId:null,status:"idle",step:"upload",schema:null,file:null,fileName:null,fileSize:null,headers:[],rows:[],totalRows:0,sampleRows:[],mappings:[],unmappedSource:[],unmappedTarget:[],validationResults:null,errorsByRow:new Map,isLoading:!1,error:null,editingCell:null,editedRows:new Set};function Mt(e,o){var r;const t=[],n=(e==null?void 0:e.trim())||"";if(o.required&&!n)return t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"required",message:`${o.label} is required`}),t;if(!n)return t;switch(o.type){case"email":{if(!/^[^\s@]+@[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/.test(n))t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"type",message:"Invalid email format"});else{const i=(r=n.split("@")[1])==null?void 0:r.toLowerCase(),a={"gmial.com":"gmail.com","gmal.com":"gmail.com","gmai.com":"gmail.com","gamil.com":"gmail.com","gnail.com":"gmail.com","gmail.co":"gmail.com","gmail.cm":"gmail.com","gmil.com":"gmail.com","gmaill.com":"gmail.com","yaho.com":"yahoo.com","yahooo.com":"yahoo.com","yahoo.co":"yahoo.com","hotmal.com":"hotmail.com","hotmial.com":"hotmail.com","hotmai.com":"hotmail.com","hotmail.co":"hotmail.com","outlok.com":"outlook.com","outloo.com":"outlook.com","outlook.co":"outlook.com"};i&&a[i]&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:"warning",validatorType:"type",message:`Possible typo: did you mean @${a[i]}?`,suggestion:`${n.split("@")[0]}@${a[i]}`})}break}case"url":/^https?:\/\/.+/.test(n)||t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"type",message:"Invalid URL format"});break;case"integer":/^-?\d+$/.test(n)||t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"type",message:"Must be a whole number"});break;case"number":case"float":/^-?\d+(\.\d+)?$/.test(n)||t.push({rowIndex:0,columnKey:o.key,value:n,severity:"error",validatorType:"type",message:"Must be a valid number"});break;case"phone":n.replace(/\D/g,"").length<10&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:"warning",validatorType:"type",message:"Invalid phone number"});break}if(o.validators)for(const s of o.validators){const i=s.severity==="info"?"warning":s.severity||"error",a=s.params||{};switch(s.type){case"minLength":{const f=a.value??0;n.length<f&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be at least ${f} characters`});break}case"maxLength":{const f=a.value??1/0;n.length>f&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be at most ${f} characters`});break}case"min":{const f=parseFloat(n),d=a.value??-1/0;!isNaN(f)&&f<d&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be at least ${d}`});break}case"max":{const f=parseFloat(n),d=a.value??1/0;!isNaN(f)&&f>d&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be at most ${d}`});break}case"pattern":{const f=a.regex??a.pattern??".*";new RegExp(f).test(n)||t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||"Format is invalid"});break}case"enum":{const f=a.values||[];f.map(p=>p.toLowerCase()).includes(n.toLowerCase())||t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Must be one of: ${f.slice(0,5).join(", ")}${f.length>5?"...":""}`});break}case"custom":{const f=a.validatorName;if(f==="commaSeparatedEnum"){const d=a.allowedValues||[],p=n.split(",").map(u=>u.trim().toLowerCase()).filter(u=>u),g=d.map(u=>u.toLowerCase()),c=p.filter(u=>!g.includes(u));c.length>0&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:s.message||`Invalid values: ${c.join(", ")}. Must be comma-separated values from: ${d.slice(0,5).join(", ")}${d.length>5?"...":""}`})}if(f==="commaSeparatedEmails"){const p=n.split(",").map(g=>g.trim()).filter(g=>g).filter(g=>!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(g));p.length>0&&t.push({rowIndex:0,columnKey:o.key,value:n,severity:i,validatorType:s.type,message:`Invalid email(s): ${p.join(", ")}`})}break}}}return t}function ce(e,o,t){var x;const n=[];for(const v of e)for(const C of t){if(!C.targetKey)continue;const R=o.columns.find(V=>V.key===C.targetKey);if(!R)continue;const $=v.data[C.targetKey]||v.data[C.sourceColumn]||"",_=Mt(String($),R);for(const V of _)n.push({...V,rowIndex:v.rowIndex})}const r=((x=o.options)==null?void 0:x.uniqueKeys)||[];for(const v of r){const C=t.find($=>$.targetKey===v);if(!C)continue;const R=new Map;for(const $ of e){const _=String($.data[v]||$.data[C.sourceColumn]||"").toLowerCase().trim();if(!_)continue;const V=R.get(_)||[];V.push($.rowIndex),R.set(_,V)}for(const[$,_]of R.entries())if(_.length>1)for(const V of _.slice(1))n.push({rowIndex:V,columnKey:v,value:$,severity:"warning",validatorType:"unique",message:`Duplicate ${v} value`})}const s=new Map;for(const v of n){const C=s.get(v.rowIndex)||[];C.push(v),s.set(v.rowIndex,C)}const i=n.filter(v=>v.severity==="error").length,a=n.filter(v=>v.severity==="warning").length,f=n.filter(v=>v.severity==="info").length,d=new Set(n.filter(v=>v.severity==="error").map(v=>v.rowIndex)),p=e.length,g=p-d.size,c={};for(const v of n){c[v.columnKey]||(c[v.columnKey]={columnKey:v.columnKey,errorCount:0,warningCount:0,infoCount:0,mostCommonError:void 0});const C=c[v.columnKey];v.severity==="error"?C.errorCount++:v.severity==="warning"?C.warningCount++:C.infoCount++,C.mostCommonError||(C.mostCommonError=v.message)}const u={};for(const v of n)u[v.validatorType]=(u[v.validatorType]||0)+1;const m=[];for(const v of r){const C=t.find($=>$.targetKey===v);if(!C)continue;const R=new Map;for(const $ of e){const _=String($.data[v]||$.data[C.sourceColumn]||"").toLowerCase().trim();if(!_)continue;const V=R.get(_)||[];V.push($.rowIndex),R.set(_,V)}for(const[$,_]of R.entries())_.length>1&&m.push({columnKey:v,value:$,rowIndices:_})}const h={byColumn:c,byType:u,duplicates:m.length>0?m:void 0};return{validationResults:{isValid:i===0,totalRows:p,validRows:g,errorCount:i,warningCount:a,infoCount:f,errors:n,summary:h},errorsByRow:s}}const ee=w.create((e,o)=>({...Ae,setSchema:t=>e({schema:t}),setSessionId:t=>e({sessionId:t}),setFile:t=>e({file:t,fileName:t.name,fileSize:t.size,error:null}),setParsedData:t=>e({headers:t.headers,rows:t.rows,totalRows:t.totalRows,sampleRows:t.sampleRows}),setMappings:t=>e({mappings:t}),updateMapping:(t,n)=>e(r=>({mappings:r.mappings.map(i=>i.sourceColumn===t?{...i,targetKey:n,isAutoMapped:!1}:i)})),setUnmapped:(t,n)=>e({unmappedSource:t,unmappedTarget:n}),setValidationResults:t=>{if(!t){e({validationResults:null,errorsByRow:new Map});return}const n=new Map;for(const r of t.errors){const s=n.get(r.rowIndex)||[];s.push(r),n.set(r.rowIndex,s)}e({validationResults:t,errorsByRow:n})},revalidate:()=>{const t=o();if(!t.schema||!t.validationResults)return;const{validationResults:n,errorsByRow:r}=ce(t.rows,t.schema,t.mappings);e({validationResults:n,errorsByRow:r})},setStep:t=>e({step:t}),nextStep:()=>{const t=["upload","mapping","validation","review","complete"],n=t.indexOf(o().step);n<t.length-1&&e({step:t[n+1]})},previousStep:()=>{const t=["upload","mapping","validation","review","complete"],n=t.indexOf(o().step);n>0&&e({step:t[n-1]})},startEditing:(t,n)=>e({editingCell:{rowIndex:t,columnKey:n}}),stopEditing:()=>e({editingCell:null}),updateCell:(t,n,r)=>{const s=o(),i=[...s.rows],a=i.find(d=>d.rowIndex===t);a&&(a.data={...a.data,[n]:String(r)});const f=new Set(s.editedRows);if(f.add(t),e({rows:i,editedRows:f,editingCell:null}),s.schema&&s.validationResults){const{validationResults:d,errorsByRow:p}=ce(i,s.schema,s.mappings);e({validationResults:d,errorsByRow:p})}},deleteRow:t=>{const n=o(),s=n.rows.filter(i=>i.rowIndex!==t).map((i,a)=>({...i,rowIndex:a}));if(e({rows:s,totalRows:s.length}),n.schema&&n.validationResults){const{validationResults:i,errorsByRow:a}=ce(s,n.schema,n.mappings);e({validationResults:i,errorsByRow:a})}},setStatus:t=>e({status:t}),setLoading:t=>e({isLoading:t}),setError:t=>e({error:t}),reset:()=>e(Ae)})),Oe=({onFileSelect:e,maxSize:o=50*1024*1024,acceptedTypes:t=[".csv",".xlsx",".xls"]})=>{const{file:n,fileName:r,fileSize:s,setFile:i,error:a,setError:f,isLoading:d}=ee(),p=b.useCallback((x,v)=>{if(v.length>0){f("Invalid file type or file too large");return}if(x.length>0){const C=x[0];i(C),e==null||e(C)}},[e,i,f]),{getRootProps:g,getInputProps:c,isDragActive:u}=w.useDropzone({onDrop:p,accept:{"text/csv":[".csv"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"],"application/vnd.ms-excel":[".xls"]},maxSize:o,multiple:!1,disabled:d}),m=x=>x<1024?`${x} B`:x<1024*1024?`${(x/1024).toFixed(1)} KB`:`${(x/(1024*1024)).toFixed(1)} MB`,h=x=>{x.stopPropagation(),ee.getState().reset()};return n?l.jsx("div",{className:"ff-p-4 ff-rounded-xl ff-border",style:{backgroundColor:"var(--ff-success-light)",borderColor:"var(--ff-success)"},children:l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-3",children:[l.jsx("div",{className:"ff-p-2 ff-rounded-lg",style:{backgroundColor:"rgba(41, 142, 51, 0.15)"},children:l.jsx(yt,{className:"ff-w-6 ff-h-6",style:{color:"var(--ff-success)"}})}),l.jsxs("div",{className:"ff-flex-1 ff-min-w-0",children:[l.jsx("p",{className:"ff-font-medium ff-truncate",style:{color:"var(--ff-success-dark)"},children:r}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-success)"},children:m(s||0)})]}),l.jsx("button",{onClick:h,className:"ff-p-1.5 ff-rounded-full ff-transition-colors",style:{color:"var(--ff-success)"},"aria-label":"Remove file",children:l.jsx(w.X,{className:"ff-w-5 ff-h-5"})})]})}):l.jsxs("div",{className:"ff-space-y-6",children:[l.jsxs("div",{...g(),className:w.clsx("ff-dropzone",u&&"ff-dropzone-active",d&&"ff-opacity-50 ff-cursor-not-allowed"),children:[l.jsx("input",{...c()}),l.jsx("div",{className:"ff-dropzone-icon-wrapper",children:l.jsx(w.Upload,{className:"ff-dropzone-icon"})}),l.jsx("h3",{className:"ff-dropzone-text",children:u?"Drop your file here":"Upload your file"}),l.jsx("p",{className:"ff-dropzone-hint",children:"Drag and drop or click to select"}),l.jsx("label",{className:"ff-inline-block",children:l.jsx("span",{className:w.clsx("ff-btn ff-btn-primary",d&&"ff-opacity-50 ff-cursor-wait"),children:d?"Processing...":"Choose file"})}),l.jsxs("p",{className:"ff-dropzone-formats",children:["Supports ",t.join(", ")," up to ",m(o)]})]}),a&&l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2 ff-p-4 ff-rounded-lg ff-text-sm",style:{backgroundColor:"var(--ff-error-light)",color:"var(--ff-error)"},children:[l.jsx(w.CircleAlert,{className:"ff-w-4 ff-h-4 ff-flex-shrink-0"}),l.jsx("p",{children:a})]})]})},Te=({onMappingChange:e})=>{const{mappings:o,schema:t,unmappedSource:n,updateMapping:r}=ee(),s=(t==null?void 0:t.columns)||[],i=(g,c)=>{const u=c===""?null:c;r(g,u),e==null||e(g,u)},a=g=>g>=.85?"var(--ff-success)":g>=.6?"var(--ff-warning)":"var(--ff-error)",f=g=>g>=.85?"High":g>=.6?"Medium":"Low",p=new Set(o.filter(g=>g.targetKey!==null).map(g=>g.targetKey));return l.jsxs("div",{className:"ff-space-y-4",children:[l.jsxs("div",{className:"ff-mapping-header",children:[l.jsxs("div",{children:[l.jsx("h3",{className:"ff-mapping-title",children:"Column Mapping"}),l.jsx("p",{className:"ff-mapping-subtitle",children:"Match your file columns to the expected fields"})]}),l.jsxs("div",{className:"ff-mapping-legend",children:[l.jsxs("span",{className:"ff-mapping-legend-item",children:[l.jsx("span",{className:"ff-mapping-legend-dot",style:{backgroundColor:"var(--ff-success)"}}),l.jsx("span",{style:{color:"var(--ff-text-secondary)"},children:"Mapped"})]}),l.jsxs("span",{className:"ff-mapping-legend-item",children:[l.jsx("span",{className:"ff-mapping-legend-dot",style:{backgroundColor:"var(--ff-warning)"}}),l.jsx("span",{style:{color:"var(--ff-text-secondary)"},children:"Review"})]}),l.jsxs("span",{className:"ff-mapping-legend-item",children:[l.jsx("span",{className:"ff-mapping-legend-dot",style:{backgroundColor:"var(--ff-gray-70)"}}),l.jsx("span",{style:{color:"var(--ff-text-secondary)"},children:"Unmapped"})]})]})]}),l.jsx("div",{className:"ff-space-y-2",children:o.map(g=>{s.find(m=>m.key===g.targetKey);const c=g.targetKey!==null,u=g.confidence>=.85;return l.jsxs("div",{className:w.clsx("ff-mapping-row",c&&u&&"ff-mapping-row-success",c&&!u&&"ff-mapping-row-warning"),children:[l.jsx("div",{className:"ff-flex-1",children:l.jsx("div",{className:"ff-mapping-source",children:g.sourceColumn})}),l.jsx("div",{className:"ff-mapping-arrow",children:l.jsx(ut,{className:"ff-w-5 ff-h-5"})}),l.jsx("div",{className:"ff-flex-1 ff-mapping-target",children:l.jsxs("select",{value:g.targetKey||"",onChange:m=>i(g.sourceColumn,m.target.value),className:"ff-input",children:[l.jsx("option",{value:"",children:"-- Do not import --"}),s.map(m=>l.jsxs("option",{value:m.key,disabled:p.has(m.key)&&g.targetKey!==m.key,children:[m.label," (",m.type,")",m.required?" *":""]},m.key))]})}),l.jsx("div",{className:"ff-mapping-status",children:c?u?l.jsx(dt,{className:"ff-w-5 ff-h-5",style:{color:"var(--ff-success)"}}):l.jsx(mt,{className:"ff-w-5 ff-h-5",style:{color:"var(--ff-warning)"}}):l.jsx("span",{className:"ff-w-5 ff-h-5"})}),g.confidence>0&&l.jsxs("div",{className:"ff-confidence",style:{color:a(g.confidence)},children:[l.jsxs("span",{children:[Math.round(g.confidence*100),"%"]}),l.jsxs("span",{style:{color:"var(--ff-text-muted)"},children:["(",f(g.confidence),")"]})]})]},g.sourceColumn)})}),(()=>{const g=s.filter(c=>c.required&&!p.has(c.key));return g.length>0?l.jsxs("div",{className:"ff-flex ff-items-start ff-gap-2 ff-p-4 ff-rounded-lg",style:{backgroundColor:"var(--ff-warning-light)",borderColor:"var(--ff-warning)"},children:[l.jsx(w.CircleAlert,{className:"ff-w-5 ff-h-5 ff-flex-shrink-0 ff-mt-0.5",style:{color:"var(--ff-warning)"}}),l.jsxs("div",{children:[l.jsx("p",{className:"ff-text-sm ff-font-medium",style:{color:"var(--ff-warning-dark)"},children:"Required fields not mapped"}),l.jsx("p",{className:"ff-text-sm ff-mt-1",style:{color:"var(--ff-warning)"},children:g.map(c=>c.label).join(", ")})]})]}):null})()]})};/**
57
57
  * table-core
58
58
  *
59
59
  * Copyright (c) TanStack
@@ -75,4 +75,4 @@
75
75
  *
76
76
  * @license MIT
77
77
  */function Ge(e,o){return e?jn(e)?ye.createElement(e,o):e:null}function jn(e){return In(e)||typeof e=="function"||$n(e)}function In(e){return typeof e=="function"&&(()=>{const o=Object.getPrototypeOf(e);return o.prototype&&o.prototype.isReactComponent})()}function $n(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Nn(e){const o={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[t]=ye.useState(()=>({current:vn(o)})),[n,r]=ye.useState(()=>t.current.initialState);return t.current.setOptions(s=>({...s,...e,state:{...n,...e.state},onStateChange:i=>{r(i),e.onStateChange==null||e.onStateChange(i)}})),t.current}const Ie=({editable:e=!0,deletable:o=!0,pageSize:t=25,onCellEdit:n,onRowDelete:r})=>{const{rows:s,schema:i,mappings:a,errorsByRow:f,editingCell:d,startEditing:p,stopEditing:g,updateCell:c,deleteRow:u}=ee(),[m,h]=b.useState([]),[x,v]=b.useState(""),[C,R]=b.useState(""),$=b.useMemo(()=>a.filter(F=>F.targetKey!==null).map(F=>{const j=i==null?void 0:i.columns.find(N=>N.key===F.targetKey);return{sourceColumn:F.sourceColumn,targetKey:F.targetKey,label:(j==null?void 0:j.label)||F.targetKey,type:(j==null?void 0:j.type)||"string"}}),[a,i]),_=b.useCallback((F,j)=>{const N=f.get(F);return N==null?void 0:N.find(T=>T.columnKey===j)},[f]),V=(F,j,N)=>{R(N),p(F,j)},Q=()=>{d&&(c(d.rowIndex,d.columnKey,C),n==null||n(d.rowIndex,d.columnKey,C)),g()},E=()=>{R(""),g()},B=F=>{u(F),r==null||r(F)},X=Vt(),L=b.useMemo(()=>[X.accessor("rowIndex",{header:"#",size:o?80:60,cell:F=>{const j=F.getValue();return l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[l.jsx("span",{className:"ff-font-mono ff-text-xs",style:{color:"var(--ff-text-muted)"},children:j+1}),o&&l.jsx("button",{onClick:N=>{N.stopPropagation(),B(j)},title:"Delete row",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"4px",borderRadius:"4px",cursor:"pointer",color:"#8e8d89",background:"transparent",border:"none",transition:"color 0.15s, background-color 0.15s",marginLeft:"2px",flexShrink:0},onMouseEnter:N=>{N.currentTarget.style.color="#d43338",N.currentTarget.style.backgroundColor="#fcdede"},onMouseLeave:N=>{N.currentTarget.style.color="#8e8d89",N.currentTarget.style.backgroundColor="transparent"},children:l.jsx(Nt,{style:{width:"14px",height:"14px",display:"block"}})})]})}}),...$.map(F=>X.accessor(j=>j.data[F.targetKey]||j.data[F.sourceColumn],{id:F.targetKey,header:F.label,cell:j=>{const N=j.row.original.rowIndex,T=String(j.getValue()??""),z=_(N,F.targetKey);return(d==null?void 0:d.rowIndex)===N&&(d==null?void 0:d.columnKey)===F.targetKey?l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2 ff-min-w-[280px]",children:[l.jsx("input",{type:"text",value:C,onChange:J=>R(J.target.value),onKeyDown:J=>{J.key==="Enter"&&Q(),J.key==="Escape"&&E()},className:"ff-input ff-py-2 ff-px-3 ff-text-sm ff-flex-1 ff-min-w-[160px]",autoFocus:!0}),l.jsx("button",{onClick:Q,className:"ff-btn ff-btn-primary ff-btn-sm ff-flex-shrink-0",children:"Save"}),l.jsx("button",{onClick:E,className:"ff-btn ff-btn-secondary ff-btn-sm ff-flex-shrink-0",children:"Cancel"})]}):l.jsxs("div",{className:w.clsx("ff-group ff-flex ff-items-center ff-gap-2",(z==null?void 0:z.severity)==="error"&&"ff-cell-error",(z==null?void 0:z.severity)==="warning"&&"ff-cell-warning"),children:[l.jsx("span",{className:"ff-flex-1 ff-truncate",children:T||l.jsx("span",{style:{color:"var(--ff-text-muted)"},children:"—"})}),z&&l.jsxs("div",{className:"ff-relative ff-group/tooltip",children:[z.severity==="error"?l.jsx(w.CircleAlert,{className:"ff-w-4 ff-h-4",style:{color:"var(--ff-error)"}}):l.jsx(w.TriangleAlert,{className:"ff-w-4 ff-h-4",style:{color:"var(--ff-warning)"}}),l.jsxs("div",{className:"ff-tooltip ff-bottom-full ff-left-1/2 ff-transform ff--translate-x-1/2 ff-mb-2 ff-w-48 group-hover/tooltip:ff-tooltip-visible",children:[z.message,z.suggestion&&l.jsx("span",{className:"ff-block ff-mt-1",style:{color:"var(--ff-text-muted)"},children:z.suggestion})]})]}),e&&l.jsx("button",{onClick:()=>V(N,F.targetKey,T),className:"ff-opacity-0 group-hover:ff-opacity-100 ff-p-1 ff-rounded ff-transition-opacity ff-edit-btn",children:l.jsx(Ft,{className:"ff-w-3 ff-h-3"})})]})}}))],[$,d,C,e,o,_,X]),O=Nn({data:s,columns:L,state:{sorting:m,globalFilter:x},onSortingChange:h,onGlobalFilterChange:v,getCoreRowModel:xn(),getPaginationRowModel:_n(),getSortedRowModel:Fn(),getFilteredRowModel:Rn(),initialState:{pagination:{pageSize:t}}});return l.jsxs("div",{className:"ff-space-y-4",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between",children:[l.jsx("input",{type:"text",value:x,onChange:F=>v(F.target.value),placeholder:"Search all columns...",className:"ff-input ff-max-w-xs"}),l.jsxs("div",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[O.getFilteredRowModel().rows.length," rows"]})]}),l.jsx("div",{className:"ff-table-container ff-max-h-[500px]",children:l.jsxs("table",{className:"ff-table",children:[l.jsx("thead",{children:O.getHeaderGroups().map(F=>l.jsx("tr",{children:F.headers.map(j=>l.jsx("th",{style:{width:j.getSize()},onClick:j.column.getToggleSortingHandler(),className:w.clsx(j.column.getCanSort()&&"ff-cursor-pointer ff-select-none"),children:l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-1",children:[Ge(j.column.columnDef.header,j.getContext()),j.column.getIsSorted()&&l.jsx("span",{children:j.column.getIsSorted()==="asc"?"↑":"↓"})]})},j.id))},F.id))}),l.jsx("tbody",{children:O.getRowModel().rows.map(F=>{const j=f.has(F.original.rowIndex);return l.jsx("tr",{className:w.clsx(j&&"ff-row-error"),children:F.getVisibleCells().map(N=>l.jsx("td",{children:Ge(N.column.columnDef.cell,N.getContext())},N.id))},F.id)})})]})}),l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between ff-px-2",children:[l.jsxs("div",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:["Page ",O.getState().pagination.pageIndex+1," of ",O.getPageCount()]}),l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2",children:[l.jsxs("button",{onClick:()=>O.previousPage(),disabled:!O.getCanPreviousPage(),className:"ff-btn ff-btn-secondary ff-btn-sm",children:[l.jsx(gt,{className:"ff-w-4 ff-h-4"}),"Previous"]}),l.jsxs("button",{onClick:()=>O.nextPage(),disabled:!O.getCanNextPage(),className:"ff-btn ff-btn-secondary ff-btn-sm",children:["Next",l.jsx(w.ChevronRight,{className:"ff-w-4 ff-h-4"})]})]})]})]})},$e=({showDetails:e=!0})=>{const{validationResults:o}=ee();if(!o)return null;const{isValid:t,totalRows:n,validRows:r,errorCount:s,warningCount:i,infoCount:a,summary:f}=o,d=Math.round(r/n*100);return l.jsxs("div",{className:"ff-space-y-4",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-4 ff-p-4 ff-rounded-lg ff-border",style:{backgroundColor:t?"var(--ff-success-light)":"var(--ff-error-light)",borderColor:t?"var(--ff-success)":"var(--ff-error)"},children:[t?l.jsx(w.CircleCheckBig,{className:"ff-w-8 ff-h-8",style:{color:"var(--ff-success)"}}):l.jsx(w.CircleX,{className:"ff-w-8 ff-h-8",style:{color:"var(--ff-error)"}}),l.jsxs("div",{children:[l.jsx("h3",{className:"ff-text-lg ff-font-semibold",style:{color:t?"var(--ff-success-dark)":"var(--ff-error-dark)"},children:t?"Validation Passed":"Validation Failed"}),l.jsxs("p",{className:"ff-text-sm",style:{color:t?"var(--ff-success)":"var(--ff-error)"},children:[r," of ",n," rows are valid (",d,"%)"]})]})]}),l.jsxs("div",{className:"ff-grid ff-grid-cols-4 ff-gap-4",children:[l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-bg-primary)",borderColor:"var(--ff-border-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:n}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Total Rows"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-success-light)",borderColor:"var(--ff-success)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-success-dark)"},children:r}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-success)"},children:"Valid Rows"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-error-light)",borderColor:"var(--ff-error)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-error-dark)"},children:s}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-error)"},children:"Errors"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-warning-light)",borderColor:"var(--ff-warning)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-warning-dark)"},children:i}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-warning)"},children:"Warnings"})]})]}),e&&f.byColumn&&Object.keys(f.byColumn).length>0&&l.jsxs("div",{className:"ff-border ff-rounded-xl ff-overflow-hidden",style:{backgroundColor:"var(--ff-bg-primary)",borderColor:"var(--ff-border-light)"},children:[l.jsx("div",{className:"ff-px-4 ff-py-3",style:{backgroundColor:"var(--ff-bg-secondary)"},children:l.jsx("h4",{className:"ff-font-medium ff-text-sm",style:{color:"var(--ff-text-secondary)"},children:"Issues by Column"})}),l.jsx("div",{children:Object.entries(f.byColumn).filter(([,p])=>p.errorCount>0||p.warningCount>0).map(([p,g],c,u)=>l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between ff-px-4 ff-py-3",style:{borderTop:c>0?"1px solid var(--ff-border-light)":void 0},children:[l.jsxs("div",{className:"ff-flex-1 ff-min-w-0 ff-mr-4",children:[l.jsx("p",{className:"ff-font-medium ff-text-sm",style:{color:"var(--ff-text-primary)"},children:g.columnKey}),g.mostCommonError&&l.jsx("p",{className:"ff-text-sm ff-truncate",style:{color:"var(--ff-text-muted)"},children:g.mostCommonError})]}),l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2 ff-flex-shrink-0",children:[g.errorCount>0&&l.jsxs("span",{className:"ff-badge ff-badge-error ff-whitespace-nowrap",children:[l.jsx(w.CircleX,{className:"ff-w-3 ff-h-3 ff-mr-1"}),g.errorCount," ",g.errorCount===1?"error":"errors"]}),g.warningCount>0&&l.jsxs("span",{className:"ff-badge ff-badge-warning ff-whitespace-nowrap",children:[l.jsx(w.TriangleAlert,{className:"ff-w-3 ff-h-3 ff-mr-1"}),g.warningCount," ",g.warningCount===1?"warning":"warnings"]})]})]},p))})]}),e&&f.duplicates&&f.duplicates.length>0&&l.jsx("div",{className:"ff-border ff-rounded-lg ff-p-4",style:{backgroundColor:"var(--ff-warning-light)",borderColor:"var(--ff-warning)"},children:l.jsxs("div",{className:"ff-flex ff-items-start ff-gap-3",children:[l.jsx(w.TriangleAlert,{className:"ff-w-5 ff-h-5 ff-flex-shrink-0 ff-mt-0.5",style:{color:"var(--ff-warning)"}}),l.jsxs("div",{children:[l.jsx("h4",{className:"ff-font-medium",style:{color:"var(--ff-warning-dark)"},children:"Duplicate Values Found"}),l.jsxs("ul",{className:"ff-mt-2 ff-space-y-1 ff-text-sm",style:{color:"var(--ff-warning-dark)"},children:[f.duplicates.slice(0,5).map((p,g)=>l.jsxs("li",{children:[l.jsx("span",{className:"ff-font-mono",children:p.columnKey}),': "',String(p.value),'" appears'," ",p.rowIndices.length," times (rows"," ",p.rowIndices.slice(0,3).map(c=>c+1).join(", "),p.rowIndices.length>3?"...":"",")"]},g)),f.duplicates.length>5&&l.jsxs("li",{style:{color:"var(--ff-warning)"},children:["... and ",f.duplicates.length-5," more duplicate groups"]})]})]})]})})]})},Ce=["upload","mapping","validation","complete"],Mn=[{key:"upload",label:"Upload",icon:w.Upload},{key:"mapping",label:"Map Columns",icon:Rt},{key:"validation",label:"Validate",icon:It},{key:"review",label:"Review",icon:vt},{key:"complete",label:"Complete",icon:w.CircleCheckBig}],Vn=({template:e,schema:o,mode:t="modal",theme:n,useShadowDom:r=!1,onComplete:s,onCancel:i,onError:a})=>{const{step:f,sessionId:d,file:p,mappings:g,validationResults:c,isLoading:u,error:m,setSchema:h,setSessionId:x,setParsedData:v,setMappings:C,setUnmapped:R,setValidationResults:$,setStep:_,nextStep:V,previousStep:Q,setLoading:E,setError:B,reset:X}=ee(),[L,O]=b.useState(null),[F,j]=b.useState(null),[N,T]=b.useState(0),[z,Z]=b.useState("");b.useEffect(()=>{if(j(null),e)if(w.templateExists(e)){const I=w.getTemplateSchema(e);I?O(I):(j(`Failed to load template "${e}"`),a==null||a(new Error(`Failed to load template "${e}"`)))}else{const I=`Template "${e}" not found. Available templates: ${w.VALID_TEMPLATE_IDS.join(", ")}`;j(I),a==null||a(new Error(I))}else if(o)O(o);else{const I=`No template or schema provided. Please specify a template (${w.VALID_TEMPLATE_IDS.join(", ")}) or provide a custom schema.`;j(I),a==null||a(new Error(I))}},[e,o,a]),b.useEffect(()=>{L&&(h(L),J(L))},[L]);const J=async I=>{try{E(!0);const P=await w.getClient().createImportSession(I);x(P.sessionId)}catch(M){const P=M;B(P.message),a==null||a(P)}finally{E(!1)}},Je=b.useCallback(async I=>{if(d)try{E(!0),B(null),C([]),R([],[]),$(null),T(10),Z("Uploading file...");const M=w.getClient();T(30),Z("Parsing file data...");const P=await M.uploadFile(d,I);T(60),Z("Processing rows...");const K=(D,H)=>({rowIndex:D.rowIndex??H,data:D.data??D,rawData:D.rawData??Object.values(D.data??D)});v({headers:P.data.headers,rows:P.data.sampleRows.map(K),totalRows:P.data.totalRows,sampleRows:P.data.sampleRows.map(K)}),T(80),Z("Matching columns..."),_("mapping"),await et(),T(100),Z("Done")}catch(M){B(`Failed to process the uploaded file: ${M.message}`)}finally{E(!1),T(0),Z("")}},[d]),et=async()=>{if(d)try{E(!0);const M=await w.getClient().matchColumns(d);C(M.mappings),R(M.unmappedSource,M.unmappedTarget)}catch(I){B(`Column matching failed: ${I.message}`)}finally{E(!1)}},tt=async()=>{if(d)try{E(!0),B(null);const M=await w.getClient().validateImport(d);$(M.validation),V()}catch(I){B(`Validation failed: ${I.message}`)}finally{E(!1)}},[ke,le]=b.useState(null),[k,be]=b.useState(null),nt=async()=>{if(d)try{E(!0),B(null),le(null);const P=await w.getClient().completeImport(d,{skipInvalidRows:!1,acknowledgeWarnings:!0}),K={...P,data:(P.data||[]).map(D=>D.data&&typeof D.data=="object"&&!Array.isArray(D.data)?{rowIndex:D.rowIndex??0,data:D.data,wasEdited:D.wasEdited??!1}:D)};be(K),_("complete"),s==null||s(K)}catch(I){le(I.message),_("complete")}finally{E(!1)}},ie=()=>{X(),i==null||i()},Ee=()=>{le(null),be(null),T(0),Z(""),X(),L&&(h(L),J(L))},ot=()=>Mn.findIndex(I=>I.key===f),rt=()=>{switch(f){case"upload":return p!==null;case"mapping":return g.length>0&&g.some(I=>I.targetKey!==null);case"validation":return c!==null;case"review":return c!==null&&(c.isValid||c.errorCount===0);default:return!1}},st=async()=>{switch(f){case"mapping":await tt();break;case"validation":V();break;case"review":await nt();break;default:V()}};if(F)return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:l.jsx("div",{className:"ff-container ff-bg-white ff-rounded-xl ff-shadow-xl ff-overflow-hidden ff-p-6",children:l.jsxs("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:[l.jsx("div",{className:"ff-w-16 ff-h-16 ff-rounded-full ff-flex ff-items-center ff-justify-center ff-mb-4",style:{backgroundColor:"var(--ff-error-light)"},children:l.jsx(w.X,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-error)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Configuration Error"}),l.jsx("p",{className:"ff-text-center ff-max-w-md ff-mb-4",style:{color:"var(--ff-text-muted)"},children:F}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})})});if(!L)return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:l.jsx("div",{className:"ff-container ff-bg-white ff-rounded-xl ff-shadow-xl ff-overflow-hidden ff-p-6",children:l.jsxs("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{style:{color:"var(--ff-text-muted)"},children:"Loading template..."})]})})});const ne=()=>{const I=f==="review"?"validation":f;return Ce.indexOf(I)},lt=t==="embed"?"ff-container ff-embed":"ff-container ff-modal",Le=l.jsx(l.Fragment,{children:l.jsxs("div",{className:lt,children:[l.jsxs("div",{className:"ff-modal-header",children:[l.jsxs("div",{className:"ff-modal-header-left",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-3",children:[l.jsx("div",{className:"ff-modal-icon",children:l.jsx(wt,{})}),l.jsx("h2",{className:"ff-modal-title",children:"Import Data"})]}),l.jsx("div",{className:"ff-steps ff-ml-4",children:Ce.map((I,M)=>l.jsxs(b.Fragment,{children:[l.jsx("div",{className:w.clsx("ff-step",ne()===M&&"ff-step-active",ne()>M&&"ff-step-complete",ne()<M&&"ff-step-pending"),children:ne()>M?"✓":M+1}),M<Ce.length-1&&l.jsx("div",{className:w.clsx("ff-step-connector",ne()>M&&"ff-step-connector-complete")})]},I))})]}),l.jsx("button",{onClick:ie,className:"ff-modal-close",children:l.jsx(w.X,{className:"ff-w-5 ff-h-5"})})]}),l.jsxs("div",{className:"ff-modal-body",children:[m&&l.jsx("div",{className:"ff-mb-4 ff-p-4 ff-border ff-rounded-lg ff-text-sm",style:{backgroundColor:"var(--ff-error-light)",borderColor:"var(--ff-error)",color:"var(--ff-error)"},children:m}),f==="upload"&&l.jsx("div",{className:"ff-py-4",children:l.jsx("div",{className:"ff-max-w-xl ff-mx-auto",children:u&&N>0?l.jsxs("div",{className:"ff-p-8 ff-text-center",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mx-auto ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{className:"ff-font-medium ff-mb-2",style:{color:"var(--ff-text-primary)"},children:z}),l.jsx("div",{className:"ff-progress ff-w-full ff-max-w-xs ff-mx-auto ff-mb-2",children:l.jsx("div",{className:"ff-progress-bar",style:{width:`${N}%`,transition:"width 0.3s ease"}})}),l.jsxs("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[N,"% complete"]})]}):l.jsx(Oe,{onFileSelect:Je})})}),f==="mapping"&&(u&&N>0?l.jsxs("div",{className:"ff-py-12 ff-text-center",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mx-auto ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{className:"ff-font-medium ff-mb-3",style:{color:"var(--ff-text-primary)"},children:z}),l.jsx("div",{className:"ff-progress ff-w-full ff-max-w-xs ff-mx-auto ff-mb-2",children:l.jsx("div",{className:"ff-progress-bar",style:{width:`${N}%`,transition:"width 0.3s ease"}})}),l.jsxs("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[N,"% complete"]})]}):l.jsx(Te,{})),f==="validation"&&l.jsxs("div",{className:"ff-space-y-6",children:[l.jsx($e,{}),l.jsx(Ie,{editable:!0})]}),f==="review"&&l.jsxs("div",{className:"ff-space-y-6",children:[l.jsx($e,{showDetails:!1}),l.jsx(Ie,{editable:!1,pageSize:10})]}),f==="complete"&&l.jsx("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:ke?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"ff-w-16 ff-h-16 ff-rounded-full ff-flex ff-items-center ff-justify-center ff-mb-4",style:{backgroundColor:"var(--ff-error-light)"},children:l.jsx(w.X,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-error)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Import Failed"}),l.jsx("p",{className:"ff-text-center ff-max-w-md ff-mb-4",style:{color:"var(--ff-text-muted)"},children:ke}),l.jsxs("div",{className:"ff-flex ff-gap-3",children:[l.jsx("button",{onClick:()=>{le(null),_("review")},className:"ff-btn ff-btn-secondary",children:"Back to Review"}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"ff-w-20 ff-h-20 ff-rounded-2xl ff-flex ff-items-center ff-justify-center ff-mb-6",style:{backgroundColor:"var(--ff-success-light)"},children:l.jsx(w.CircleCheckBig,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-success)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Import Complete!"}),l.jsx("p",{className:"ff-mb-6",style:{color:"var(--ff-text-muted)"},children:"Your data has been successfully imported."}),l.jsxs("div",{className:"ff-flex ff-gap-6 ff-mb-6",children:[l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-border-light)",backgroundColor:"var(--ff-bg-primary)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:(k==null?void 0:k.totalRows)??(c==null?void 0:c.totalRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Total Rows"})]}),l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-success)",backgroundColor:"var(--ff-success-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-success-dark)"},children:(k==null?void 0:k.importedRows)??(c==null?void 0:c.validRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-success)"},children:"Imported"})]}),((k==null?void 0:k.skippedRows)??0)>0&&l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-warning)",backgroundColor:"var(--ff-warning-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-warning-dark)"},children:(k==null?void 0:k.skippedRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-warning)"},children:"Skipped"})]}),l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-border-light)",backgroundColor:"var(--ff-bg-primary)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:g.filter(I=>I.targetKey!==null).length}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Columns Mapped"})]})]}),(k==null?void 0:k.data)&&k.data.length>0&&(()=>{const I=k.data.slice(0,5),M=I[0],P=(M==null?void 0:M.data)||M,K=Object.keys(typeof P=="object"?P:{}).slice(0,6),D=(L==null?void 0:L.columns)||[];return K.length===0?null:l.jsxs("div",{className:"ff-w-full ff-mb-6",children:[l.jsxs("p",{className:"ff-text-xs ff-font-semibold ff-uppercase ff-tracking-wider ff-mb-2",style:{color:"var(--ff-text-muted)"},children:["Data Preview (first ",I.length," rows)"]}),l.jsx("div",{className:"ff-table-container ff-max-h-[250px]",children:l.jsxs("table",{className:"ff-table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{style:{width:40},children:"#"}),K.map(H=>{const te=D.find(oe=>oe.key===H);return l.jsx("th",{children:(te==null?void 0:te.label)||H},H)}),K.length<Object.keys(typeof P=="object"?P:{}).length&&l.jsx("th",{children:"..."})]})}),l.jsx("tbody",{children:I.map((H,te)=>{const oe=(H==null?void 0:H.data)||H;return l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx("span",{className:"ff-font-mono ff-text-xs",style:{color:"var(--ff-text-muted)"},children:((H==null?void 0:H.rowIndex)??te)+1})}),K.map(De=>l.jsx("td",{children:l.jsx("span",{className:"ff-text-sm ff-truncate ff-block ff-max-w-[150px]",children:String((oe==null?void 0:oe[De])??"—")})},De)),K.length<Object.keys(typeof P=="object"?P:{}).length&&l.jsx("td",{children:l.jsx("span",{style:{color:"var(--ff-text-muted)"},children:"..."})})]},te)})})]})}),k.data.length>5&&l.jsxs("p",{className:"ff-text-xs ff-mt-1",style:{color:"var(--ff-text-muted)"},children:["Showing 5 of ",k.data.length," imported rows"]})]})})(),l.jsxs("div",{className:"ff-flex ff-gap-3",children:[l.jsx("button",{onClick:Ee,className:"ff-btn ff-btn-primary",children:"Start New Import"}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})]})})]}),l.jsx("div",{className:"ff-modal-footer",children:f==="complete"?l.jsxs(l.Fragment,{children:[l.jsx("div",{}),l.jsx("button",{onClick:Ee,className:"ff-btn ff-btn-primary",children:"Start New Import"})]}):l.jsxs(l.Fragment,{children:[l.jsx("button",{onClick:Q,disabled:ot()===0||u,className:"ff-btn ff-btn-ghost",children:"Back"}),l.jsx("button",{onClick:st,disabled:!rt()||u,className:"ff-btn ff-btn-primary",children:u?l.jsxs(l.Fragment,{children:[l.jsx(w.LoaderCircle,{className:"ff-w-4 ff-h-4 ff-animate-spin"}),"Processing..."]}):f==="review"?"Complete Import":"Continue"})]})})]})});return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:t==="modal"?l.jsx("div",{className:"ff-overlay",children:Le}):Le})};exports.ColumnMapper=Te;exports.DataTable=Ie;exports.FileUploader=Oe;exports.ImportWizard=Vn;exports.ValidationSummary=$e;exports.useImportStore=ee;
78
- //# sourceMappingURL=ImportWizard-Bueox6It.js.map
78
+ //# sourceMappingURL=ImportWizard-AygpIr0Y.js.map