1import{r as t,j as e}from"./vendor-react-C_xdI0Ng.js";import{u as U}from"./index-BLFiW9lJ.js";import{L as r}from"./linear-icon-BS_Bu1OG.js";import{r as z,c as S,l as B,a as I,T as D}from"./noto-sans-cyrillic-700-normal-B3rv6UnQ.js";import q from"./noto-sans-latin-400-normal-DZbyGt1h.js";import H from"./noto-sans-latin-ext-400-normal-ChgRUxkZ.js";import O from"./noto-sans-cyrillic-400-normal-C2Ud1djk.js";import"./vendor-icons-CmfhFn4k.js";function V({inputFiles:s,onStart:x,onBack:k}){const{runtime:m}=U(),[j,i]=t.useState("config"),[n,b]=t.useState(null),[E,p]=t.useState([]),[y,c]=t.useState(null),h=t.useRef(0),g=t.useRef(null);t.useEffect(()=>()=>{var o;return(o=g.current)==null?void 0:o.abort()},[]);const _=t.useCallback(async()=>{var d,u,N,v,w,C;if(s.length===0)return;(d=g.current)==null||d.abort();const o=++h.current,l=new AbortController;g.current=l,i("parsing"),c(null),(u=window.posthog)==null||u.capture("app_tool_run_started",{toolId:"auto-toc",action:"parse",fileCount:s.length});try{const a=await z(m,s[0],l.signal);if(o!==h.current)return;if(a.error){(N=window.posthog)==null||N.capture("app_tool_run_error",{toolId:"auto-toc",action:"parse",message:a.error}),c(a.error),i("config");return}(v=window.posthog)==null||v.capture("app_tool_run_success",{toolId:"auto-toc",action:"parse",headersFound:a.headingCandidatesFound,totalPages:a.totalPages});const R=m.billing.getContext().plan,f=a.totalPages??0;if(R==="basic"&&f>5){(w=window.posthog)==null||w.capture("app_upsell_shown",{toolId:"auto-toc",source:"page_limit",pageCount:f}),c(`Free plan limited to 5 pages (this document has ${f}). Upgrade to Pro for unlimited page TOC generation.`),i("config");return}b(a),p(a.headers),i("review")}catch(a){if(o!==h.current||a instanceof DOMException&&a.name==="AbortError")return;(C=window.posthog)==null||C.capture("app_tool_run_error",{toolId:"auto-toc",action:"parse",message:a instanceof Error?a.message:"Unknown"}),c(a instanceof Error?a.message:"Unknown error"),i("config")}},[s,m]),P=t.useCallback(o=>{p(o)},[]),T=t.useCallback(o=>{const l="/app/",d=`${l}fonts/Roboto-Regular.ttf`.replace(/\/+/g,"/"),u=`${l}fonts/Roboto-Bold.ttf`.replace(/\/+/g,"/");x({action:"apply",headers:o.headers,bodyTextSize:n==null?void 0:n.bodyTextSize,generateTocPage:o.generateTocPage,fontUrls:{latinUrl:q,latinExtUrl:H,cyrillicUrl:O,latinBoldUrl:I,latinExtBoldUrl:B,cyrillicBoldUrl:S,robotoUrl:d,robotoBoldUrl:u}})},[x,n]),A=t.useCallback(()=>{i("config"),b(null),p([]),c(null)},[]);return j==="parsing"?e.jsxs("div",{className:"tool-config-root autoc-root",children:[e.jsxs("div",{className:"autoc-header",style:{textAlign:"center",padding:"40px 0"},children:[e.jsx("div",{className:"autoc-spinner",style:{margin:"0 auto 16px",width:40,height:40,border:"3px solid var(--border)",borderTopColor:"var(--accent)",borderRadius:"50%",animation:"autoc-spin 0.8s linear infinite"}}),e.jsx("h3",{className:"autoc-title",children:"Analyzing Documentâ¦"}),e.jsx("p",{className:"tool-config-copy",children:"Extracting text layer and detecting headings."})]}),e.jsx("style",{children:"@keyframes autoc-spin { to { transform: rotate(360deg); } }"})]}):j==="review"&&n?e.jsx(D,{headers:E,bodyTextSize:n.bodyTextSize,headingCandidatesFound:n.headingCandidatesFound,totalSpansExtracted:n.totalSpansExtracted,onHeadersChange:P,onApply:T,onBack:A}):e.jsxs("div",{className:"tool-config-root autoc-root",children:[e.jsxs("div",{className:"autoc-header",children:[e.jsx("h3",{className:"autoc-title",children:"Auto-TOC & Bookmarks"}),e.jsx("p",{className:"tool-config-copy",children:"Automatically scan your PDF for headings, then generate an interactive table of contents with bookmarks for easy navigation."})]}),e.jsxs("div",{className:"autoc-features",children:[e.jsxs("div",{className:"autoc-feature",children:[e.jsx(r,{name:"ocr",className:"linear-icon icon-md"}),e.jsxs("div",{children:[e.jsx("strong",{children:"Smart Detection"}),e.jsx("p",{children:"Finds headings by analyzing font size, weight, and structure."})]})]}),e.jsxs("div",{className:"autoc-feature",children:[e.jsx(r,{name:"signature",className:"linear-icon icon-md"}),e.jsxs("div",{children:[e.jsx("strong",{children:"PDF Bookmarks"}),e.jsx("p",{children:"Adds interactive navigation to your document outline."})]})]}),e.jsxs("div",{className:"autoc-feature",children:[e.jsx(r,{name:"edit",className:"linear-icon icon-md"}),e.jsxs("div",{children:[e.jsx("strong",{children:"Edit & Refine"}),e.jsx("p",{children:"Review detected headings, adjust levels, and customize the final output."})]})]})]}),y&&e.jsxs("div",{className:"autoc-error",children:[e.jsx(r,{name:"x",className:"linear-icon"}),e.jsx("span",{children:y})]}),s.length>0&&e.jsxs("div",{className:"autoc-file-info",children:[e.jsx(r,{name:"file-input",className:"linear-icon"}),e.jsxs("span",{children:[s.length," file(s) ready for analysis"]})]}),e.jsxs("div",{className:"tool-config-actions premium-actions",children:[e.jsx("button",{className:"btn-ghost",onClick:k,children:e.jsxs("span",{className:"btn-inline",children:[e.jsx(r,{name:"x",className:"linear-icon"}),"Cancel"]})}),e.jsx("button",{className:"btn-primary btn-premium-glow",onClick:_,disabled:s.length===0,children:e.jsxs("span",{className:"btn-inline",children:[e.jsx(r,{name:"play",className:"linear-icon"}),"Analyze Document"]})})]})]})}export{V 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.