1import{j as e}from"./vendor-ui-WIutmQvu.js";import{r as v,R as Et}from"./vendor-react-Mjzju8Fo.js";import{ag as Rt,S as At,bF as ke,$ as F,bC as Mt,B as Je,F as G,bG as Lt,bH as J,aM as le,bI as et,bJ as tt,bl as st,bj as Dt,C as ce,aP as $t,bK as Ft,aJ as I,aX as _e,aY as Ce,bL as at,aZ as Te,bf as it,bg as rt,a_ as Z,bM as It,bN as zt,bO as Wt,bP as Pe,bQ as Ot,bR as oe,aK as Y,A as B,bS as Bt,bT as ve,bU as Ht,G as qe,aj as Ue,bV as nt,H as Gt,bW as Kt,ak as ot,E as we,bX as Vt,aN as qt,aq as Ut,af as Xt,bY as Qt,bZ as Zt,b_ as Yt,bk as Xe,b$ as Jt,bs as es,c0 as ts,c1 as ss,ab as as,ac as is,c2 as rs,c3 as ns,ae as os,c4 as ls,Z as cs,aO as ds,T as ms}from"./ToolShell-Cj1RulUX.js";import{be as de,cY as ye,cS as us,cv as ps,j as hs,cR as gs,c as xs}from"./ToolLoadingSkeleton-BoTumGG9.js";import{C as k,n as A,o as M,p as _,B as ee}from"./index-CGeKhxlS.js";import{S as fs}from"./SmartFieldSelector-C2gU0v9n.js";import{u as bs}from"./useAnalysisCache-BxDbiygZ.js";import{q as fe,r as Ee,s as lt,t as ct,u as dt,v as mt,w as Re,x as Ae,y as vs,z as ys,D as js,E as Ns,F as ws,R as Ss,P as ks,m as _s,k as Cs,T as Ts,L as Ps}from"./vendor-charts-Dtasu9Ii.js";import{d as Es,b as Rs,a as As}from"./downloadUtils-ZbOEV_jP.js";import{w as Ms,u as O}from"./vendor-data-DfX1IQMU.js";import{t as ut}from"./truncation-DX7k8PX-.js";import{d as te,K as se,p as pt,f as ht}from"./resultProvenance-B0KIFgds.js";import{T as Ls}from"./TruncationBanner-DKW30tHo.js";import{u as Ds}from"./WorkstationDataBanner-WXyB-7xs.js";import{u as $s}from"./useFileLoader-4_J3GMz-.js";import{P as Fs}from"./ProcessingOverlay-evG_HBZ3.js";import{T as gt,a as xt,b as q,c as U}from"./tabs-CCPzWN16.js";import{R as Is}from"./reset-button-BGVfFqt7.js";import{P as zs}from"./ProcessingProgressOverlay-B6fIKTgl.js";import{L as Ws}from"./LargeDatasetHandler-DrR0Pk3m.js";import{g as Qe,a as Os,b as Bs}from"./dataSampling-BLby5lRG.js";import{g as Hs,c as ne}from"./dataProcessingConfig-DAJSaH9g.js";import{M as Gs}from"./index-CAidFLHU.js";import{D as Ks}from"./DashboardPageLayout-BDYR88x8.js";import{u as Vs}from"./WorkstationDataContext-B71S8xiE.js";import"./vendor-ai-LcOSHxZq.js";import{A as qs}from"./AmBestPracticesPanel-DSwFFlyS.js";import"./useWhiteLabel-3vub9u51.js";import"./userBrainLoader-61slGmfL.js";import"./vendor-supabase-4AdVcAsc.js";import"./checkbox-RmNFHI00.js";import"./columnFillStats-C7YBe9Ri.js";import"./filter-BRhMzzJF.js";import"./toggle-left-BYNTyFS4.js";import"./chevrons-up-down-DlD2PJSz.js";import"./safeCsv-D8dqx_aU.js";import"./defaultHealingRules-DwxSt-x5.js";import"./healingRulesEngine-B460FyzF.js";import"./scopedKeys-BBZGqdXQ.js";import"./lookupTables-DOLISixA.js";import"./sapTableMappings-DZCvqr84.js";import"./useDataWorker-CGfdnIeB.js";import"./demoAccessGuard-CRWjDrXP.js";import"./centralizedDataHandler-CIjlIF4h.js";import"./useToolReset-DSS0G6sO.js";import"./rotate-ccw-BpsxbSaS.js";import"./index-CGXTfhLO.js";import"./proxy-rrAUG4v2.js";import"./radio-group-D-LJwyJ2.js";import"./collapsible-i4zlFhDZ.js";import"./index-BFAz8H1a.js";import"./EnterprisePageHeader-CtAQ7jpB.js";import"./SEO-CUKSF61s.js";import"./trending-down-ChmSmJyA.js";import"./minus-DCVssX1V.js";import"./blockedFieldGuard-CchPMkRM.js";function Us({selectedColumns:r,onToggleColumn:s,onSelectAll:o,onClearAll:i,onAnalyze:a,loading:c,disabled:m,useCloudAI:g=!1,onToggleCloudAI:u}){const{data:p}=de(),n=p&&p.length>0?Object.keys(p[0]):[],l=t=>{const d=new Set(t);if(d.size===0)return i();if(d.size===n.length&&n.every(x=>d.has(x)))return o();const b=new Set(r),h=t.filter(x=>!b.has(x)),f=r.filter(x=>!d.has(x));if(h.length===1&&f.length===0)return s(h[0]);if(f.length===1&&h.length===0)return s(f[0]);i(),t.forEach(x=>s(x))};return e.jsxs(k,{children:[e.jsx(A,{children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs(M,{className:"text-lg",children:["Select Text Columns (",r.length,"/",n.length,")"]}),e.jsx("div",{className:"flex items-center gap-3",children:u&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg border border-border bg-muted/30",children:[e.jsx(Rt,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Local"}),e.jsx(At,{checked:g,onCheckedChange:u}),e.jsx(ke,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{className:"text-xs text-primary font-medium",children:"Local AI"}),g&&e.jsx(F,{variant:"outline",className:"text-[10px] px-1.5 py-0 border-primary/30 text-primary",children:"Local AI"})]})})]})}),e.jsxs(_,{children:[e.jsx("div",{className:"mb-6",children:e.jsx(fs,{columns:n,rows:
1p||[],selected:r,onChange:l,typeFilter:["text","mixed"],title:"Pick text columns to analyze",helperText:"Numeric and date columns are filtered out â text analysis runs on string content."})}),e.jsxs(ee,{onClick:a,disabled:m||c,children:[c?e.jsx(Mt,{className:"h-4 w-4 mr-2 animate-spin"}):g?e.jsx(ke,{className:"h-4 w-4 mr-2"}):e.jsx(Je,{className:"h-4 w-4 mr-2"}),c?"Analyzing...":g?"Analyze with Local AI":"Analyze Text"]})]})]})}Ee.register(lt,ct,dt,mt,Re,Ae);function Xs({column:r,analysis:s}){const o={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"bottom"}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-white p-6 rounded-xl shadow-sm",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4",children:["Sentiment Analysis: ",r]}),e.jsx("div",{className:"h-64",children:e.jsx(fe,{data:{labels:["Positive","Neutral","Negative"],datasets:[{label:"Sentiment Distribution",data:[s.sentiment[r]?.positive||0,s.sentiment[r]?.neutral||0,s.sentiment[r]?.negative||0],backgroundColor:["rgba(16, 185, 129, 0.8)","rgba(59, 130, 246, 0.8)","rgba(239, 68, 68, 0.8)"]}]},options:o})})]}),e.jsxs("div",{className:"bg-white p-6 rounded-xl shadow-sm",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4",children:["Entity Recognition: ",r]}),e.jsx("div",{className:"h-64",children:e.jsx(fe,{data:{labels:Object.keys(s.entities[r]||{}),datasets:[{label:"Entity Counts",data:Object.values(s.entities[r]||{}),backgroundColor:"rgba(99, 102, 241, 0.8)"}]},options:o})})]}),e.jsxs("div",{className:"bg-white p-6 rounded-xl shadow-sm",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4",children:["Topic Distribution: ",r]}),e.jsx("div",{className:"h-64",children:e.jsx(fe,{data:{labels:(s.topics[r]||[]).map(i=>i.name),datasets:[{label:"Topic Weight",data:(s.topics[r]||[]).map(i=>i.weight*100),backgroundColor:"rgba(245, 158, 11, 0.8)"}]},options:o})})]}),e.jsxs("div",{className:"bg-white p-6 rounded-xl shadow-sm",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4",children:["Readability Metrics: ",r]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx("span",{className:"text-sm font-medium text-gray-600",children:"Flesch Reading Ease"}),e.jsx("span",{className:"text-sm text-gray-900",children:s.readability[r]?.fleschReadingEase||s.readability[r]?.score||0})]}),e.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2",children:e.jsx("div",{className:"bg-indigo-600 h-2 rounded-full",style:{width:`${s.readability[r]?.fleschReadingEase||s.readability[r]?.score||0}%`}})})]}),e.jsx("div",{className:"bg-blue-50 p-3 rounded-lg mb-2",children:e.jsxs("p",{className:"text-sm text-blue-800 font-medium",children:["Reading Level: ",s.readability[r]?.level||"Unknown"]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Flesch-Kincaid Grade"}),e.jsx("p",{className:"text-lg font-semibold",children:s.readability[r]?.fleschKincaidGrade||0})]}),e.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Avg. Sentence Length"}),e.jsxs("p",{className:"text-lg font-semibold",children:[s.readability[r]?.avgSentenceLength||0," words"]})]}),e.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Avg. Word Length"}),e.jsxs("p",{className:"text-lg font-semibold",children:[s.readability[r]?.avgWordLength||0," chars"]})]}),e.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Reading Ease Score"}),e.jsxs("p",{className:"text-lg font-semibold",children:[s.readability[r]?.score||0,"/100"]})]})]})]})]})]})}function Ze({analysis:r,selectedColumns:s,fileName:o}){const i=s.reduce((h,f)=>{const x=r.sentiment[f];return x&&(h.positive+=Number(x.positive)||0,h.negative+=Number(x.negative)||0,h.neutral+=Number(x.neutral)||0),h},{positive:0,negative:0,neutral:0}),a=i.positive+i.negative+i.neutral,c=a>0?Math.round(i.positive/a*100):0,m=a>0?Math.round(i.negative/a*100):0,g=a>0?Math.round(i.neutral/a*100):0,u=s.reduce((h,f)=>{const x=r.readability[f],y=Number(x?.score)||0;return h+y},0)/Math.max(s.length,1),p=s.reduce((h,f)=>{const x=r.entities[f],y=Object.values(x||{}).reduce((E,R)=>{const D=Number(R)||0;return(Number(E)||0)+D},0);return h+Number(y)},0),l=s.flatMap(h=>r.topics[h]||[]).reduce((h,f)=>{const x=Number(f.weight)||0,y=Number(h[f.name])||0;return h[f.name]=y+x,h},{}),t=Object.entries(l).sort(([,h],[,f])=>Number(f)-Number(h)).slice(0,3).map(([h])=>h),d=()=>c>m&&c>g?e.jsx(le,{className:"h-5 w-5 text-slate-600"}):m>c&&m>g?e.jsx(et,{className:"h-5 w-5 text-slate-600"}):e.jsx(tt,{className:"h-5 w-5 text-slate-600"}),b=()=>c>m&&c>g?"Mostly Positive":m>c&&m>g?"Mostly Negative":"Mostly Neutral";return e.jsxs("div",{className:"bg-white p-6 rounded-xl shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Analysis Summary"}),o&&e.jsxs("div",{className:"flex items-center text-sm text-gray-600",children:[e.jsx(G,{className:"h-4 w-4 mr-1"}),o]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx("div",{className:"bg-gradient-to-r from-[#E3F2FD] to-[#E3F2FD] p-4 rounded-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-600",children:"Overall Sentiment"}),e.jsx("p",{className:"text-lg font-semibold text-gray-900",children:b()}),e.jsxs("p",{className:"text-xs text-gray-500",children:[c,"% positive, ",m,"% negative"]})]}),d()]})}),e.jsx("div",{className:"bg-gradient-to-r from-slate-50 to-gray-50 p-4 rounded-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-600",children:"Readability Score"}),e.jsxs("p",{className:"text-lg font-semibold text-gray-900",children:[u.toFixed(1),"/100"]}),e.jsx("p",{className:"text-xs text-gray-500",children:"Average across columns"})]}),e.jsx(Lt,{className:"h-5 w-5 text-slate-600"})]})}),e.jsx("div",{className:"bg-gradient-to-r from-[#E3F2FD] to-[#E3F2FD] p-4 rounded-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-600",children:"Entities Found"}),e.jsx("p",{className:"text-lg font-semibold text-gray-900",children:p}),e.jsx("p",{className:"text-xs text-gray-500",children:"Total identified entities"})]}),e.jsx(J,{className:"h-5 w-5 text-slate-600"})]})}),e.jsx("div",{className:"bg-gradient-to-r from-slate-50 to-gray-50 p-4 rounded-lg",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-600",children:"Columns Analyzed"}),e.jsx("p",{className:"text-lg font-semibold text-gray-900",children:s.length}),e.jsx("p",{className:"text-xs text-gray-500",children:"Text columns processed"})]}),e.jsx(G,{className:"h-5 w-5 text-slate-600"})]})})]}),t.length>0&&e.jsxs("div",{className:"mt-6",children:[e.jsx("h4",{className:"text-sm font-medium text-gray-700 mb-3",children:"Top Topics Identified"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.map((h,f)=>e.jsx("span",{className:`px-3 py-1 rounded-full text-xs font-medium ${f===0?"bg-[#E3F2FD] text-[#1E5A9E]":f===1?"bg-[#E3F2FD] text-[#3478BE]":"bg-gray-100 text-gray-800"}`,children:h},h))})]})]})}const Ye=5e3;function Qs(r){const o=r.slice(0,200).join(" ").toLowerCase(),i={English:["the","is","and","to","of","a","in","for","on","with","that","this","are","
1was","it"],Spanish:["el","la","de","que","y","en","los","se","del","las","un","por","con","para","una"],French:["le","la","de","et","les","des","en","un","une","du","dans","est","que","pour","qui"],German:["der","die","und","in","den","von","zu","das","mit","sich","des","auf","für","ist","nicht"]};let a=0,c="English";for(const[g,u]of Object.entries(i)){let p=0;for(const n of u){const l=new RegExp(`\\b${n}\\b`,"gi");p+=o.match(l)?.length||0}p>a&&(a=p,c=g)}const m=Math.min(95,Math.max(50,50+a*2));return{language:c,confidence:m}}function Zs(r,s){const o=r.length,i=o>Ye,a=i?Math.ceil(o/Ye):1,c=i?Math.ceil(o/a):o;let m=0,g=0,u=0,p=0;const n=new Set,l=[];for(const R of s)for(let D=0;D<o;D+=a){const z=String(r[D][R]||"");if(z.length===0)continue;g+=z.length,u+=z.replace(/\s/g,"").length;const me=z.split(/\s+/);for(const K of me)K.length!==0&&(m++,p+=K.length,n.size<1e5&&n.add(K.toLowerCase()));l.length<200&&l.push(z)}const t=i?o/c:1,d=Math.round(m*t),b=Math.round(g*t),h=Math.round(u*t),f=m>0?p/m:0,x=m>0?n.size/m*100:0,{language:y,confidence:E}=Qs(l);return{totalWords:d,totalCharacters:b,totalCharactersNoSpaces:h,uniqueWords:n.size,avgWordLength:Math.round(f*10)/10,vocabularyRichness:Math.round(x*10)/10,detectedLanguage:y,languageConfidence:E,isSampled:i}}function Ys({data:r,selectedColumns:s}){const o=v.useMemo(()=>!r||s.length===0?null:Zs(r,s),[r,s]);if(!o)return null;const i=[{icon:G,label:"Total Words",value:o.totalWords.toLocaleString(),color:"text-primary",bgColor:"bg-primary/10"},{icon:st,label:"Characters",value:o.totalCharacters.toLocaleString(),subValue:`${o.totalCharactersNoSpaces.toLocaleString()} without spaces`,color:"text-blue-600",bgColor:"bg-blue-50"},{icon:Dt,label:"Unique Words",value:o.uniqueWords.toLocaleString(),color:"text-purple-600",bgColor:"bg-purple-50"},{icon:ce,label:"Avg Word Length",value:`${o.avgWordLength} chars`,color:"text-amber-600",bgColor:"bg-amber-50"},{icon:$t,label:"Vocabulary Richness",value:`${o.vocabularyRichness}%`,subValue:"unique/total ratio",color:"text-emerald-600",bgColor:"bg-emerald-50"},{icon:Ft,label:"Detected Language",value:o.detectedLanguage,subValue:`${o.languageConfidence}% confidence`,color:"text-rose-600",bgColor:"bg-rose-50"}];return e.jsxs(k,{className:"bg-card border border-border shadow-professional overflow-hidden",children:[e.jsx(A,{className:"pb-4 bg-gradient-to-br from-muted/50 to-background border-b border-border",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(I,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(M,{className:"text-lg font-semibold text-foreground",children:"Text Statistics"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-0.5",children:["Analyzing ",s.length," column",s.length>1?"s":""," across ",r?.length.toLocaleString()," rows",o.isSampled&&e.jsx("span",{className:"text-xs ml-1",children:"(sampled for speed)"})]})]})]})}),e.jsx(_,{className:"p-6",children:e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:i.map((a,c)=>e.jsxs("div",{className:"flex flex-col p-4 rounded-xl border border-border bg-background hover:shadow-md transition-shadow",children:[e.jsx("div",{className:`p-2 rounded-lg ${a.bgColor} w-fit mb-3`,children:e.jsx(a.icon,{className:`h-4 w-4 ${a.color}`})}),e.jsx("span",{className:"text-xs text-muted-foreground font-medium uppercase tracking-wide",children:a.label}),e.jsx("span",{className:"text-xl font-bold text-foreground mt-1",children:a.value}),a.subValue&&e.jsx("span",{className:"text-xs text-muted-foreground mt-0.5",children:a.subValue})]},c))})})]})}function Js({analysis:r,selectedColumns:s,fileName:o}){const{toast:i}=ye(),a=o?.replace(/\.[^/.]+$/,"")||"text_analysis",c=new Date().toISOString().split("T")[0],m=()=>{const n=ea(r,s,o);Es(n,`${a}_report_${c}.html`),i({title:"Report Downloaded",description:"HTML report saved successfully"})},g=()=>{const n={metadata:{fileName:o,selectedColumns:s,exportDate:new Date().toISOString(),analysisType:"Text Analysis",provenance:r?.provenance??te(se.textAnalysis),truncationNotices:r?.truncationNotices??[]},results:r};As(n,`${a}_analysis_${c}.json`),i({title:"Data Exported",description:"JSON file saved successfully"})},u=()=>{const n=ta(r,s);Rs(n,`${a}_analysis_${c}.csv`),i({title:"Data Exported",description:"CSV file saved successfully"})},p=()=>{const n=sa(r,s);Ms(n,`${a}_analysis_${c}.xlsx`),i({title:"Data Exported",description:"Excel file saved successfully"})};return e.jsxs(_e,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(ee,{variant:"outline",className:"gap-2",children:[e.jsx(at,{className:"h-4 w-4"}),"Export"]})}),e.jsxs(Te,{align:"end",className:"w-56 bg-popover border border-border shadow-lg z-50",children:[e.jsx(it,{className:"text-foreground",children:"Export Options"}),e.jsx(rt,{}),e.jsxs(Z,{onClick:m,className:"cursor-pointer gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-primary"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"HTML Report"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Formatted visual report"})]})]}),e.jsxs(Z,{onClick:u,className:"cursor-pointer gap-2",children:[e.jsx(It,{className:"h-4 w-4 text-emerald-600"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"CSV Data"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Raw data in table format"})]})]}),e.jsxs(Z,{onClick:g,className:"cursor-pointer gap-2",children:[e.jsx(zt,{className:"h-4 w-4 text-amber-600"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"JSON Data"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Complete analysis results"})]})]}),e.jsxs(Z,{onClick:p,className:"cursor-pointer gap-2",children:[e.jsx(Wt,{className:"h-4 w-4 text-green-600"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:"Excel Workbook"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Multi-sheet spreadsheet"})]})]})]})]})}function ea(r,s,o){const i=()=>s.map(a=>{const c=r.sentiment?.[a]||{positive:0,negative:0,neutral:0};return` 2 <div class="column-section"> 3 <h4>${a}</h4> 4 <div class="sentiment-bars"> 5 <div class="bar positive" style="width: ${c.positive}%">Positive: ${c.positive}%</div> 6 <div class="bar neutral" style="width: ${c.neutral}%">Neutral: ${c.neutral}%</div> 7 <div class="bar negative" style="width: ${c.negative}%">Negative: ${c.negative}%</div> 8 </div> 9 </div> 10 `}).join("");return`<!DOCTYPE html> 11<html lang="en"> 12<head> 13 <meta charset="UTF-8"> 14 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 15 <title>Text Analysis Report - ${o||"Analysis"}</title> 16 <style> 17 * { box-sizing: border-box; margin: 0; padding: 0; } 18 body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #1a1a1a; background: #f8f9fa; } 19 .container { max-width: 1200px; margin: 0 auto; padding: 2rem; } 20 .header { background: linear-gradient(135deg, #0070F2, #3399FF); color: white; padding: 3rem 2rem; border-radius: 12px; margin-bottom: 2rem; } 21 .header h1 { font-size: 2rem; margin-bottom: 0.5rem; } 22 .header p { opacity: 0.9; } 23 .card { background: white; border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: 0 2px 8px rgba(0,0,0,0.08); } 24 .card h3 { color: #0070F2; margin-bottom: 1rem; border-bottom: 2px solid #e5e7eb; padding-bottom: 0.5rem; } 25 .column-section { margin: 1rem 0; padding: 1rem; background: #f8f9fa; border-radius: 8px; } 26 .column-section h4 { font-size: 1rem; color: #374151; margin-bottom: 0.75rem; } 27 .sentiment-bars { display: flex; flex-direction: column; gap: 0.5rem; } 28 .bar { padding: 0.5rem 1rem; border-radius: 4px; font-size: 0.875rem; color: white; min-width: 100px; } 29 .bar.positive { background: #28A745; } 30 .bar.neutral { background: #6b7280; } 31 .bar.negative { background: #ef4444; } 32 .meta { color: #6b7280; font-size: 0.875rem; } 33 .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; } 34 .stat-item { padding: 1rem; background: #f8f9fa; border-radius: 8px; text-align: center; } 35 .stat-value { font-size: 1.5rem; font-weight: bold; color: #0070F2; } 36 .stat-label { font-size: 0.875rem; color: #6b7280; } 37 </style> 38</head> 39<body> 40 <div class="container"> 41 <div class="header"> 42 <h1>Text Analysis Report</h1> 43 <p class="meta">File: ${o||"Unknown"}
43 | Generated: ${new Date().toLocaleString()}</p> 44 </div> 45 ${r?.truncationNotices?.length?`<div class="card"> 46 <h3>Partial Results â Truncation Notices</h3> 47 ${ut(r.truncationNotices)} 48 </div>`:""} 49 <div class="card"> 50 <h3>Result Provenance</h3> 51 ${pt(r?.provenance??te(se.textAnalysis))} 52 </div> 53 <div class="card"> 54 <h3>Sentiment Analysis</h3> 55 ${i()} 56 </div> 57 <div class="card"> 58 <h3>Analysis Summary</h3> 59 <div class="grid"> 60 <div class="stat-item"> 61 <div class="stat-value">${s.length}</div> 62 <div class="stat-label">Columns Analyzed</div> 63 </div> 64 <div class="stat-item"> 65 <div class="stat-value">${Object.keys(r.entities||{}).reduce((a,c)=>a+Object.keys(r.entities[c]||{}).length,0)}</div> 66 <div class="stat-label">Entity Types Found</div> 67 </div> 68 <div class="stat-item"> 69 <div class="stat-value">${Object.keys(r.topics||{}).reduce((a,c)=>a+(r.topics[c]?.length||0),0)}</div> 70 <div class="stat-label">Topics Identified</div> 71 </div> 72 </div> 73 </div> 74 </div> 75</body> 76</html>`}function ta(r,s){const o=[];return o.push({column:"# provenance",sentiment_positive:ht(r?.provenance??te(se.textAnalysis))}),(r?.truncationNotices??[]).forEach(i=>{o.push({column:"# truncation",sentiment_positive:`${i.scope}: analysed ${i.limit} of ${i.actual} â ${i.reason}`})}),s.forEach(i=>{const a=r.sentiment?.[i]||{},c=r.readability?.[i]||{},m=r.entities?.[i]||{},g=r.topics?.[i]||[];o.push({column:i,sentiment_positive:a.positive||0,sentiment_negative:a.negative||0,sentiment_neutral:a.neutral||0,readability_score:c.score||0,readability_level:c.level||"N/A",flesch_grade:c.fleschKincaidGrade||0,entity_types:Object.keys(m).join("; "),entity_counts:Object.values(m).join("; "),top_topics:g.slice(0,5).map(u=>u.name).join("; ")})}),o}function sa(r,s,o){const i=O.book_new(),a=s.map(n=>({Column:n,"Positive %":r.sentiment?.[n]?.positive||0,"Neutral %":r.sentiment?.[n]?.neutral||0,"Negative %":r.sentiment?.[n]?.negative||0,"Readability Score":r.readability?.[n]?.score||0,"Reading Level":r.readability?.[n]?.level||"N/A"})),c=O.json_to_sheet(a);O.book_append_sheet(i,c,"Summary");const m=r?.provenance??te(se.textAnalysis),g=[{Field:"Model",Value:m.modelId},{Field:"Quantisation",Value:m.quantisation},{Field:"Kernel Version",Value:m.kernelVersion},...(r?.truncationNotices??[]).map(n=>({Field:`Truncation â ${n.scope}`,Value:`analysed ${n.limit} of ${n.actual} â ${n.reason}`}))];O.book_append_sheet(i,O.json_to_sheet(g),"Provenance");const u=[];if(s.forEach(n=>{const l=r.entities?.[n]||{};Object.entries(l).forEach(([t,d])=>{u.push({Column:n,"Entity Type":t,Count:d})})}),u.length>0){const n=O.json_to_sheet(u);O.book_append_sheet(i,n,"Entities")}const p=[];if(s.forEach(n=>{(r.topics?.[n]||[]).forEach((t,d)=>{p.push({Column:n,Rank:d+1,Topic:t.name,Weight:t.weight})})}),p.length>0){const n=O.json_to_sheet(p);O.book_append_sheet(i,n,"Topics")}return i}function aa(r){const s=["text-primary","text-blue-600","text-purple-600","text-emerald-600","text-amber-600","text-rose-600","text-cyan-600","text-indigo-600"];return s[Math.floor(Math.random()*s.length)]}function ia(r){const i=12+r*24;return`${Math.round(i)}px`}function ra({words:r,maxWords:s=30}){const o=v.useMemo(()=>{if(!r||r.length===0)return[];const a=[...r].sort((p,n)=>n.weight-p.weight).slice(0,s),c=a.map(p=>p.weight),m=us(c),u=ps(c)-m||1;return a.map(p=>({text:p.text,weight:p.weight,normalizedWeight:(p.weight-m)/u,color:aa((p.weight-m)/u),fontSize:ia((p.weight-m)/u),rotation:Math.random()>.7?Math.random()>.5?"rotate-6":"-rotate-6":""}))},[r,s]),i=v.useMemo(()=>[...o].sort(()=>Math.random()-.5),[o]);return i.length===0?e.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"No topics to display"}):e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-3 p-4 min-h-[200px]",children:i.map((a,c)=>e.jsx("span",{className:` 77 ${a.color} 78 ${a.rotation} 79 font-medium 80 cursor-default 81 transition-all 82 duration-200 83 hover:scale-110 84 hover:opacity-80 85 `,style:{fontSize:a.fontSize,opacity:.7+a.normalizedWeight*.3},title:`Weight: ${a.weight.toFixed(2)}`,children:a.text},`${a.text}-${c}`))})}function na({sentiment:r,columnSentiments:s,selectedColumns:o=[]}){const i=r.positive+r.neutral+r.negative,a=i>0?Math.round(r.positive/i*100):0,c=i>0?Math.round(r.negative/i*100):0,m=i>0?Math.round(r.neutral/i*100):0,g=a-c,p=(l=>l>=60?{label:"Strongly Positive",color:"text-emerald-600",bg:"bg-emerald-50"}:l>=30?{label:"Moderately Positive",color:"text-emerald-500",bg:"bg-emerald-50"}:l>=10?{label:"Slightly Positive",color:"text-emerald-400",bg:"bg-emerald-50"}:l>=-10?{label:"Neutral",color:"text-muted-foreground",bg:"bg-secondary"}:l>=-30?{label:"Slightly Negative",color:"text-amber-500",bg:"bg-amber-50"}:l>=-60?{label:"Moderately Negative",color:"text-red-500",bg:"bg-red-50"}:{label:"Strongly Negative",color:"text-red-600",bg:"bg-red-50"})(g),n=g/100*90;return e.jsxs(k,{className:"bg-card border border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 bg-emerald-50 rounded-lg",children:e.jsx(Pe,{className:"h-4 w-4 text-emerald-600"})}),e.jsx(M,{className:"text-base font-semibold text-foreground",children:"Sentiment Analysis"})]})}),e.jsxs(_,{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative w-48 h-24 overflow-hidden",children:[e.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-24 rounded-t-full bg-gradient-to-r from-red-200 via-gray-200 to-emerald-200"}),e.jsx("div",{className:"absolute bottom-0 left-4 right-4 h-20 rounded-t-full bg-card"}),e.jsx("div",{className:"absolute bottom-0 left-1/2 w-1 h-16 bg-foreground rounded-t origin-bottom transition-transform duration-500",style:{transform:`translateX(-50%) rotate(${n}deg)`}}),e.jsx("div",{className:"absolute bottom-0 left-1/2 w-4 h-4 bg-foreground rounded-full -translate-x-1/2 translate-y-1/2"})]}),e.jsxs("div",{className:"text-center mt-4",children:[e.jsxs("div",{className:`text-3xl font-bold ${p.color}`,children:[g>0?"+":"",g]}),e.jsx("div",{className:`text-sm font-medium px-3 py-1 rounded-full mt-2 ${p.bg} ${p.color}`,children:p.label})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:"Distribution"})}),e.jsxs("div",{className:"h-4 rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"bg-emerald-500 transition-all duration-500",style:{width:`${a}%`},title:`Positive: ${a}%`}),e.jsx("div",{className:"bg-gray-300 transition-all duration-500",style:{width:`${m}%`},title:`Neutral: ${m}%`}),e.jsx("div",{className:"bg-red-500 transition-all duration-500",style:{width:`${c}%`},title:`Negative: ${c}%`})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"text-center p-3 bg-emerald-50 rounded-lg",children:[e.jsx(le,{className:"h-4 w-4 text-emerald-600 mx-auto mb-1"}),e.jsxs("div",{className:"text-xl font-bold text-emerald-600",children:[a,"%"]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Positive"})]}),e.jsxs("div",{className:"text-center p-3 bg-secondary rounded-lg",children:[e.jsx(tt,{className:"h-4 w-4 text-muted-foreground mx-auto mb-1"}),e.jsxs("div",{className:"text-xl font-bold text-muted-foreground",children:[m,"%"]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Neutral"})]}),e.jsxs("div",{className:"text-center p-3 bg-red-50 rounded-lg",children:[e.jsx(et,{className:"h-4 w-4 text-red-600 mx-auto mb-1"}),e.jsxs("div",{className:"text-xl font-bold text-red-600",children:[c,"%"]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Negative"})]})]}),s&&o.length>1&&e.jsxs("div",{className:"space-y-3 pt-4 border-t border-border",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Column Comparison"}
85),o.slice(0,5).map(l=>{const t=s[l]||{positive:0,neutral:0,negative:0},d=t.positive+t.neutral+t.negative,b=d>0?Math.round(t.positive/d*100):0,h=d>0?Math.round(t.negative/d*100):0,f=b-h;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-foreground truncate max-w-[60%]",children:l}),e.jsxs("span",{className:f>=0?"text-emerald-600":"text-red-600",children:[f>0?"+":"",f]})]}),e.jsxs("div",{className:"h-2 rounded-full overflow-hidden flex bg-secondary",children:[e.jsx("div",{className:"bg-emerald-500",style:{width:`${b}%`}}),e.jsx("div",{className:"bg-red-500",style:{width:`${h}%`,marginLeft:`${100-b-h}%`}})]})]},l)})]})]})]})}const oa=[{name:"Children's Books",grade:3,score:95,color:"bg-emerald-500"},{name:"Newspapers",grade:8,score:65,color:"bg-blue-500"},{name:"Academic Papers",grade:12,score:40,color:"bg-amber-500"},{name:"Legal Documents",grade:16,score:20,color:"bg-red-500"}];function la({readability:r,selectedColumns:s}){const o=s.map(t=>r[t]?.fleschReadingEase||0).filter(t=>t>0),i=o.length>0?Math.round(o.reduce((t,d)=>t+d,0)/o.length):0,a=s.map(t=>r[t]?.fleschKincaidGrade||0).filter(t=>t>0),c=a.length>0?Math.round(a.reduce((t,d)=>t+d,0)/a.length*10)/10:0,m=s.map(t=>r[t]?.avgSentenceLength||0).filter(t=>t>0).reduce((t,d,b,h)=>t+d/h.length,0),u=(t=>t>=90?{label:"Very Easy",desc:"Easily understood by 5th graders",color:"text-emerald-600",icon:oe}:t>=80?{label:"Easy",desc:"Conversational English",color:"text-emerald-500",icon:oe}:t>=70?{label:"Fairly Easy",desc:"Suitable for 7th graders",color:"text-blue-500",icon:oe}:t>=60?{label:"Standard",desc:"Plain English, 8th-9th grade",color:"text-blue-600",icon:Y}:t>=50?{label:"Fairly Hard",desc:"High school level",color:"text-amber-500",icon:B}:t>=30?{label:"Hard",desc:"College level reading",color:"text-amber-600",icon:B}:{label:"Very Hard",desc:"College graduate level",color:"text-red-600",icon:B})(i),p=u.icon,l=(()=>{const t=[];return i<60&&t.push("Consider using shorter sentences for better readability"),m>20&&t.push("Average sentence length is high. Try breaking up long sentences"),c>12&&t.push("Text complexity is at college level. Simplify vocabulary if targeting general audience"),i>=70&&i<80&&t.push("Good readability! Consider minor simplifications for broader accessibility"),i>=80&&t.push("Excellent readability! Text is accessible to most readers"),t})();return e.jsxs(k,{className:"bg-card border border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 bg-blue-50 rounded-lg",children:e.jsx(ce,{className:"h-4 w-4 text-blue-600"})}),e.jsx(M,{className:"text-base font-semibold text-foreground",children:"Readability Analysis"})]})}),e.jsxs(_,{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative w-40 h-40",children:[e.jsxs("svg",{className:"w-full h-full -rotate-90",children:[e.jsx("circle",{cx:"80",cy:"80",r:"70",fill:"none",stroke:"currentColor",strokeWidth:"12",className:"text-secondary"}),e.jsx("circle",{cx:"80",cy:"80",r:"70",fill:"none",stroke:"currentColor",strokeWidth:"12",strokeDasharray:`${i/100*440} 440`,strokeLinecap:"round",className:i>=60?"text-emerald-500":i>=40?"text-amber-500":"text-red-500"})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:"text-3xl font-bold text-foreground",children:i}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"/ 100"})]})]}),e.jsxs("div",{className:`flex items-center gap-2 mt-3 px-3 py-1.5 rounded-full ${i>=60?"bg-emerald-50":i>=40?"bg-amber-50":"bg-red-50"}`,children:[e.jsx(p,{className:`h-4 w-4 ${u.color}`}),e.jsx("span",{className:`text-sm font-medium ${u.color}`,children:u.label})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:u.desc})]}),e.jsx("div",{className:"p-4 bg-gradient-to-br from-primary/5 to-primary/10 rounded-xl",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg",children:e.jsx(Ot,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-foreground",children:c}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Grade Level (Flesch-Kincaid)"})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Compared to Common Standards"}),e.jsx("div",{className:"space-y-2",children:oa.map(t=>{i<=t.score;const d=Math.abs(i-t.score)<15;return e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:d?"font-medium text-foreground":"text-muted-foreground",children:t.name}),e.jsxs("span",{className:"text-muted-foreground",children:["~",t.score]})]}),e.jsxs("div",{className:"h-2 bg-secondary rounded-full overflow-hidden relative",children:[e.jsx("div",{className:`h-full ${t.color} opacity-30`,style:{width:`${t.score}%`}}),d&&e.jsx("div",{className:"absolute top-0 h-full w-1 bg-foreground rounded",style:{left:`${i}%`}})]})]})},t.name)}
85)})]}),s.length>1&&e.jsxs("div",{className:"space-y-3 pt-4 border-t border-border",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"By Column"}),s.slice(0,5).map(t=>{const d=r[t]||{},b=d.fleschReadingEase||0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-foreground truncate max-w-[60%]",children:t}),e.jsxs("span",{className:"text-muted-foreground",children:[Math.round(b)," ⢠Grade ",d.fleschKincaidGrade||0]})]}),e.jsx("div",{className:"h-2 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${b>=60?"bg-emerald-500":b>=40?"bg-amber-500":"bg-red-500"}`,style:{width:`${Math.min(100,b)}%`}})})]},t)})]}),l.length>0&&e.jsxs("div",{className:"space-y-2 pt-4 border-t border-border",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Recommendations"}),l.map((t,d)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted-foreground",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-primary mt-1.5 flex-shrink-0"}),e.jsx("span",{children:t})]},d))]})]})]})}Ee.register(ys,js,Ns,ws,Re,Ae);function ca({topics:r,selectedColumns:s}){const o={};s.forEach(t=>{(r[t]||[]).forEach(b=>{o[b.name]=(o[b.name]||0)+b.weight})});const i=Object.entries(o).sort(([,t],[,d])=>d-t),a=i.slice(0,8),c=i.slice(0,15),m=a[0]?.[1]||1,g=a.slice(0,6),u={labels:g.map(([t])=>t.length>12?t.slice(0,12)+"...":t),datasets:[{label:"Topic Weight",data:g.map(([,t])=>t/m*100),backgroundColor:"rgba(8, 145, 178, 0.2)",borderColor:"rgba(8, 145, 178, 1)",borderWidth:2,pointBackgroun
85dColor:"rgba(8, 145, 178, 1)",pointBorderColor:"#fff",pointHoverBackgroundColor:"#fff",pointHoverBorderColor:"rgba(8, 145, 178, 1)"}]},p={responsive:!0,maintainAspectRatio:!1,scales:{r:{angleLines:{color:"rgba(0, 0, 0, 0.1)"},grid:{color:"rgba(0, 0, 0, 0.1)"},pointLabels:{font:{size:11}},ticks:{display:!1},suggestedMin:0,suggestedMax:100}},plugins:{legend:{display:!1}}},l=(t=>{const d={Business:[],Technical:[],People:[],General:[]},b=["sales","revenue","market","business","customer","growth","profit","strategy"],h=["data","system","software","technology","code","api","server","algorithm"],f=["team","employee","manager","leader","staff","people","user","client"];return t.forEach(([x,y])=>{const E=x.toLowerCase();b.some(R=>E.includes(R))?d.Business.push([x,y]):h.some(R=>E.includes(R))?d.Technical.push([x,y]):f.some(R=>E.includes(R))?d.People.push([x,y]):d.General.push([x,y])}),d})(c);return e.jsxs(k,{className:"bg-card border border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 bg-amber-50 rounded-lg",children:e.jsx(Bt,{className:"h-4 w-4 text-amber-600"})}),e.jsx(M,{className:"text-base font-semibold text-foreground",children:"Topic Analysis"})]})}),e.jsx(_,{className:"space-y-6",children:a.length===0?e.jsx("div",{className:"h-48 flex items-center justify-center text-muted-foreground",children:"No topics identified"}):e.jsxs(e.Fragment,{children:[g.length>=3&&e.jsx("div",{className:"h-52",children:e.jsx(vs,{data:u,options:p})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-sm font-medium text-foreground flex items-center gap-2",children:[e.jsx(le,{className:"h-4 w-4 text-amber-600"}),"Top Topics by Frequency"]}),a.map(([t,d],b)=>{const h=Math.round(d/m*100),f=["bg-amber-500","bg-orange-500","bg-cyan-500","bg-emerald-500","bg-purple-500","bg-blue-500","bg-pink-500","bg-indigo-500"];return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"font-medium text-foreground flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${f[b%f.length]}`}),t]}),e.jsxs("span",{className:"text-muted-foreground",children:[h,"%"]})]}),e.jsx("div",{className:"h-2 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full ${f[b%f.length]} rounded-full transition-all duration-500`,style:{width:`${h}%`}})})]},t)})]}),e.jsxs("div",{className:"space-y-3 pt-4 border-t border-border",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Topic Categories"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Object.entries(l).filter(([,t])=>t.length>0).map(([t,d])=>e.jsxs("div",{className:"p-3 bg-secondary/50 rounded-lg",children:[e.jsx("div",{className:"text-xs font-medium text-foreground mb-1",children:t}),e.jsx("div",{className:"text-lg font-bold text-primary",children:d.length}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[d.slice(0,2).map(([b])=>b).join(", "),d.length>2&&"..."]})]},t))})]})]})})]})}function da({texts:r,selectedColumns:s}){const o=v.useMemo(()=>{const c=new Set(["the","a","an","is","are","was","were","be","been","being","have","has","had","do","does","did","will","would","could","should","may","might","must","shall","can","need","to","of","in","for","on","with","at","by","from","as","into","through","during","and","but","or","nor","so","yet","not","only","own","same","than","too","very","just","also","now","here","there","when","where","why","how","all","each","every","both","few","more","most","other","some","such","no","any","this","that","these","those","what","which","who","whom","whose","i","me","my","we","our","you","your","he","him","his","she","her","it","its","they","them","their","about","over","under","again","then"]),m={},g={};r.flat().forEach(n=>{if(!n||typeof n!="string")return;const l=n.toLowerCase().replace(/[^a-z\s]/g,"").split(/\s+/).filter(t=>t.length>2);for(let t=0;t<l.length-1;t++){const d=l[t],b=l[t+1];if((!c.has(d)||!c.has(b))&&!c.has(d)&&!c.has(b)){const h=`${d} ${b}`;m[h]=(m[h]||0)+1}}for(let t=0;t<l.length-2;t++){const d=l[t],b=l[t+1],h=l[t+2];if([d,b,h].filter(x=>!c.has(x)).length>=2){const x=`${d} ${b} ${h}`;g[x]=(g[x]||0)+1}}});const u=Object.entries(m).filter(([,n])=>n>=2).sort(([,n],[,l])=>l-n).slice(0,10),p=Object.entries(g).filter(([,n])=>n>=2).sort(([,n],[,l])=>l-n).slice(0,8);return{bigrams:u,trigrams:p}},[r]),i=[...o.trigrams,...o.bigrams].slice(0,12),a=i[0]?.[1]||1;return e.jsxs(k,{className:"bg-card border border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 bg-purple-50 rounded-lg",children:e.jsx(ve,{className:"h-4 w-4 text-purple-600"})}),e.jsx(M,{className:"text-base font-semibold text-foreground",children:"Key Phrases (N-Grams)"})]})}),e.jsx(_,{className:"space-y-6",children:i.length===0?e.jsx("div",{className:"h-32 flex items-center justify-center text-muted-foreground text-sm",children:"Not enough text data to extract phrases"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:i.slice(0,8).map(([c,m],g)=>{const u=.8+m/a*.6,p=.6+m/a*.4;return e.jsxs("div",{className:"px-3 py-1.5 bg-gradient-to-r from-purple-100 to-indigo-100 rounded-full border border-purple-200/50",style:{fontSize:`${u}rem`,opacity:p},children:[e.jsx("span",{className:"text-purple-700 font-medium",children:c}),e.jsxs("span",{className:"text-purple-400 ml-1.5 text-xs",children:["(",m,")"]})]},c)})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[o.trigrams.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[e.jsx(Ht,{className:"h-4 w-4 text-purple-500"}),"3-Word Phrases"]}),e.jsx("div",{className:"space-y-1.5",children:o.trigrams.slice(0,5).map(([c,m])=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-foreground",children:c}),e.jsxs("span",{className:"text-muted-foreground bg-secondary px-2 py-0.5 rounded text-xs",children:[m,"x"]})]},c))})]}),o.bigrams.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-foreground",children:[e.jsx(st,{className:"h-4 w-4 text-indigo-500"}),"2-Word Phrases"]}),e.jsx("div",{className:"space-y-1.5",children:o.bigrams.slice(0,5).map(([c,m])=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-foreground",children:c}),e.jsxs("span",{className:"text-muted-foreground bg-secondary px-2 py-0.5 rounded text-xs",children:[m,"x"]})]},c))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 pt-4 border-t border-border",children:[e.jsxs("div",{className:"p-3 bg-secondary/50 rounded-lg text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-purple-600",children:o.bigrams.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Unique 2-Grams"})]}),e.jsxs("div",{className:"p-3 bg-secondary/50 rounded-lg text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-indigo-600",children:o.trigrams.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Unique 3-Grams"})]})]})]})})]})}function ma({analysis:r,selectedColumns:s}){const o=s.reduce((x,y)=>{const E=r.sentiment?.[y]||{positive:0,neutral:0,negative:0};return{positive:x.positive+E.positive,neutral:x.neutral+E.neutral,negative:x.negative+E.negative}},{positive:0,neutral:0,negative:0}),i=o.positive+o.neutral+o.negative,a=i>0?Math.round(o.positive/i*100):0,c=i>0?Math.round(o.negative/i*100):0,m=s.map(x=>r.readability?.[x]?.fleschReadingEase||0).filter(x=>x>0),g=m.length>0?Math.round(m.reduce((x,y)=>x+y,0)/m.length):0,u=s.map(x=>r.readability?.[x]?.avgSentenceLength||0).filter(x=>x>0).reduce((x,y,E,R)=>x+y/R.length,0),p={};
85s.forEach(x=>{(r.topics?.[x]||[]).forEach(y=>{p[y.name]=(p[y.name]||0)+y.weight})});const n=Object.entries(p).sort(([,x],[,y])=>y-x).slice(0,3),l={};s.forEach(x=>{Object.entries(r.entities?.[x]||{}).forEach(([y,E])=>{l[y]=(l[y]||0)+E})});const t=[];a>=60?t.push({type:"positive",title:"Strong Positive Sentiment",description:`${a}% of your text content has positive sentiment. This indicates favorable tone overall.`,icon:le}):c>=40?t.push({type:"warning",title:"Negative Sentiment Detected",description:`${c}% of content shows negative sentiment. Review for potential issues or concerns being expressed.`,icon:B}):t.push({type:"info",title:"Balanced Sentiment",description:"Your text shows a mix of positive, neutral, and negative tones across the content.",icon:Y}),g>=70?t.push({type:"positive",title:"Excellent Readability",description:`Score of ${g}/100 indicates clear, accessible writing suitable for general audiences.`,icon:oe}):g>=50?t.push({type:"info",title:"Moderate Readability",description:`Score of ${g}/100 suggests college-level reading. Consider simplifying for broader reach.`,icon:Y}):g>0&&t.push({type:"warning",title:"Complex Text Detected",description:`Low readability score (${g}/100). Text may be difficult for average readers.`,icon:B}),u>25?t.push({type:"warning",title:"Long Sentences",description:`Average ${Math.round(u)} words per sentence. Consider breaking into shorter sentences.`,icon:B}):u>0&&u<=15&&t.push({type:"positive",title:"Concise Writing",description:`Average ${Math.round(u)} words per sentence keeps content punchy and readable.`,icon:oe}),n.length>=3&&t.push({type:"info",title:"Key Topics Identified",description:`Main themes: ${n.map(([x])=>x).join(", ")}. Content appears focused on these areas.`,icon:qe});const d=Object.values(l).reduce((x,y)=>x+y,0);d>10&&t.push({type:"info",title:"Rich Entity Content",description:`Found ${d} entities including ${Object.keys(l).join(", ")}. Content is data-rich.`,icon:I});const b=Math.round(Math.min(g,100)*.4+a*.3+(100-c)*.3),f=(x=>x>=80?{label:"Excellent",color:"text-emerald-600",bg:"bg-emerald-50"}:x>=60?{label:"Good",color:"text-blue-600",bg:"bg-blue-50"}:x>=40?{label:"Fair",color:"text-amber-600",bg:"bg-amber-50"}:{label:"Needs Work",color:"text-red-600",bg:"bg-red-50"})(b);return e.jsxs(k,{className:"bg-card border border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 bg-gradient-to-br from-amber-50 to-orange-50 rounded-lg",children:e.jsx(qe,{className:"h-4 w-4 text-amber-600"})}),e.jsx(M,{className:"text-base font-semibold text-foreground",children:"Key Insights & Recommendations"})]})}),e.jsxs(_,{className:"space-y-6",children:[e.jsxs("div",{className:"p-4 bg-gradient-to-br from-primary/5 to-primary/10 rounded-xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Overall Text Quality"}),e.jsx("div",{className:`text-3xl font-bold ${f.color}`,children:b})]}),e.jsx("div",{className:`px-4 py-2 rounded-full ${f.bg}`,children:e.jsx("span",{className:`font-semibold ${f.color}`,children:f.label})})]}),e.jsx("div",{className:"mt-3 h-2 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-700 ${b>=60?"bg-emerald-500":b>=40?"bg-amber-500":"bg-red-500"}`,style:{width:`${b}%`}})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Key Findings"}),t.map((x,y)=>{const E=x.icon,D={positive:{bg:"bg-emerald-50",icon:"text-emerald-600",border:"border-emerald-200"},warning:{bg:"bg-amber-50",icon:"text-amber-600",border:"border-amber-200"},info:{bg:"bg-blue-50",icon:"text-blue-600",border:"border-blue-200"}}[x.type];return e.jsx("div",{className:`p-3 rounded-lg ${D.bg} border ${D.border}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(E,{className:`h-5 w-5 ${D.icon} flex-shrink-0 mt-0.5`}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground text-sm",children:x.title}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:x.description})]})]})},y)})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 pt-4 border-t border-border",children:[e.jsxs("div",{className:"p-2 bg-secondary/50 rounded-lg text-center",children:[e.jsx("div",{className:"text-lg font-bold text-foreground",children:s.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Columns"})]}),e.jsxs("div",{className:"p-2 bg-secondary/50 rounded-lg text-center",children:[e.jsx("div",{className:"text-lg font-bold text-foreground",children:Object.keys(p).length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Topics"})]}),e.jsxs("div",{className:"p-2 bg-secondary/50 rounded-lg text-center",children:[e.jsx("div",{className:"text-lg font-bold text-foreground",children:d}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Entities"})]})]})]})]})}Ee.register(lt,ct,dt,mt,Re,Ae);function ua({analysis:r,selectedColumns:s}){const{data:o}=de(),i=s.reduce((n,l)=>{const t=r.sentiment?.[l]||{positive:0,neutral:0,negative:0};return{positive:n.positive+t.positive,neutral:n.neutral+t.neutral,negative:n.negative+t.negative}},{positive:0,neutral:0,negative:0}),a={};
85s.forEach(n=>{const l=r.entities?.[n]||{};Object.entries(l).forEach(([t,d])=>{a[t]=(a[t]||0)+d})});const c={};s.forEach(n=>{(r.topics?.[n]||[]).forEach(t=>{c[t.name]=(c[t.name]||0)+t.weight})});const m=Object.entries(c).sort(([,n],[,l])=>l-n).slice(0,25),g=s.map(n=>(o||[]).map(l=>String(l[n]||"")).filter(l=>l.length>0)),u={labels:Object.keys(a),datasets:[{label:"Entity Count",data:Object.values(a),backgroundColor:"rgba(139, 92, 246, 0.8)",borderRadius:6}]},p={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1}},scales:{y:{beginAtZero:!0,grid:{color:"rgba(0, 0, 0, 0.05)"}},x:{grid:{display:!1}}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(na,{sentiment:i,columnSentiments:r.sentiment,selectedColumns:s}),e.jsx(la,{readability:r.readability||{},selectedColumns:s})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(ca,{topics:r.topics||{},selectedColumns:s}),e.jsx(ma,{analysis:r,selectedColumns:s})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(da,{texts:g,selectedColumns:s}),e.jsxs(k,{className:"bg-card border border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 bg-purple-50 rounded-lg",children:e.jsx(J,{className:"h-4 w-4 text-purple-600"})}),e.jsx(M,{className:"text-base font-semibold text-foreground",children:"Entity Recognition"})]})}),e.jsx(_,{children:Object.keys(a).length>0?e.jsx("div",{className:"h-[280px]",children:e.jsx(fe,{data:u,options:p})}):e.jsx("div",{className:"h-[280px] flex items-center justify-center text-muted-foreground",children:"No entities detected"})})]})]}),e.jsxs(k,{className:"bg-card border border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-2 bg-gradient-to-br from-primary/20 to-purple-100 rounded-lg",children:e.jsx(ke,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx(M,{className:"text-base font-semibold text-foreground",children:"Topic Word Cloud"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Visual representation of discovered topics - larger words appear more frequently"})]})]})}),e.jsx(_,{children:e.jsx("div",{className:"min-h-[250px] bg-gradient-to-br from-muted/30 via-background to-muted/20 rounded-xl border border-border/50",children:e.jsx(ra,{words:m.map(([n,l])=>({text:n,weight:l})),maxWords:25})})})]})]})}const pa={name:"Customer Reviews",description:"50 product reviews with mixed sentiment for sentiment analysis demo",columns:["review_id","product_name","review_text","category"],data:[{review_id:"R001",product_name:"Wireless Earbuds Pro",review_text:"Absolutely love these earbuds! Crystal clear sound quality and the battery life is amazing. Best purchase I've made this year.",category:"Electronics"},{review_id:"R002",product_name:"Smart Watch X",review_text:"Disappointed with the build quality. The screen cracked after just two weeks of normal use. Not worth the premium price.",category:"Electronics"},{review_id:"R003",product_name:"Running Shoes Elite",review_text:"These shoes are incredibly comfortable for long runs. Great arch support and lightweight design.",category:"Footwear"},{review_id:"R004",product_name:"Coffee Maker Deluxe",review_text:"Makes decent coffee but the machine is quite noisy. The interface could be more intuitive.",category:"Kitchen"},{review_id:"R005",product_name:"Laptop Stand Pro",review_text:"Perfect for my home office setup. Sturdy, adjustable, and looks professional. Highly recommend!",category:"Office"},{review_id:"R006",product_name:"Wireless Mouse",review_text:"Good mouse for the price. Battery lasts about a month. Wish it had more programmable buttons.",category:"Electronics"},{review_id:"R007",product_name:"Yoga Mat Premium",review_text:"Excellent grip and cushioning. No slipping during hot yoga sessions. Worth every penny.",category:"Fitness"},{review_id:"R008",product_name:"Bluetooth Speaker",review_text:"Terrible sound quality at high volumes. Bass is almost non-existent. Very disappointed.",category:"Electronics"},{review_id:"R009",product_name:"Travel Backpack",review_text:"Perfect size for weekend trips. Lots of compartments and the laptop sleeve is very secure.",category:"Travel"},{review_id:"R010",product_name:"Air Purifier",review_text:"Noticed a significant improvement in air quality. Quiet operation and easy filter replacement.",category:"Home"},{review_id:"R011",product_name:"Mechanical Keyboard",review_text:"Amazing typing experience! The tactile feedback is perfect for both work and gaming.",category:"Electronics"},{review_id:"R012",product_name:"Fitness Tracker",review_text:"Inaccurate step counting and the heart rate monitor seems unreliable. App crashes frequently.",category:"Electronics"},{review_id:"R013",product_name:"Standing Desk",review_text:"Great quality desk. Smooth height adjustment and very stable. My back pain has reduced significantly.",category:"Office"},{review_id:"R014",product_name:"Noise Canceling Headphones",review_text:"The noise cancellation is outstanding. Perfect for focusing in noisy environments.",category:"Electronics"},{review_id:"R015",product_name:"Smart Home Hub",review_text:"Setup was complicated and it doesn't work well with all my smart devices. Customer support was unhelpful.",category:"Smart Home"},{review_id:"R016",product_name:"Electric Toothbrush",review_text:"Gentle on gums and leaves teeth feeling clean. Battery lasts for weeks. Great upgrade from manual brushing.",category:"Personal Care"},{review_id:"R017",product_name:"Portable Charger",review_text:"Fast charging and compact design. Perfect for travel. Can charge my phone three times on a single charge.",category:"Electronics"},{review_id:"R018",product_name:"Instant Pot",review_text:"Game changer for meal prep! Makes cooking so much faster and easier. Love the multiple cooking modes.",category:"Kitchen"},{review_id:"R019",product_name:"Webcam HD",review_text:"Poor image quality in low light. Autofocus is slow and often misses. Not recommended for video calls.",category:"Electronics"},{review_id:"R020",product_name:"Ergonomic Chair",review_text:"Best chair I've ever owned. Perfect lumbar support and highly adjustable. No more back pain!",category:"Office"},{review_id:"R021",product_name:"Robot Vacuum",review_text:"Does an okay job on hard floors but struggles with carpet. Gets stuck frequently under furniture.",category:"Home"},{review_id:"R022",product_name:"Wireless Charger",review_text:"Convenient and works great with my phone. Charges a bit slower than wired but worth the convenience.",category:"Electronics"},{review_id:"R023",product_name:"Plant Grow Light",review_text:"My plants are thriving! Easy to install and the timer function is very useful.",category:"Home"},{review_id:"R024",product_name:"Smart Thermostat",review_text:"Reduced my energy bills by 20%. The app is intuitive and scheduling is straightforward.",category:"Smart Home"},{review_id:"R025",product_name:"Resistance Bands Set",review_text:"Great for home workouts. Different resistance levels allow for progressive training.",category:"Fitness"},{review_id:"R026",product_name:"Desk Lamp LED",review_text:"Eye-friendly lighting with adjustable brightness. USB charging port is a
85nice bonus.",category:"Office"},{review_id:"R027",product_name:"Water Bottle Insulated",review_text:"Keeps drinks cold for 24 hours. No leaks and fits in my car cup holder. Excellent quality.",category:"Accessories"},{review_id:"R028",product_name:"Streaming Stick",review_text:"Buggy interface and frequent buffering issues. Remote stopped working after a month.",category:"Electronics"},{review_id:"R029",product_name:"Blender Pro",review_text:"Powerful motor handles everything. Makes smooth smoothies and can even crush ice easily.",category:"Kitchen"},{review_id:"R030",product_name:"External SSD",review_text:"Incredibly fast transfer speeds. Compact and reliable. Perfect for backing up important files.",category:"Electronics"},{review_id:"R031",product_name:"Weighted Blanket",review_text:"Helps me sleep so much better. The weight is evenly distributed and the fabric is breathable.",category:"Home"},{review_id:"R032",product_name:"Wireless Doorbell",review_text:"Easy installation and clear video quality. Motion detection works well day and night.",category:"Smart Home"},{review_id:"R033",product_name:"Beard Trimmer",review_text:"Gives a precise trim every time. Long battery life and the attachments are useful.",category:"Personal Care"},{review_id:"R034",product_name:"Monitor Light Bar",review_text:"Reduces eye strain significantly. No screen glare and the touch controls are responsive.",category:"Office"},{review_id:"R035",product_name:"Protein Shaker",review_text:"No clumps! The mixing ball works perfectly. Leak-proof and easy to clean.",category:"Fitness"},{review_id:"R036",product_name:"Smart Lock",review_text:"Installation was difficult without professional help. Fingerprint reader sometimes fails.",category:"Smart Home"},{review_id:"R037",product_name:"Tablet Stand",review_text:"Sturdy and adjustable. Perfect for watching videos or video calls. Great value for money.",category:"Accessories"},{review_id:"R038",product_name:"Electric Kettle",review_text:"Boils water quickly and has precise temperature settings. Perfect for tea and coffee enthusiasts.",category:"Kitchen"},{review_id:"R039",product_name:"Gaming Mouse Pad",review_text:"Smooth surface for precise mouse movements. The RGB lighting is a nice aesthetic touch.",category:"Gaming"},{review_id:"R040",product_name:"Massage Gun",review_text:"Great for post-workout recovery. Multiple attachments and intensity levels. Highly effective.",category:"Fitness"},{review_id:"R041",product_name:"USB Hub",review_text:"All ports work well but it runs quite hot during extended use. Could use better build quality.",category:"Electronics"},{review_id:"R042",product_name:"Foot Massager",review_text:"Relaxing after a long day on my feet. Heat function adds to the comfort. A bit loud though.",category:"Personal Care"},{review_id:"R043",product_name:"Smart Plug",review_text:"Works seamlessly with voice assistants. Easy to set up schedules and monitor energy usage.",category:"Smart Home"},{review_id:"R044",product_name:"Drawing Tablet",review_text:"Pressure sensitivity is excellent. Great for digital artists. Driver software needs improvement.",category:"Electronics"},{review_id:"R045",product_name:"Neck Pillow",review_text:"Memory foam is comfortable. Perfect for long flights. Wish it came with a carrying case.",category:"Travel"},{review_id:"R046",product_name:"Air Fryer",review_text:"Makes crispy food with minimal oil. Easy to clean basket. A must-have kitchen appliance!",category:"Kitchen"},{review_id:"R047",product_name:"Desk Organizer",review_text:"Keeps my workspace tidy. Good quality materials and modern design. Very satisfied.",category:"Office"},{review_id:"R048",product_name:"Humidifier",review_text:"Quiet operation and large water tank. Helped with my dry skin during winter months.",category:"Home"},{review_id:"R049",product_name:"Cable Management Kit",review_text:"Finally got my desk cables organized! Easy to use and looks professional.",category:"Office"},{review_id:"R050",product_name:"Night Light",review_text:"Motion sensor works perfectly. Soft light doesn't disturb sleep. Great for hallways and bathrooms.",category:"Home"}]},ha={name:"Support Tickets",description:"35 customer support tickets for issue analysis",columns:["ticket_id","subject","description","priority"],data:[{ticket_id:"T001",subject:"Login Issues",description:"Cannot login to my account since yesterday. Password reset email never arrives. Please help urgently!",priority:"High"},{ticket_id:"T002",subject:"Billing Question",description:"I was charged twice for my subscription this month. Please refund the duplicate charge.",priority:"Medium"},{ticket_id:"T003",subject:"Feature Request",description:"Would be great to have dark mode option in the mobile app. Many users would appreciate this.",priority:"Low"},{ticket_id:"T004",subject:"App Crash",description:"The app crashes every time I try to upload a file larger than 10MB. This is very frustrating.",priority:"High"},{ticket_id:"T005",subject:"Account Deletion",description:"I want to delete my account and all associated data. Please confirm the process.",priority:"Medium"},{ticket_id:"T006",subject:"Integration Help",description:"Need assistance setting up the API integration with our CRM system. Documentation is unclear.",priority:"Medium"},{ticket_id:"T007",subject:"Slow Performance",description:"The dashboard has been loading very slowly for the past week. Takes over 30 seconds.",priority:"High"},{ticket_id:"T008",subject:"Export Not Working",description:"CSV export fails with an error message. Need to export data for monthly reporting.",priority:"High"},{ticket_id:"T009",subject:"Password Policy",description:"Can you explain the password requirements? I keep getting an error when creating a new password.",priority:"Low"},{ticket_id:"T010",subject:"Mobile Sync",description:"Changes made on mobile are not syncing to the web version. Data appears different.",priority:"High"},{ticket_id:"T011",subject:"Upgrade Plan",description:"I would like to upgrade from Basic to Professional plan. What are the next steps?",priority:"Low"},{ticket_id:"T012",subject:"Missing Features",description:"The bulk import feature mentioned in the documentation is not available in my account.",priority:"Medium"},{ticket_id:"T013",subject:"Security Concern",description:"I received a suspicious email claiming to be from your company. Is this legitimate?",priority:"High"},{ticket_id:"T014",subject:"Training Request",description:"Our team needs training on the advanced features. Do you offer webinars or tutorials?",priority:"Low"},{ticket_id:"T015",subject:"Data Recovery",description:"Accidentally deleted important project files. Is there a way to recover them?",priority:"High"},{ticket_id:"T016",subject:"Invoice Request",description:"Please send me an invoice for the last 6 months of service for tax purposes.",priority:"Low"},{ticket_id:"T017",subject:"API Rate Limits",description:"Our application is hitting rate limits frequently. Can we increase our API quota?",priority:"Medium"}
85,{ticket_id:"T018",subject:"Team Permissions",description:"Unable to add new team members. The invite button is grayed out.",priority:"Medium"},{ticket_id:"T019",subject:"Report Inaccuracy",description:"The analytics report shows different numbers than what I see in the dashboard.",priority:"Medium"},{ticket_id:"T020",subject:"Notification Settings",description:"I'm receiving too many email notifications. How do I customize my preferences?",priority:"Low"},{ticket_id:"T021",subject:"Browser Compatibility",description:"The platform doesn't work properly in Safari. Buttons are not clickable.",priority:"High"},{ticket_id:"T022",subject:"Webhook Failure",description:"Webhooks stopped working since last update. No events are being received.",priority:"High"},{ticket_id:"T023",subject:"Calendar Integration",description:"Google Calendar sync creates duplicate events. Very confusing for scheduling.",priority:"Medium"},{ticket_id:"T024",subject:"Custom Domain",description:"How do I set up a custom domain for my workspace? Need step-by-step instructions.",priority:"Low"},{ticket_id:"T025",subject:"Two-Factor Auth",description:"Lost my phone and can't access 2FA codes. Need to regain access to my account.",priority:"High"},{ticket_id:"T026",subject:"Attachment Limit",description:"What is the maximum file size for attachments? Getting upload failures.",priority:"Low"},{ticket_id:"T027",subject:"SSO Setup",description:"We want to implement SSO with Azure AD. Please provide configuration details.",priority:"Medium"},{ticket_id:"T028",subject:"Compliance Question",description:"Is your platform GDPR compliant? Need this info for our legal team.",priority:"Medium"},{ticket_id:"T029",subject:"Bulk User Import",description:"Need to import 500 users from CSV. The import keeps timing out.",priority:"High"},{ticket_id:"T030",subject:"White Label Option",description:"Interested in white labeling your solution for our clients. Is this possible?",priority:"Low"},{ticket_id:"T031",subject:"Data Backup",description:"How often is our data backed up? Where are backups stored?",priority:"Low"},{ticket_id:"T032",subject:"Search Not Working",description:"Search results are not showing recent items. Index seems outdated.",priority:"Medium"},{ticket_id:"T033",subject:"Template Missing",description:"The project templates that were available last week are no longer showing.",priority:"Medium"},{ticket_id:"T034",subject:"Timezone Issue",description:"All timestamps show wrong timezone. How do I change my timezone settings?",priority:"Low"},{ticket_id:"T035",subject:"Contract Renewal",description:"Our enterprise contract is expiring next month. Please contact us to discuss renewal.",priority:"Medium"}]},ga={name:"Product Descriptions",description:"40 product descriptions for content analysis",columns:["product_id","name","description","specifications"],data:[{product_id:"P001",name:"UltraBook Pro 15",description:"Experience unparalleled performance with our flagship laptop featuring 11th Gen Intel Core i7 processor and stunning 4K OLED display.",specifications:'16GB RAM, 512GB SSD, 15.6" Display'},{product_id:"P002",name:"CloudSync Storage 2TB",description:"Secure cloud storage solution with end-to-end encryption, automatic backup, and seamless cross-device synchronization.",specifications:"2TB Storage, AES-256 Encryption"},{product_id:"P003",name:"SmartHub Home Center",description:"The heart of your smart home. Control lights, thermostat, security cameras, and more from a single intuitive interface.",specifications:"WiFi 6, Zigbee, Z-Wave Compatible"},{product_id:"P004",name:"AeroFit Running Shoes",description:"Engineered for speed with responsive cushioning, breathable mesh upper, and carbon fiber plate for explosive energy return.",specifications:"Available sizes: 6-14, Weight: 210g"},{product_id:"P005",name:"PureBreeze Air Purifier",description:"Advanced HEPA filtration captures 99.97% of airborne particles. Whisper-quiet operation perfect for bedrooms and offices.",specifications:"Coverage: 500 sq ft, 3 Speed Settings"},{product_id:"P006",name:"ChefMaster Pro Blender",description:"Professional-grade blender with 1500W motor, variable speed control, and self-cleaning function for effortless meal preparation.",specifications:"64oz Container, BPA-Free"},{product_id:"P007",name:"NightOwl Security Camera",description:"24/7 surveillance with 4K HDR video, color night vision, and AI-powered person detection. Weather-resistant for outdoor use.",specifications:"4K Resolution, IP67 Rated"},{product_id:"P008",name:"ZenDesk Ergonomic Chair",description:"Premium office chair with adjustable lumbar support, breathable mesh back, and 4D armrests for all-day comfort.",specifications:"Max Weight: 300lbs, 5-Year Warranty"}
85,{product_id:"P009",name:"SoundWave Earbuds Pro",description:"Immersive audio experience with active noise cancellation, transparency mode, and 8 hours of battery life.",specifications:"Bluetooth 5.2, IPX4 Water Resistant"},{product_id:"P010",name:"PowerVault 20000",description:"High-capacity portable charger with 20000mAh battery, USB-C PD charging, and ability to charge three devices simultaneously.",specifications:"65W Output, Weight: 340g"},{product_id:"P011",name:"FlexStand Monitor Arm",description:"Premium aluminum monitor arm with gas spring mechanism, cable management, and 360-degree rotation for optimal viewing angles.",specifications:'Supports 17-32" Monitors, VESA Compatible'},{product_id:"P012",name:"BrewMaster Coffee System",description:"Barista-quality coffee at home with built-in grinder, milk frother, and customizable brewing profiles for your perfect cup.",specifications:"15 Bar Pressure, Bean Hopper: 250g"},{product_id:"P013",name:"FitTrack Pro Watch",description:"Advanced fitness tracking with heart rate monitoring, GPS, blood oxygen sensor, and 14-day battery life.",specifications:'1.4" AMOLED, 5ATM Water Resistant'},{product_id:"P014",name:"QuietType Keyboard",description:"Ultra-quiet mechanical keyboard with customizable RGB backlighting, hot-swappable switches, and premium PBT keycaps.",specifications:"Wireless + Wired, Mac/PC Compatible"},{product_id:"P015",name:"ClearView Webcam 4K",description:"Crystal-clear video conferencing with 4K resolution, autofocus, low-light correction, and dual stereo microphones.",specifications:"4K@30fps, 1080p@60fps"},{product_id:"P016",name:"TravelLite Luggage Set",description:"Lightweight yet durable luggage with TSA-approved locks, 360-degree spinner wheels, and expandable compartments.",specifications:'Set of 3: 20", 24", 28"'},{product_id:"P017",name:"GreenThumb Planter Kit",description:"Smart indoor garden with automated watering, LED grow lights, and companion app for plant care guidance.",specifications:'6 Pod Capacity, Height: 18"'},{product_id:"P018",name:"ProShot Action Camera",description:"Capture every adventure in stunning 5K video with electronic image stabilization, waterproof design, and voice control.",specifications:"5K@30fps, Waterproof to 33ft"},{product_id:"P019",name:"RelaxPro Massage Chair",description:"Full-body massage chair with zero-gravity positioning, heat therapy, and 12 customizable massage programs.",specifications:'Dimensions: 65x35x48"'},{product_id:"P020",name:"StudyDesk Electric",description:"Height-adjustable standing desk with memory presets, anti-collision technology, and spacious 60x30 inch surface.",specifications:'Height Range: 28-48", Weight Capacity: 350lbs'},{product_id:"P021",name:"VisionPro Gaming Monitor",description:"Competitive edge with 240Hz refresh rate, 1ms response time, and NVIDIA G-Sync for tear-free gaming.",specifications:'27" QHD, HDR600'},{product_id:"P022",name:"AquaPure Water Filter",description:"Advanced multi-stage filtration removes 99% of contaminants while preserving essential minerals for great-tasting water.",specifications:"Filter Life: 6 months"},{product_id:"P023",name:"SleepWell Mattress King",description:"Premium hybrid mattress combining memory foam comfort with pocketed coil support for your best sleep ever.",specifications:'King Size, 12" Height, 100-Night Trial'},{product_id:"P024",name:"CleanBot Robot Vacuum",description:"Intelligent navigation with room mapping, scheduled cleaning, and automatic dirt disposal for hands-free maintenance.",specifications:"150 min Runtime, 2500Pa Suction"},{product_id:"P025",name:"QuickCharge Wall Adapter",description:"Compact GaN charger with 100W output, compatible with laptops, tablets, and smartphones for fast charging anywhere.",specifications:"100W, 2x USB-C, 1x USB-A"},{product_id:"P026",name:"SafeGuard Door Lock",description:"Keyless smart lock with fingerprint recognition, app control, and temporary access codes for guests and service providers.",specifications:"100 Fingerprint Capacity"},{product_id:"P027",name:"FlexFit Resistance Kit",description:"Complete home workout system with adjustable resistance bands, door anchor, handles, and guided workout app.",specifications:"5-150lbs Resistance Range"},{product_id:"P028",name:"LightStream Desk Lamp",description:"Eye-care LED lamp with adjustable color temperature, brightness levels, and built-in USB charging port.",specifications:"5 Color Temps, 10 Brightness Levels"},{product_id:"P029",name:"TechGear Laptop Bag",description:"Professional laptop backpack with padded compartment, anti-theft pocket, and waterproof exterior for daily commute.",specifications:'Fits up to 17" Laptops'},{product_id:"P030",name:"ChillMax Mini Fridge",description:"Compact refrigerator perfect for dorms and offices with adjustable thermostat and reversible door.",specifications:"4.5 cu ft, Energy Star Certified"},{product_id:"P031",name:"SoundBar Pro 5.1",description:"Immersive home theater audio with wireless subwoofer, Dolby Atmos supp
85ort, and easy TV connection.",specifications:"500W Total Output"},{product_id:"P032",name:"SmartScale Body Analyzer",description:"Comprehensive health tracking with body fat percentage, muscle mass, BMI, and heart rate measurements synced to your phone.",specifications:"Supports 8 Users, Weight: 400lbs Max"},{product_id:"P033",name:"DroneView Explorer",description:"Aerial photography drone with 4K camera, 30-minute flight time, and GPS return-to-home for stunning aerial footage.",specifications:"4K Camera, Range: 5 miles"},{product_id:"P034",name:"PrintMaster 3D Pro",description:"High-resolution 3D printer with auto-leveling bed, resume print function, and large build volume for creative projects.",specifications:"Build Size: 300x300x400mm"},{product_id:"P035",name:"StreamDeck Controller",description:"Content creator essential with customizable LCD keys, macro actions, and seamless integration with popular streaming software.",specifications:"15 LCD Keys, USB-C Connection"},{product_id:"P036",name:"GlowSkin Beauty Device",description:"Professional-grade skincare with LED light therapy, microcurrent treatment, and sonic massage for radiant skin.",specifications:"5 Treatment Modes, USB Rechargeable"},{product_id:"P037",name:"ThermoSmart Kettle",description:"Precision temperature control kettle with presets for different tea types and keep-warm function for the perfect brew.",specifications:"1.7L Capacity, 6 Temp Presets"},{product_id:"P038",name:"GameStation Pro Console",description:"Next-generation gaming with 8K output, ray tracing graphics, and ultra-fast SSD for instant loading.",specifications:"1TB SSD, 4K@120fps"},{product_id:"P039",name:"AirFresh Diffuser",description:"Elegant essential oil diffuser with whisper-quiet operation, color-changing LED, and auto shut-off for aromatherapy relaxation.",specifications:"300ml Capacity, 8-Hour Runtime"},{product_id:"P040",name:"SafeBox Digital Safe",description:"Secure storage with electronic keypad, biometric access, and pry-resistant construction for valuables and documents.",specifications:"1.2 cu ft, Fire Resistant 30min"}]},be=[pa,ha,ga];function ft(r){return r.data}const xa={"Customer Reviews":ve,"Support Tickets":Gt,"Product Descriptions":nt};function fa(){const{setData:r,setFileName:s}=de(),{toast:o}=ye(),i=a=>{const c=be.find(g=>g.name===a);if(!c)return;const m=ft(c);r(m),s(`${c.name.replace(/\s+/g,"_")}_sample.csv`),o({title:"Sample Data Loaded",description:`Loaded ${m.length} rows from "${c.name}" dataset`})};return e.jsxs(_e,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(ee,{variant:"outline",className:"gap-2",children:[e.jsx(Ue,{className:"h-4 w-4"}),"Try Sample Data",e.jsx(F,{variant:"secondary",className:"ml-1 text-xs",children:"Demo"})]})}),e.jsxs(Te,{align:"center",className:"w-72 bg-popover border border-border shadow-lg z-50",children:[e.jsx(it,{className:"text-foreground",children:"Load Sample Dataset"}),e.jsx(rt,{}),be.map(a=>{const c=xa[a.name]||Ue;return e.jsx(Z,{onClick:()=>i(a.name),className:"cursor-pointer p-3",children:e.jsxs("div",{className:"flex items-start gap-3 w-full",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg shrink-0",children:e.jsx(c,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("span",{className:"font-medium text-foreground",children:a.name}),e.jsx("span",{className:"text-xs text-muted-foreground line-clamp-2",children:a.description}),e.jsxs("div",{className:"flex gap-1 mt-1.5 flex-wrap",children:[a.columns.slice(0,3).map(m=>e.jsx(F,{variant:"outline",className:"text-[10px] px-1.5",children:m},m)),a.columns.length>3&&e.jsxs(F,{variant:"outline",className:"text-[10px] px-1.5",children:["+",a.columns.length-3]})]})]})]})},a.name)})]})]})}const ba=[{icon:Pe,title:"Sentiment Analysis",description:"Detect positive, negative, and neutral tones"},{icon:ce,title:"Readability Scores",description:"Flesch-Kincaid grade level analysis"},{icon:ot,title:"Topic Discovery",description:"Automatic theme extraction"},{icon:ve,title:"Key Phrases",description:"N-gram phrase extraction"},{icon:J,title:"Entity Recognition",description:"People, places, organizations"},{icon:I,title:"AI Insights",description:"Actionable recommendations"}],Q={sentimentScore:65,sentimentLabel:"Mostly Positive",readabilityScore:72,readabilityGrade:"8th Grade",topics:[{name:"Technology",weight:35},{name:"Business",weight:28},{name:"Customer",weight:22},{name:"Quality",weight:15}],insights:["Text shows strong positive sentiment overall","Reading level appropriate for general audience","Clear focus on technology and business themes"]};function va({onProgress:r}){const{hasData:s}=Ds(),{setData:o,setFileName:i}=de(),{toast:a}=ye(),[c,m]=Et.useState(!1),{isLoading:g,progress:u,stage:p,loadFile:n}=$s(),l=async h=>{try{const f=await n(h);o(f.data),i(f.fileName),a({title:"File uploaded successfully",description:`Loa
85ded ${f.data.length.toLocaleString()} rows from ${f.fileName}`})}catch(f){a({title:"Error processing file",description:f instanceof Error?f.message:"Failed to process file",variant:"destructive"})}},t=h=>{h.preventDefault(),m(!1);const f=Array.from(h.dataTransfer.files);f.length>0&&l(f[0])},d=h=>{const f=h.target.files?.[0];f&&l(f)},b=h=>{const f=be.find(x=>x.name===h);if(f){const x=ft(f);o(x),i(`${f.name} (Sample)`),a({title:"Sample data loaded",description:`Loaded ${x.length} rows from "${f.name}"`})}};return e.jsxs(e.Fragment,{children:[e.jsx(Fs,{isVisible:g,progress:u,stage:p}),e.jsxs("div",{className:"space-y-8",children:[!s&&e.jsx(k,{className:"border-2 border-dashed border-border bg-card/50",children:e.jsx(_,{className:"p-8",children:e.jsxs("div",{className:`text-center transition-colors rounded-lg p-6 ${c?"bg-primary/5":""}`,onDrop:t,onDragOver:h=>{h.preventDefault(),m(!0)},onDragLeave:()=>m(!1),children:[e.jsx("input",{type:"file",id:"file-upload-empty",className:"hidden",accept:".csv,.xlsx,.xls",onChange:d}),e.jsx("div",{className:"p-4 bg-primary/10 rounded-full w-fit mx-auto mb-4",children:e.jsx(Kt,{className:"h-8 w-8 text-primary"})}),e.jsx("h3",{className:"text-xl font-semibold text-foreground mb-2",children:"Analyze your text data"}),e.jsx("p",{className:"text-muted-foreground mb-6 max-w-md mx-auto",children:"Drag and drop your CSV or Excel file here, or click to browse. We'll analyze sentiment, readability, and extract insights."}),e.jsxs("div",{className:"flex items-center justify-center gap-3",children:[e.jsx("label",{htmlFor:"file-upload-empty",children:e.jsx(ee,{asChild:!0,children:e.jsxs("span",{className:"cursor-pointer",children:[e.jsx(G,{className:"h-4 w-4 mr-2"}),"Choose File"]})})}),e.jsxs(_e,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(ee,{variant:"outline",children:"Try Sample Data"})}),e.jsx(Te,{align:"center",className:"w-64",children:be.map(h=>e.jsxs(Z,{onClick:()=>b(h.name),className:"flex flex-col items-start py-3",children:[e.jsx("span",{className:"font-medium",children:h.name}),e.jsx("span",{className:"text-xs text-muted-foreground line-clamp-1",children:h.description})]},h.name))})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-4",children:"Supports: CSV, XLS, XLSX"})]})})}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:ba.map(h=>e.jsx(k,{className:"bg-card/50 border-border/50 hover:border-primary/30 transition-colors",children:e.jsxs(_,{className:"p-4 text-center",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg w-fit mx-auto mb-2",children:e.jsx(h.icon,{className:"h-5 w-5 text-primary"})}),e.jsx("h4",{className:"text-sm font-medium text-foreground mb-1",children:h.title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h.description})]})},h.title))}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-background via-background/80 to-transparent z-10 flex items-end justify-center pb-8",children:e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 bg-primary/10 text-primary px-4 py-2 rounded-full mb-3",children:[e.jsx(I,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Preview"})]}),e.jsx("p",{className:"text-muted-foreground",children:"Load data or upload a file to see full analysis with AI insights"})]})}),e.jsxs("div",{className:"opacity-60 blur-[2px] pointer-events-none select-none",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mb-6",children:[e.jsx(k,{className:"bg-card border-border",children:e.jsxs(_,{className:"p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4 flex items-center gap-2",children:[e.jsx(Pe,{className:"h-5 w-5 text-primary"}),"Sentiment Analysis"]}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs("div",{className:"relative w-32 h-16",children:[e.jsxs("svg",{viewBox:"0 0 100 50",className:"w-full h-full",children:[e.jsx("path",{d:"M 10 45 A 40 40 0 0 1 90 45",fill:"none",stroke:"hsl(var(--muted))",strokeWidth:"8",strokeLinecap:"round"}),e.jsx("path",{d:"M 10 45 A 40 40 0 0 1 75 20",fill:"none",stroke:"hsl(var(--primary))",strokeWidth:"8",strokeLinecap:"round"})]}),e.jsx("div",{className:"absolute inset-0 flex items-end justify-center pb-1",children:e.jsxs("span",{className:"text-2xl font-bold text-primary",children:["+",Q.sentimentScore]})})]})}),e.jsx("p",{className:"text-center text-muted-foreground mt-2",children:Q.sentimentLabel}),e.jsxs("div",{className:"flex gap-1 mt-4 h-3 rounded-full overflow-hidden",children:[e.jsx("div",{className:"bg-green-500 flex-[45]"}),e.jsx("div",{className:"bg-gray-400 flex-[30]"}),e.jsx("div",{className:"bg-red-400 flex-[25]"})]})]})}),e.jsx(k,{className:"bg-card border-border",children:e.jsxs(_,{className:"p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4 flex items-center gap-2",children:[e.jsx(ce,{className:"h-5 w-5 text-primary"}),"Readability Score"]}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs("div",{className:"relative w-24 h-24",children:[e.jsxs("svg",{viewBox:"0 0 100 100",className:"w-full h-full -rotate-90",children:[e.jsx("circle",{cx:"50",cy:"50",r:"40",fill:"none",stroke:"hsl(var(--muted))",strokeWidth:"8"}),e.jsx("circle",{cx:"50",cy:"50",r:"40",fill:"none",stroke:"hsl(var(--primary))",strokeWidth:"8",strokeDasharray:"251",strokeDashoffset:"70",strokeLinecap:"round"})]}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("span",{className:"text-2xl font-bold text-foreground",children:Q.readabilityScore})})]})}),e.jsxs("p",{className:"text-center text-muted-foreground mt-2",children:[Q.readabilityGrade," Reading Level"]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(k,{className:"bg-card border-border",children:e.jsxs(_,{className:"p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4 flex items-center gap-2",children:[e.jsx(ot,{className:"h-5 w-5 text-primary"}),"Top Topics"]}),e.jsx("div",{className:"space-y-3",children:Q.topics.map(h=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsx("span",{className:"text-foreground",children:h.name}),e.jsxs("span",{className:"text-muted-foreground",children:[h.weight,"%"]})]}),e.jsx("div",{className:"h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary rounded-full",style:{width:`${h.weight}%`}})})]},h.name))})]})}),e.jsx(k,{className:"bg-card border-border",children:e.jsxs(_,{className:"p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-4 flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5 text-primary"}),"Key Insights"]}),e.jsx("div",{className:"space-y-3",children:Q.insights.map((h,f)=>e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-muted/50 rounded-lg",children:[e.jsx("div",{className:"w-6 h-6 rounded-full bg-primary/20 flex items-center justify-center flex-shrink-0",children:e.jsx("span",{className:"text-xs font-medium text-primary",children:f+1})}),e.jsx("p",{className:"text-sm text-foreground",children:h})]},f))})]})})]})]})]})]})]})}function ya(r,s){const o=[];for(const i of s){const a=r[i];a&&(a.negative>30&&o.push({id:`sentiment-negative-${i}`,category:"sentiment",priority:a.negative>50?"high":"medium",title:"High Negative Sentiment Detected",issue:`${a.negative}% of text in "${i}
85" contains negative language`,recommendation:"Review the negative content to identify recurring pain points, complaints, or issues that need addressing.",affectedColumns:[i],metrics:{"Negative %":a.negative,"Positive %":a.positive,"Neutral %":a.neutral},actions:[{label:"Export Negative Content",type:"export",description:"Export rows with negative sentiment for review"},{label:"View Examples",type:"view",description:"See sample negative text entries"},{label:"Sentiment Guide",type:"guide",description:"Learn about sentiment patterns"}]}),a.neutral>80&&a.positive<10&&a.negative<10&&o.push({id:`sentiment-neutral-${i}`,category:"sentiment",priority:"low",title:"Low Sentiment Diversity",issue:`${a.neutral}% of text in "${i}" is classified as neutral`,recommendation:"This could indicate: factual/technical content (expected), short text entries, or text that needs more expressive language.",affectedColumns:[i],metrics:{"Neutral %":a.neutral},actions:[{label:"Review Content Type",type:"view",description:"Check if neutral is expected for this content"}]}),a.positive>30&&a.negative>30&&o.push({id:`sentiment-mixed-${i}`,category:"sentiment",priority:"medium",title:"Mixed Sentiment Detected",issue:`"${i}" shows both high positive (${a.positive}%) and negative (${a.negative}%) sentiment`,recommendation:"Consider segmenting this data by sentiment to analyze positive and negative feedback separately.",affectedColumns:[i],metrics:{"Positive %":a.positive,"Negative %":a.negative},actions:[{label:"Segment by Sentiment",type:"filter",description:"Split data into positive/negative groups"},{label:"Export Analysis",type:"export",description:"Export sentiment breakdown"}]}))}return o}function ja(r,s){const o=[];for(const i of s){const a=r[i];a&&(a.fleschKincaidGrade>12&&o.push({id:`readability-complex-${i}`,category:"readability",priority:a.fleschKincaidGrade>16?"high":"medium",title:"Complex Readability Level",issue:`Text in "${i}" is at grade level ${a.fleschKincaidGrade.toFixed(1)} (${a.level})`,recommendation:"Consider simplifying sentences and using shorter words for broader accessibility. Target grade 8-10 for general audiences.",affectedColumns:[i],metrics:{"Grade Level":a.fleschKincaidGrade.toFixed(1),"Reading Ease":a.fleschReadingEase.toFixed(1),"Avg Sentence Length":`${a.avgSentenceLength.toFixed(1)} words`},actions:[{label:"View Complex Sentences",type:"view",description:"See examples of complex text"},{label:"Readability Guide",type:"guide",description:"Tips for improving readability"}]}),a.fleschKincaidGrade<5&&a.fleschReadingEase>90&&o.push({id:`readability-simple-${i}`,category:"readability",priority:"low",title:"Very Simple Text",issue:`Text in "${i}" is at grade level ${a.fleschKincaidGrade.toFixed(1)} - very basic`,recommendation:"If this is intentional (e.g., for children or quick scanning), great! Otherwise, consider if more detail would add value.",affectedColumns:[i],metrics:{"Grade Level":a.fleschKincaidGrade.toFixed(1)},actions:[{label:"View Examples",type:"view",description:"See sample simple text entries"}]}),a.avgSentenceLength>25&&o.push({id:`readability-sentences-${i}`,category:"readability",priority:"medium",title:"Long Sentence Length",issue:`Average sentence in "${i}" is ${a.avgSentenceLength.toFixed(1)} words`,recommendation:"Sentences over 20 words can be harder to follow. Consider breaking long sentences into shorter ones.",affectedColumns:[i],metrics:{"Avg Sentence Length":`${a.avgSentenceLength.toFixed(1)} words`},actions:[{label:"View Long Sentences",type:"view",description:"See examples of long sentences"}]}))}return o}function Na(r,s){const o=[],i={},a={};for(const p of s){const n=r[p]||{};let l=0;for(const[t,d]of Object.entries(n))i[t]=(i[t]||0)+d,l+=d;a[p]=l}const c=Object.entries(a).filter(([,p])=>p>50).map(([p])=>p);c.length>0&&o.push({id:"entities-high-density",category:"entities",priority:"medium",title:"High Entity Density",issue:`Columns ${c.map(p=>`"${p}"`).join(", ")} contain many identifiable entities`,recommendation:"Consider extracting entities into dedicated columns for better data structure and analysis.",affectedColumns:c,metrics:Object.fromEntries(c.map(p=>[p,a[p]])),actions:[{label:"View Entity Breakdown",type:"view",description:"See entity types and examples"},{label:"Export Entities",type:"export",description:"Export extracted entities to new columns"}]}),(i.Email||0)+(i.Phone||0)>0&&o.push({id:"entities-pii",category:"entities",priority:"high",title:"Personal Information Detected",issue:`Found ${i.Email||0} emails and ${i.Phone||0} phone numbers`,recommendation:"Ensure proper handling of personal information. Consider masking or encrypting sensitive data.",affectedColumns:s,metrics:{Emails:i.Email||0,Phones:i.Phone||0},actions:[{label:"View PII Locations",type:"view",description:"See where PII appears in data"},{label:"Privacy Guide",type:"guide",description:"Best practices for handling PII"}]});const g=i.Person||0,u=i.Organization||0;return(g>20||u>20)&&o.push({id:"entities-named",category:"entities",priority:"low",title:"Named Entities Found",issue:`Detected ${g} person names and ${u} organization names`,recommendation:"Consider creating a lookup table or standardizing entity references for better analysis.",affectedColumns:s,metrics:{Persons:g,Organizations:u},actions:[{label:"View Entities",type:"view",description:"See detected names and organizations"},{label:"Export Entity List",type:"export",description:"Export unique entities for review"}]}),o}function wa(r,s){const o=[],i=new Map;for(const m of s){const g=r[m]||[];for(const u of g)i.set(u.name,(i.get(u.name)||0)+u.weight)}const a=i.size;a<5&&s.length>0&&o.push({id:"content-low-diversity",category:"content",priority:"low",title:"Low Topic Diversity",issue:`Only ${a} distinct topics identified across analyzed columns`,recommendation:"Content appears focused on a narrow set of topics. This may be expected for specialized content.",affectedColumns:s,metrics:{"Unique Topics":a},actions:[{label:"View Topic List",type:"view",description:"See all identified topics"}]});const c=Array.from(i.entries()).sort((m,g)=>g[1]-m[1]);if(c.length>0){const m=c[0],g=m[1]/Array.from(i.values()).reduce((u,p)=>u+p,0);g>.5&&o.push({id:"content-dominant-topic",category:"content",priority:"low",title:"Dominant Topic Detected",issue:`"${m[0]}" accounts for ${(g*100).toFixed(0)}% of topic weight`,recommendation:"Consider if the content needs more variety or if this focus is intentional.",affectedColumns:s,metrics:{"Dominant Topic":m[0],Share:`${(g*100).toFixed(0)}%`},actions:[{label:"View Topic Distribution",type:"view",description:"See full topic breakdown"}]})}return o}
85function Sa(r,s){const o=[...ya(r.sentiment,s),...ja(r.readability,s),...Na(r.entities,s),...wa(r.topics,s)],i={high:0,medium:1,low:2};return o.sort((a,c)=>i[a.priority]-i[c.priority]),o}function ka(r,s){let o=100,i=100,a=100,c=100;for(const p of s){const n=r.sentiment[p];n&&n.negative>30&&(o-=Math.min(30,n.negative-30))}for(const p of s){const n=r.readability[p];n&&(n.fleschKincaidGrade>12&&(i-=Math.min(30,(n.fleschKincaidGrade-12)*5)),n.avgSentenceLength>25&&(i-=Math.min(20,(n.avgSentenceLength-25)*2)))}for(const p of s){const n=r.entities[p];n&&(n.Email||n.Phone)&&(a-=10)}const m=new Set;for(const p of s)(r.topics[p]||[]).forEach(l=>m.add(l.name));m.size<3&&s.length>1&&(c-=15);const g=Math.round((Math.max(0,o)+Math.max(0,i)+Math.max(0,a)+Math.max(0,c))/4);let u;return g>=85?u="Excellent":g>=70?u="Good":g>=55?u="Fair":g>=40?u="Needs Improvement":u="Poor",{score:g,label:u,breakdown:{sentiment:Math.max(0,Math.round(o)),readability:Math.max(0,Math.round(i)),entities:Math.max(0,Math.round(a)),content:Math.max(0,Math.round(c))}}}function _a({analysis:r,selectedColumns:s}){const o=Sa(r,s),i=ka(r,s),a=t=>{switch(t){case"high":return e.jsx(B,{className:"h-4 w-4 text-destructive"});case"medium":return e.jsx(Y,{className:"h-4 w-4 text-amber-500"});case"low":return e.jsx(we,{className:"h-4 w-4 text-primary"});default:return e.jsx(Y,{className:"h-4 w-4"})}},c=t=>{switch(t){case"high":return"border-destructive/30 bg-destructive/5";case"medium":return"border-amber-500/30 bg-amber-50 dark:bg-amber-950/20";case"low":return"border-primary/30 bg-primary/5";default:return"border-border"}},m=t=>({sentiment:"bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300",readability:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300",entities:"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300",content:"bg-orange-100 text-orange-800 dark:bg-orange-900/30 dark:text-orange-300",engagement:"bg-pink-100 text-pink-800 dark:bg-pink-900/30 dark:text-pink-300"})[t]||"bg-muted text-muted-foreground",g=t=>{switch(t){case"export":return e.jsx(at,{className:"h-3 w-3"});case"view":return e.jsx(Vt,{className:"h-3 w-3"});case"guide":return e.jsx(ce,{className:"h-3 w-3"});default:return e.jsx(G,{className:"h-3 w-3"})}},u=t=>t>=85?"text-green-600 dark:text-green-400":t>=70?"text-primary":t>=55?"text-amber-600 dark:text-amber-400":"text-destructive",p=o.filter(t=>t.priority==="high"),n=o.filter(t=>t.priority==="medium"),l=o.filter(t=>t.priority==="low");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(k,{className:"bg-card border-border shadow-professional",children:[e.jsx(A,{className:"pb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 bg-gradient-to-br from-primary/20 to-purple-100 dark:to-purple-900/30 rounded-xl",children:e.jsx(I,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(M,{className:"text-lg font-semibold text-foreground",children:"Text Quality Analysis"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Overall assessment of your text data"})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:`text-3xl font-bold ${u(i.score)}`,children:[i.score,e.jsx("span",{className:"text-lg font-normal text-muted-foreground",children:"/100"})]}),e.jsx(F,{variant:"outline",className:"mt-1",children:i.label})]})]})}),e.jsx(_,{children:e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:Object.entries(i.breakdown).map(([t,d])=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground capitalize",children:t}),e.jsxs("span",{className:"font-medium",children:[d,"%"]})]}),e.jsx(hs,{value:d,className:"h-2"})]},t))})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(k,{className:"bg-destructive/5 border-destructive/20",children:e.jsx(_,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(B,{className:"h-5 w-5 text-destructive"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold text-destructive",children:p.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"High Priority"})]})]})})}),e.jsx(k,{className:"bg-amber-50 dark:bg-amber-950/20 border-amber-500/20",children:e.jsx(_,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{className:"h-5 w-5 text-amber-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold text-amber-600 dar
85k:text-amber-400",children:n.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Medium Priority"})]})]})})}),e.jsx(k,{className:"bg-primary/5 border-primary/20",children:e.jsx(_,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(we,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold text-primary",children:l.length}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Low Priority"})]})]})})})]}),o.length===0?e.jsx(k,{className:"bg-card border-border",children:e.jsxs(_,{className:"p-8 text-center",children:[e.jsx(we,{className:"h-12 w-12 text-green-500 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-2",children:"No Issues Detected"}),e.jsx("p",{className:"text-muted-foreground",children:"Your text data looks great! No recommendations at this time."})]})}):e.jsx("div",{className:"space-y-4",children:o.map(t=>e.jsx(k,{className:`border ${c(t.priority)} transition-all hover:shadow-md`,children:e.jsx(_,{className:"p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"mt-0.5",children:a(t.priority)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[e.jsx("h4",{className:"font-semibold text-foreground",children:t.title}),e.jsx(F,{className:m(t.category),variant:"secondary",children:t.category}),e.jsx(F,{variant:"outline",className:"capitalize",children:t.priority})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:t.issue}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-3 mb-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(le,{className:"h-4 w-4 text-primary mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm text-foreground",children:t.recommendation})]})}),t.metrics&&Object.keys(t.metrics).length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-4",children:Object.entries(t.metrics).map(([d,b])=>e.jsxs(F,{variant:"secondary",className:"font-normal",children:[d,": ",e.jsx("span",{className:"font-medium ml-1",children:b})]},d))}),t.affectedColumns.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-4 text-xs text-muted-foreground",children:[e.jsx(G,{className:"h-3 w-3"}),e.jsxs("span",{children:["Affected columns: ",t.affectedColumns.join(", ")]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.actions.map((d,b)=>e.jsxs(ee,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1.5",title:d.description,children:[g(d.type),d.label]},b))})]})]})})},t.id))})]})}const Ca={Person:e.jsx(J,{className:"h-4 w-4"}),Organization:e.jsx(ss,{className:"h-4 w-4"}),Location:e.jsx(ts,{className:"h-4 w-4"}),Product:e.jsx(nt,{className:"h-4 w-4"}),Event:e.jsx(Xe,{className:"h-4 w-4"}),Email:e.jsx(es,{className:"h-4 w-4"}),Phone:e.jsx(Jt,{className:"h-4 w-4"}),Date:e.jsx(Xe,{className:"h-4 w-4"}),URL:e.jsx(Yt,{className:"h-4 w-4"}),Money:e.jsx(Zt,{className:"h-4 w-4"}),Percentage:e.jsx(Qt,{className:"h-4 w-4"}),Time:e.jsx(Xt,{className:"h-4 w-4"})},Se={Person:"#8b5cf6",Organization:"#3b82f6",Location:"hsl(var(--sap-blue))",Product:"#f59e0b",Event:"#ec4899",Email:"#6366f1",Phone:"#14b8a6",Date:"#f97316",URL:"#06b6d4",Money:"#22c55e",Percentage:"#a855f7",Time:"#64748b"};function Ta({entities:r,selectedColumns:s,data:o}){const[i,a]=v.useState(null),c=v.useMemo(()=>{const l={};for(const t of s){const d=r[t]||{};for(const[b,h]of Object.entries(d))l[b]=(l[b]||0)+h}return l},[r,s]),m=v.useMemo(()=>{const l=["Person","Organization","Location","Product","Event"],t=["Email","Phone","Date","URL","Money","Percentage","Time"];return{nlp:Object.entries(c).filter(([d])=>l.includes(d)).sort((d,b)=>b[1]-d[1]),pattern:Object.entries(c).filter(([d])=>t.includes(d)).sort((d,b)=>b[1]-d[1])}},[c]),g=v.useMemo(()=>Object.entries(c).filter(([,l])=>l>0).map(([l,t])=>({name:l,value:t,color:Se[l]||"#6b7280"})).sort((l,t)=>t.value-l.value),[c]),u=Object.values(c).reduce((l,t)=>l+t,0),p=l=>{if(!o||o.length===0)return[];const t=new Set,b={Email:/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,Phone:/\b(?:\+?1?[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g,Money:/\$[\d,]+(?:\.\d{2})?/g,URL:/https?:\/\/[^\s]+/g,Date:/\b\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}\b/g}[l];if(!b)return[];for(const h of o.slice(0,100)){for(const f of s){const y=String(h[f]||"").match(b);if(y&&(y.forEach(E=>t.add(E)),t.size>=5))break}if(t.size>=5)break}return Array.from(t).slice(0,5)},n=(l,t)=>{const d=i===l,b=p(l);return e.jsxs("div",{className:"border border-border rounded-lg p-4 bg-card hover:shadow-sm transition-shadow",children:[e.jsxs("div",{className:"flex items-center justify-between cursor-pointer",onClick:()=>a(d?null:l),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg",style:{backgroundColor:`${Se[l]}20`},children:e.jsx("div",{style:{color:Se[l]},children:Ca[l]||e.jsx(I,{className:"h-4 w-4"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-foreground",children:l}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.toLocaleStr
85ing()," found"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(F,{variant:"secondary",children:[(t/u*100).toFixed(1),"%"]}),b.length>0&&(d?e.jsx(qt,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Ut,{className:"h-4 w-4 text-muted-foreground"}))]})]}),d&&b.length>0&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Sample values:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:b.map((h,f)=>e.jsx(F,{variant:"outline",className:"font-mono text-xs max-w-[200px] truncate",children:h},f))})]})]},l)};return u===0?e.jsx(k,{className:"bg-card border-border",children:e.jsxs(_,{className:"p-8 text-center",children:[e.jsx(J,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-2",children:"No Entities Detected"}),e.jsx("p",{className:"text-muted-foreground",children:"No named entities, emails, phones, or other patterns were found in the selected columns."})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(k,{className:"bg-card border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4 text-primary"}),"Entity Distribution"]})}),e.jsx(_,{children:e.jsx("div",{className:"h-[280px]",children:e.jsx(Ss,{width:"100%",height:"100%",children:e.jsxs(ks,{children:[e.jsx(_s,{data:g,cx:"50%",cy:"50%",innerRadius:60,outerRadius:100,paddingAngle:2,dataKey:"value",children:g.map((l,t)=>e.jsx(Cs,{fill:l.color},`cell-${t}`))}),e.jsx(Ts,{formatter:l=>[l.toLocaleString(),"Count"],contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"8px"}}),e.jsx(Ps,{verticalAlign:"bottom",height:36,formatter:l=>e.jsx("span",{className:"text-xs text-foreground",children:l})})]})})})})]}),e.jsxs(k,{className:"bg-card border-border shadow-professional",children:[e.jsx(A,{className:"pb-2",children:e.jsxs(M,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(J,{className:"h-4 w-4 text-primary"}),"Entity Summary"]})}),e.jsx(_,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/50 rounded-lg",children:[e.jsx("span",{className:"text-muted-foreground",children:"Total Entities"}),e.jsx("span",{className:"text-2xl font-bold text-foreground",children:u.toLocaleString()})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/50 rounded-lg",children:[e.jsx("span",{className:"text-muted-foreground",children:"Entity Types"}),e.jsx("span",{className:"text-2xl font-bold text-foreground",children:g.length})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/50 rounded-lg",children:[e.jsx("span",{className:"text-muted-foreground",children:"NLP Entities"}),e.jsx("span",{className:"text-2xl font-bold text-primary",children:m.nlp.reduce((l,[,t])=>l+t,0).toLocaleString()})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/50 rounded-lg",children:[e.jsx("span",{className:"text-muted-foreground",children:"Pattern Entities"}),e.jsx("span",{className:"text-2xl font-bold text-success",children:m.pattern.reduce((l,[,t])=>l+t,0).toLocaleString()})]})]})})]})]}),e.jsxs(k,{className:"bg-card border-border shadow-professional",children:[e.jsx(A,{className:"pb-4",children:e.jsx(M,{className:"text-base font-semibold",children:"Entity Details"})}),e.jsx(_,{children:e.jsxs(gt,{defaultValue:"all",children:[e.jsxs(xt,{className:"mb-4",children:[e.jsxs(q,{value:"all",children:["All (",g.length,")"]}),e.jsxs(q,{value:"nlp",children:["NLP (",m.nlp.length,")"]}),e.jsxs(q,{value:"pattern",children:["Patterns (",m.pattern.length,")"]})]}),e.jsx(U,{value:"all",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:g.map(({name:l,value:t})=>n(l,t))})}),e.jsx(U,{value:"nlp",children:m.nlp.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No NLP entities (Person, Organization, Location, etc.) detected."}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:m.nlp.map(([l,t])=>n(l,t))})}),e.jsx(U,{value:"pattern",children:m.pattern.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No pattern-based entities (Email, Phone, etc.) detected."}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:m.pattern.map(([l,t])=>n(l,t))})})]})})]})]})}const Pa="text-analysis-v2";function Ea({workstationData:r}){const{data:s,fileName:o,setData:i,setFileName:a}=de(),{cached:c,save:m,clear:g}=bs("text-analysis"),[u,p]=v.useState(c?.selectedColumns??[]),[n,l]=v.useState(c?.analysis??null),[t,d]=v.useState(null),{saveReport:b}=as("Text Analysis"),{infer:h,engineStatus:f,ensureModelReady:x}=gs(),[y,E]=v.useState(null),[R,D]=v.useState(null),[z,me]=v.useState(!1),K=is(),Me=v.useMemo(()=>
85{if(!n||!s)return null;const j=Object.entries(n.sentiment||{}),w=[],N=j.filter(([,C])=>{const S=C.positive+C.negative+C.neutral||1;return C.negative/S>.4});N.length&&w.push({id:"neg-sentiment",title:`${N.length} column(s) with high negative sentiment`,severity:"medium",category:"sentiment",affectedColumns:N.map(([C])=>C)});const T=Object.entries(n.readability||{}).filter(([,C])=>C.fleschReadingEase<30);T.length&&w.push({id:"readability",title:`${T.length} column(s) very hard to read`,severity:"low",category:"readability",affectedColumns:T.map(([C])=>C)});const P=Object.values(n.readability||{}).reduce((C,S)=>C+S.fleschReadingEase,0)/Math.max(1,Object.keys(n.readability||{}).length);return{toolName:"Text Analysis",toolCategory:"analytics",datasetName:o??void 0,rowCount:s.length,columnCount:j.length,overallScore:Math.round(Math.max(0,Math.min(100,P))),dimensionScores:{"Avg Readability":Math.round(P)},issues:w}},[n,s,o]);v.useEffect(()=>{if(!n||!s)return;const j=Object.keys(n.sentiment||{}).length;b({reportData:{columnsAnalyzed:j,rows:s.length,hasSentiment:!!n.sentiment,hasEntities:!!n.entities},toolCategory:"understand",rowCount:s.length})},[n,s]),v.useEffect(()=>{if(!n||!s){K(null);return}const j=Object.entries(n.sentiment||{}),w=j.length,N=j.map(([L,$])=>{const Ne=$.positive+$.negative+$.neutral||1;return{col:L,posPct:Math.round($.positive/Ne*100),negPct:Math.round($.negative/Ne*100),neuPct:Math.round($.neutral/Ne*100)}}),T=w?Math.round(N.reduce((L,$)=>L+$.posPct,0)/w):0,P=w?Math.round(N.reduce((L,$)=>L+$.negPct,0)/w):0,C=Object.values(n.readability||{}),S=C.length?Math.round(C.reduce((L,$)=>L+$.fleschReadingEase,0)/C.length):0,H=Hs(s.length),V=s.length>ne.MEDIUM_MAX,Tt=Math.max(0,Math.min(100,S)),Pt={toolResult:{toolName:"Text Analysis",toolCategory:"analytics",datasetName:o??void 0,rowCount:s.length,columnCount:w,overallScore:Tt,dimensionScores:{"Avg Readability":S,"Avg Positive %":T,"Avg Negative %":P},issues:[]},kpis:[{id:"cols",label:"Text Columns",value:w.toLocaleString(),tone:"info"},{id:"rows",label:"Rows Analyzed",value:s.length.toLocaleString(),tone:"default"},{id:"pos",label:"Avg Positive",value:`${T}%`,tone:T>=50?"success":"default",metricId:"text-analysis.positive",aiContext:{tool:"Text Analysis",avgPositivePct:T}},{id:"neg",label:"Avg Negative",value:`${P}%`,tone:P>=40?"danger":P>=20?"warning":"success",metricId:"text-analysis.negative",aiContext:{tool:"Text Analysis",avgNegativePct:P}},{id:"ease",label:"Readability",value:S,tone:S>=60?"success":S>=30?"warning":"danger",metricId:"text-analysis.readability",aiContext:{tool:"Text Analysis",fleschReadingEase:S}},{id:"cap",label:"Capacity",value:`${H.toUpperCase()}${V?" · sampled":""}`,tone:H==="massive"?"warning":"success",aiContext:{tool:"Text Analysis",tier:H,rowFloor:ne.MEDIUM_MAX}}],reportTable:{headers:["Column","Positive %","Negative %","Neutral %","Readability"],rows:N.map(L=>[L.col,`${L.posPct}%`,`${L.negPct}%`,`${L.neuPct}%`,n.readability?.[L.col]?.fleschReadingEase!=null?Math.round(n.readability[L.col].fleschReadingEase):"â"])},reportSections:[...n.truncationNotices?.length?[{heading:"Partial Results â Truncation Notices",content:ut(n.truncationNotices)}]:[],{heading:"Result Provenance",content:pt(n.provenance??te(se.textAnalysis))},{heading:"Run Summary",content:`Analyzed ${w} text column(s) across ${s.length.toLocaleString()} rows. Average sentiment: ${T}% positive / ${P}% negative. Average readability (Flesch): ${S}.${V?` Dataset auto-sampled to ${ne.MEDIUM_MAX.toLocaleString()} rows for on-device analysis.`:""}`},...y?[{heading:"AI Narrative",content:y}]:[]],useTabbedReport:!0,reportMethodology:`Text Analysis runs sentiment scoring (lexicon + on-device SmolLM2 refinement), Flesch readability, and per-column distributional statistics entirely in your browser. Sentiment counts are normalised to percentages; readability uses syllable-aware Flesch Reading Ease (higher = easier to read). ${V?`Dataset auto-sampled to ${ne.MEDIUM_MAX.toLocaleString()} rows for tractable on-device analysis.`:""} No text is transmitted off-device.`};K(Pt)},[n,s,o,y,K]);const W=v.useRef(null),ue=v.useRef(null),X=v.useRef(null),[Le,ae]=v.useState(!1),[bt,pe]=v.useState(0),[vt,he]=v.useState(""),[yt,De]=v.useState(0),[jt,$e]=v.useState(0);v.useEffect(()=>{n&&m({analysis:n,selectedColumns:u})},[n,u,m]);const{toast:ie}=ye(),Fe=v.useRef(!1),Ie=v.useRef(0);v.useEffect(()=>{if(!r)return;const j=r.totalRows!==Ie.current;(!Fe.current||j)&&(j&&s&&(l(null),p([]),d(null),g()),Ie.current=r.totalRows,Fe.current=!0,r.readAllData().then(w=>
85{w.length>0&&(i(w),a(`Workstation (${w.length} rows)`),l(null),ie({title:"Data loaded from Workstation",description:`${w.length.toLocaleString()} rows ready for text analysis`}))}))},[r,s,i,a,g,ie]);const ze=v.useRef(s);v.useEffect(()=>{if(s&&s!==ze.current){const j=s.length>0?Object.keys(s[0]):[];p(w=>{const N=w.filter(T=>j.includes(T));return N.length>0?N:[]}),l(null),d(null),re(!1)}ze.current=s},[s]);const[We,re]=v.useState(!1),[Oe,Be]=v.useState(null),[ge,He]=v.useState(Qe(s?.length||0)),Ge=v.useRef(ge);v.useEffect(()=>{Ge.current=ge},[ge]),v.useEffect(()=>()=>{W.current?.terminate(),W.current=null},[]);const Ke=v.useCallback((j,w)=>{const{data:N,selectedColumns:T,type:P}=w,C=25e3;if(N.length<=C){j.postMessage({type:P,data:N,selectedColumns:T});return}j.postMessage({type:"init-chunked",totalRows:N.length,selectedColumns:T});let S=0;const H=()=>{if(S>=N.length){j.postMessage({type:"start-analysis"});return}const V=N.slice(S,S+C);j.postMessage({type:"data-chunk",chunk:V,offset:S}),S+=C,setTimeout(H,0)};H()},[]),Ve=v.useCallback((j,w)=>new Promise((N,T)=>{ue.current=N,X.current=T,W.current?.terminate(),ae(!0),pe(0),he("Initializing..."),De(0),$e(j.length);const P=new Worker(new URL("/assets/worker-textAnalysisWorker-DW_mw7tf.js",import.meta.url),{type:"module"});W.current=P,P.onmessage=C=>{const S=C.data;S.type==="progress"?(pe(S.value),he(S.stage),S.processedRows!==void 0&&De(S.processedRows),S.totalRows!==void 0&&$e(S.totalRows)):S.type==="complete"?(ae(!1),pe(100),he("Complete"),P.terminate(),W.current=null,ue.current=null,X.current=null,N(S.results)):S.type==="error"&&(ae(!1),P.terminate(),W.current=null,ue.current=null,X.current=null,T(new Error(S.message)))},P.onerror=C=>{ae(!1),P.terminate(),W.current=null,T(new Error(C.message||"Worker error"))},Ke(P,{type:"analyze",data:j,selectedColumns:w})}),[Ke]),je=v.useCallback(()=>{W.current?.terminate(),W.current=null,X.current&&(X.current(new Error("Cancelled")),X.current=null,ue.current=null),ae(!1),pe(0),he("Cancelled")},[]),xe=v.useCallback(async(j=!1,w=!1)=>{if(!(!s||u.length===0)){if(!w&&!j&&s.length>ne.MEDIUM_MAX){const N=Os(s);Be(N),He(Qe(s.length)),re(!0);return}re(!1);try{const N=Ge.current,T=j?Bs(s,{...N,enabled:!0}).sampledData:s,P=await Ve(T,u);l(P),D(null),d(null),ie({title:"Text Analysis Complete",description:`Successfully analyzed ${u.length} text columns${j?" (sampled)":""} (on-device AI)`}),me(!0),(async()=>{try{const S=await x()&&f.generativeProviderConnected?h:null,[H,V]=await Promise.all([rs(S,P),ns(S,T,u,P.sentiment)]);E(H),D(V??null)}finally{me(!1)}})()}catch(N){if(N instanceof Error&&N.message==="Cancelled")return;const T=N instanceof Error?N.message:"Error analyzing text data";d(T),ie({title:"Analysis Failed",description:T,variant:"destructive"})}}},[s,u,Ve,ie,h,x,f.generativeProviderConnected]),Nt=v.useCallback(j=>{re(!1),xe(j,!0)},[xe]),wt=v.useCallback(j=>{p(w=>w.includes(j)?w.filter(N=>N!==j):[...w,j])},[]),St=v.useCallback(()=>{s&&s.length>0&&p(Object.keys(s[0]))},[s]),kt=v.useCallback(()=>{p([])},[]),_t=v.useCallback(()=>{je(),i(null),a(null),p([]),l(null),d(null),re(!1),Be(null),g()},[i,a,g,je]),Ct=v.useCallback(()=>{xe(!1)},[xe]);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(zs,{isOpen:Le,title:"Analyzing Text Data",stage:vt,progress:bt,processedItems:yt,totalItems:jt,itemLabel:"rows",onCancel:je}),We&&Oe&&e.jsx(Ws,{datasetAnalysis:Oe,samplingConfig:ge,onSamplingConfigChange:He,onProceed:Nt,operationType:"text-analysis"}),e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2.5 bg-primary/10 rounded-xl",children:e.jsx(ve,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"Natural Language Analysis"}),o&&e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Analyzing:"}),e.jsx(F,{variant:"secondary",className:"text-xs",children:o}),s&&e.jsxs(F,{variant:"outline",className:"text-xs",children:[s.length.toLocaleStr
85ing()," rows"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[!s&&e.jsx(fa,{}),s&&e.jsx(Is,{onReset:_t,label:"New Analysis",description:"This will clear all text data and analysis results. Are you sure?"}),n&&e.jsx(Js,{analysis:n,selectedColumns:u,fileName:o})]})]}),t&&e.jsx("div",{className:"bg-destructive/10 border border-destructive/20 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(B,{className:"h-5 w-5 text-destructive mr-2"}),e.jsx("p",{className:"text-sm text-destructive",children:t})]})}),!s&&e.jsx(va,{}),s&&!We&&e.jsxs(e.Fragment,{children:[e.jsx(Us,{selectedColumns:u,onToggleColumn:wt,onSelectAll:St,onClearAll:kt,onAnalyze:Ct,loading:Le,disabled:!s||u.length===0}),u.length>0&&e.jsx(Ys,{data:s,selectedColumns:u}),n&&e.jsxs(e.Fragment,{children:[e.jsx(Ls,{notices:n.truncationNotices}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Provenance â ",ht(n.provenance??te(se.textAnalysis))]}),e.jsxs(k,{className:"border-primary/20 bg-gradient-to-br from-primary/5 to-transparent",children:[e.jsx(A,{className:"pb-2",children:e.jsxs(M,{className:"text-sm flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4 text-primary"}),"AI Insights (On-Device)",z&&e.jsx(os,{className:"h-3 w-3 animate-spin text-muted-foreground"})]})}),e.jsx(_,{children:y?e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none text-sm",children:e.jsx(Gs,{children:y})}):z?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generating insights with on-device language modelâ¦"}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Local AI model unavailable â showing rule-based results only."})})]}),R&&e.jsxs(k,{className:"border-amber-500/30",children:[e.jsx(A,{className:"pb-2",children:e.jsxs(M,{className:"text-sm flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4 text-amber-600"}),"AI opinion â sentiment (on-device LLM, ",Pa,")"]})}),e.jsxs(_,{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"The deterministic lexicon result is the system of record and is shown in every chart, export and report. The AI opinion below is an unvalidated second reading and is never merged into the numbers above."}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-muted-foreground",children:[e.jsx("th",{className:"py-1 pr-4",children:"Column"}),e.jsx("th",{className:"py-1 pr-4",children:"Deterministic (pos/neu/neg %)"}),e.jsx("th",{className:"py-1",children:"AI opinion (pos/neu/neg %)"})]})}),e.jsx("tbody",{children:Object.keys(n.sentiment||{}).map(j=>{const w=n.sentiment[j],N=R[j];return e.jsxs("tr",{className:"border-t border-border/50",children:[e.jsx("td",{className:"py-1 pr-4 font-medium",children:j}),e.jsxs("td",{className:"py-1 pr-4",children:[w.positive,"/",w.neutral,"/",w.negative]}),e.jsx("td",{className:"py-1",children:N?`${N.positive}/${N.neutral}/${N.negative}`:"â"})]},j)})})]})})]})]}),e.jsxs(gt,{defaultValue:"consolidated",className:"w-full",children:[e.jsxs(xt,{className:"bg-muted/50 p-1",children:[e.jsx(q,{value:"consolidated",className:"gap-2",children:"Consolidated View"}),e.jsx(q,{value:"per-column",className:"gap-2",children:"Per Column View"}),e.jsx(q,{value:"entities",className:"gap-2",children:"Entity Explorer"}),e.jsx(q,{value:"recommendations",className:"gap-2",children:"Recommendations"})]}),e.jsxs(U,{value:"consolidated",className:"mt-6 space-y-6",children:[e.jsx(Ze,{analysis:n,selectedColumns:u,fileName:o}),e.jsx(ua,{analysis:n,selectedColumns:u})]}),e.jsxs(U,{value:"per-column",className:"mt-6 space-y-6",children:[e.jsx(Ze,{analysis:n,selectedColumns:u,fileName:o}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:u.map(j=>e.jsx(Xs,{column:j,analysis:n},j))})]}),e.jsx(U,{value:"entities",className:"mt-6 space-y-6",children:e.jsx(Ta,{entities:n.entities,selectedColumns:u,data:s||void 0})}),e.jsx(U,{value:"recommendations",className:"mt-6 space-y-6",children:e.jsx(_a,{analysis:n,selectedColumns:u})})]})]}),Me&&e.jsx(ls,{toolResult:Me})]})]})}const Mi=({workstationData:r})=>{const s=Vs(),o=r??s;return e.jsx(Ks,{seoTitle:"Text Analysis | Puridex",seoDescription:"Advanced natural language processing and sentiment analysis for your text data",icon:G,title:"Text Analysis",description:"Advanced natural language processing and sentiment analysis",badges:[{icon:Je,label:"NLP Processing"},{icon:cs,label:"Sentiment Analysis"},{icon:ds,label:"Local AI"}],helpToolId:"text-analysis",children:e.jsxs(ms,{toolId:"text-analysis",toolName:"Text Analysis",children:[e.jsx(xs,{children:e.jsx(Ea,{workstationData:o})}),e.jsx(qs,{toolId:"text-analysis"})]})})};export{Mi 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.