PageSourceSearch

https://scrollbook.ai/assets/BookDetailPage-D4CcnM0w.js

js scrollbook.ai collected 2026-10-05 12:40:44 UTC 56,010 bytes, 3 lines download raw bytes

1import{a as Pt}from"./rolldown-runtime-M0oDzQ_3.js";import{_ as At,c as ge}from"./vendor-react-BK73EwAN.js";import{O as Et,i as be,k as Ft,o as Mt,r as N}from"./vendor-data-BwcWGEsa.js";import{t as Ge}from"./supabase-C5lAo7mf.js";import{t as v}from"./utils-Dxo0lxcD.js";import{t as Oe}from"./arrow-left-B_Ixnu3o.js";import{t as $t}from"./calendar-B6bUHjyt.js";import{t as Ke}from"./chevron-up-BpBk6XOo.js";import{t as A}from"./circle-alert-CBdHC6QX.js";import{t as pe}from"./circle-check-DpATGgU0.js";import{t as Bt}from"./clock-DTQt8uc9.js";import{t as He}from"./cpu-grWkGcxs.js";import{t as E}from"./external-link-CJfwKTEY.js";import{t as Tt}from"./eye-p4K02Njq.js";import{t as Ve}from"./film-Zro1TiRm.js";import{t as he}from"./flag-DyGMMVLx.js";import{t as We}from"./hourglass-C7YOYvZ7.js";import{t as I}from"./image-CaYZDweo.js";import{t as qt}from"./layers-Crk8r4zl.js";import{t as Ut}from"./pen-line-MIy2oqNF.js";import{t as w}from"./refresh-cw-dz9G8Tu5.js";import{t as Je}from"./rotate-ccw-DuSNkFOM.js";import{t as It}from"./save-BrAWCm4T.js";import{t as Lt}from"./shield-check-r-8diVlc.js";import{t as Dt}from"./sparkles-B_ubz5O3.js";import{t as K}from"./volume-2-aepH6Hyd.js";import{t as Qt}from"./x-cBmH4UyD.js";import{t as Ye}from"./zap-DdqMYNHk.js";import{i as Xe,r as fe}from"./legalHold-C_9EGpge.js";import{D as H,Nt as zt}from"./index-Bhvx0-ct.js";import{t as ve}from"./Dialog-D30fkc27.js";import"./ui-DMgQNDEI.js";import{t as Ze}from"./AdminActivityService-DsX82pi5.js";import{t as h}from"./AdminContentService-Ul655M7R.js";import{t as m}from"./adminQueryKeys-BdnMWn-Q.js";import{n as Gt}from"./AdminToast-DqMvvxiF.js";import{t as L}from"./AgentOrchestrationService-BOGBOApV.js";import{t as Ot}from"./AgentRunBadge-CFatFdfK.js";import{t as Kt}from"./MarkFreeButton-B9x95uBJ.js";var l=Pt(Ft(),1),e=Et();function Fs(){const{bookId:i}=At(),x=Mt(),{data:V,isLoading:et,isError:tt,error:st}=be({queryKey:m.books.detail(i??""),queryFn:async()=>{if(!i)throw new Error("No book ID");const[t,r,n]=await Promise.all([h.getBookById(i),h.getChaptersByBook(i),h.getDomains()]);if(!t)throw new Error("Book not found");return{book:t,chapters:r,domains:n}},enabled:!!i,staleTime:120*1e3,refetchInterval:t=>(t.state.data?.chapters??[]).some(r=>r.infographicStatus==="generating"||r.audioStatus==="generating")?8e3:!1}),s=V?.book??null,f=V?.chapters??[],rt=V?.domains??[],ke=tt?st.message:null,{data:o=null}=be({queryKey:m.books.scorecard(i??""),queryFn:()=>h.getBookScorecard(i),enabled:!!i,staleTime:600*1e3}),{data:b=null}=be({queryKey:m.books.scroll(i??""),queryFn:()=>h.getBookScroll(i),enabled:!!i,staleTime:300*1e3}),[k,W]=(0,l.useState)(!1),[a,p]=(0,l.useState)(null),[je,at]=(0,l.useState)(!1),[J,ot]=(0,l.useState)(null),Ne=Gt(),[nt,Y]=(0,l.useState)(!1),[we,X]=(0,l.useState)(""),[ye,D]=(0,l.useState)(null),[it,Se]=(0,l.useState)(!1),Q=(0,l.useRef)(!1),Ce=(0,l.useRef)(null),_e=(0,l.useRef)(null),[Z,lt]=(0,l.useState)(!1),[c,y]=(0,l.useState)(null),[dt,F]=(0,l.useState)(!1),P=(0,l.useRef)(!1),Re=(0,l.useRef)(null),Pe=(0,l.useRef)(null),[Ae,C]=(0,l.useState)(null),[M,ct]=(0,l.useState)("chapters"),[ee,$]=(0,l.useState)(new Map),[S,Ee]=(0,l.useState)(null),Fe=(0,l.useRef)(null),Me=(0,l.useRef)(null),[$e,te]=(0,l.useState)(null),[z,ut]=(0,l.useState)(()=>localStorage.getItem(`exec_engine_${i}`)??"local"),[Be,se]=(0,l.useState)(null),[B,Te]=(0,l.useState)(!1),d=(t,r)=>{r==="success"?Ne.success(t):Ne.error(t)},T=N({mutationFn:async t=>{const r=ee.get(t.id);if(!r)throw new Error("No edits");return await h.updateChapterBlueprint(t.id,{audioScript:r.audioScript,keyTakeaways:r.keyTakeaways,ahaMoments:r.ahaMoments,keyStats:r.keyStats,quotes:r.quotes}),t.id},onSuccess:t=>{$(r=>{const n=new Map(r);return n.delete(t),n}),d("Blueprint saved!","success")},onError:()=>d("Failed to save blueprint","error")});(0,l.useEffect)(()=>{i&&L.getActiveRun(i).then(t=>se(t)).catch(()=>{})},[i]);const re=N({mutationFn:async()=>{if(!s)throw new Error("No book");const{data:{session:t}}=await Ge.auth.getSession();await fetch(`https://rmrbduwijacdyjwmibga.supabase.co
2/functions/v1/generate-scroll`,{method:"POST",headers:{Authorization:`Bearer ${t?.access_token}`,"Content-Type":"application/json"},body:JSON.stringify({bookId:s.id})})},onSuccess:()=>{x.invalidateQueries({queryKey:m.books.scroll(i)}),C(`Scroll generation started for ${s?.title??"this book"}.`),d("Scroll generation started","success")},onError:t=>{d(`Scroll generation failed: ${t.message||"Unknown"}`,"error")}}),mt=()=>{s&&(p({title:s.title,author:s.author,priority:s.priority||"P3",status:s.status,description:s.description||"",amazonUrl:s.amazonUrl||"",evidenceUrl:s.evidenceUrl||"",reviewStatus:s.reviewStatus||"approved",reviewNotes:s.reviewNotes||""}),W(!0))},xt=()=>{W(!1),p(null)},qe=N({mutationFn:async t=>{if(!s)throw new Error("No book");return await h.updateBook(s.id,{status:t}),t},onSuccess:t=>{x.invalidateQueries({queryKey:m.books.detail(i)}),C(`Status changed to ${t.replace(/_/g," ")} for ${s?.title??"this book"}.`),d(`Status changed to ${t.replace(/_/g," ")}`,"success")},onError:()=>d("Failed to update status","error")}),gt=t=>{!s||s.status===t||qe.mutate(t)},ae=N({mutationFn:async()=>
2{if(!s||!a)throw new Error("No edits");await h.updateBook(s.id,{title:a.title,author:a.author,priority:a.priority,status:a.status,description:a.description||void 0,amazonUrl:a.amazonUrl||void 0,evidenceUrl:a.evidenceUrl||void 0,reviewStatus:a.reviewStatus||void 0,reviewNotes:a.reviewNotes||void 0})},onSuccess:()=>{x.invalidateQueries({queryKey:m.books.detail(i)}),W(!1),p(null),C(`Saved changes for ${s?.title??"this book"}.`),d("Book updated successfully!","success")},onError:t=>{console.error("Failed to update book:",t),d("Failed to update book","error")}}),G=N({mutationFn:async()=>{if(!s)throw new Error("No book");await h.createJob({jobType:"batch",bookId:s.id,payload:{action:"generate_all_chapters"},priority:1})},onSuccess:()=>{y(null),C(`Queued full chapter generation for ${s?.title??"this book"}.`),d("Generation job queued for all chapters!","success"),x.invalidateQueries({queryKey:m.books.detail(i)})},onError:t=>{console.error("Failed to queue generation:",t),y(r=>r&&{...r,error:t.message||"Failed to queue generation job"}),d("Failed to queue generation job","error")},onSettled:()=>{P.current=!1,F(!1)}}),Ue=N({mutationFn:async t=>{if(!s)throw new Error("No book");const r=t==="pending"?await L.triggerPendingChapters(s.id,s.slug,z):await L.triggerRun(z,s.id,s.slug,"all");let n=null;return r.record_id&&(n=(await L.getRuns(s.id)).find(u=>u.id===r.record_id)??null),{mode:t,run:n}},onMutate:()=>Te(!0),onSuccess:({mode:t,run:r})=>{se(r);const n=z==="github_actions"?"GitHub Actions":"Local",u=t==="pending"?"Run":"All chapters";y(null),C(`${u} triggered for ${s?.title??"this book"} via ${n}.`),d(`${u} triggered via ${n}`,"success")},onError:t=>{y(r=>r&&{...r,error:t.message||"Unknown error"}),d(`Failed: ${t.message||"Unknown error"}`,"error")},onSettled:()=>{P.current=!1,F(!1),Te(!1)}}),bt=()=>Ue.mutate("pending"),pt=()=>Ue.mutate("all"),_=N({mutationFn:async({chapter:t,type:r})=>{if(!s)throw new Error("No book");return await h.createJob({jobType:r,bookId:s.id,chapterId:t.id,payload:{chapterNumber:t.chapterNumber,chapterTitle:t.title,regenerate:t.infographicStatus==="complete"||t.audioStatus==="complete"},priority:2}),{chapter:t,type:r}},onMutate:async({chapter:t,type:r})=>{const n=m.books.detail(i);await x.cancelQueries({queryKey:n});const u=x.getQueryData(n);return x.setQueryData(n,g=>g&&{...g,chapters:g.chapters.map(j=>j.id===t.id?{...j,[r==="infographic"?"infographicStatus":"audioStatus"]:"generating"}:j)}),{previous:u}},onSuccess:({type:t})=>{d(`${t==="infographic"?"Infographic":"Audio"} job queued!`,"success")},onError:(t,r,n)=>{n?.previous&&x.setQueryData(m.books.detail(i),n.previous),console.error("Failed to queue generation:",t),d("Failed to queue generation job","error")}}),oe=(t,r)=>{_.mutate({chapter:t,type:r})},ne=N({mutationFn:async()=>{if(!s)throw new Error("No book");await h.approveBook(s.id)},onSuccess:()=>{s&&(x.invalidateQueries({queryKey:m.books.detail(i)}),y(null),C(`${s.title} approved and published.`),d("Book approved and published!","success"),Ze.log({action_type:"book_approved",entity_type:"book",entity_id:s.id,entity_name:s.title}))},onError:t=>{y(r=>r&&{...r,error:t.message||"Failed to approve book"}),d(t.message||"Failed to approve book","error")},onSettled:()=>{P.current=!1,F(!1)}}),ht=()=>ne.mutate(),ft=t=>{_e.current=t,X(""),D(null),Y(!0)},ie=N({mutationFn:async t=>{if(!s)throw new Error("No book");return await h.rejectBook(s.id,t.trim()||void 0),t},onSuccess:t=>{s&&(x.invalidateQueries({queryKey:m.books.detail(i)}),Y(!1),X(""),D(null),C(`${s.title} sent back for review.`),d("Book sent back for review","success"),Ze.log({action_type:"book_rejected",entity_type:"book",entity_id:s.id,entity_name:s.title,metadata:t.trim()?{reason:t.trim()}:void 0}))},onError:t=>{D(t.message||"Failed to reject book"),d(t.message||"Failed to reject book","error")},onSettled:()=>{Q.current=!1,Se(!1)}}),vt=()=>{if(Q.current)return;const t=we;Q.current=!0,Se(!0),ie.mutate(t)},Ie=()=>{Q.current||(Y(!1),D(null))},le=N({onMutate:()=>{te(null)},mutationFn:async t=>{if(!s)throw new Error("No book");const{data:{session:r}}=await Ge.auth.getSession();if(!r?.access_token)throw new Error("SESSION_EXPIRED");const n=await fetch(`https://rmrbduwijacdyjwmibga.supabase.co
3/functions/v1/generate-book-cover`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.access_token}`},body:JSON.stringify({bookSlug:s.slug,forceRegenerate:t})}),u=await n.json();if(!n.ok)throw new Error(u.error||"Cover generation failed");return u},onSuccess:t=>{t.skipped?te('Cover already set — use "Regenerate" to replace it.'):(d("AI cover generated successfully!","success"),te(null),x.invalidateQueries({queryKey:m.books.detail(i)}))},onError:t=>{t.message==="SESSION_EXPIRED"?d("Session expired — please log in again","error"):d(t.message||"Failed to generate cover","error")}}),kt=(t=!1)=>le.mutate(t),jt=c?.kind==="approve_publish"?`Approve and publish ${s?.title??"this book"}`:c?.kind==="generate_all"?`Generate all chapters for ${s?.title??"this book"}`:c?.kind==="run_pending"?`Run pending chapters for ${s?.title??"this book"}`:`Run all chapters for ${s?.title??"this book"}`,Nt=c?.kind==="approve_publish"?`Publish ${s?.title??"this book"}?`:c?.kind==="generate_all"?"Generate all chapters?":c?.kind==="run_pending"?"Run pending chapters?":"Run every chapter?",wt=c?.kind==="approve_publish"?"This publishes the dev-ready book to the live catalog.":c?.kind==="generate_all"?"This queues generation work for every chapter in the book.":c?.kind==="run_pending"?"This re-runs only pending or failed chapters via the selected engine.":"This re-runs every chapter via the selected engine.",yt=c?.kind==="approve_publish"?"Confirm Approve and Publish":c?.kind==="generate_all"?"Confirm Generate All":c?.kind==="run_pending"?"Confirm Run Pending Chapters":"Confirm Run All Chapters",q=dt||ne.isPending||G.isPending||B,R=it||ie.isPending,O=(t,r)=>{Pe.current=r,F(!1),y({kind:t,error:null})},St=()=>{if(!(!c||P.current)){if(P.current=!0,F(!0),c.kind==="approve_publish"){ht();return}if(c.kind==="generate_all"){G.mutate();return}if(c.kind==="run_pending"){bt();return}pt()}},Le=()=>{P.current||y(null)},De=t=>{switch(t){case"complete":return(0,e.jsx)(pe,{className:"w-4 h-4 text-emerald-500"});case"generating":return(0,e.jsx)(Bt,{className:"w-4 h-4 text-gold-500 animate-spin"});case"error":return(0,e.jsx)(A,{className:"w-4 h-4 text-red-500"});default:return(0,e.jsx)(We,{className:"w-4 h-4 text-stone-400"})}},Qe=t=>{const r={complete:{bg:"bg-emerald-100 dark:bg-emerald-900/30",text:"text-emerald-700 dark:text-emerald-400"},generating:{bg:"bg-gold-100 dark:bg-gold-900/30",text:"text-gold-700 dark:text-gold-400"},error:{bg:"bg-red-100 dark:bg-red-900/30",text:"text-red-700 dark:text-red-400"}
3,pending:{bg:"bg-stone-100 dark:bg-stone-800",text:"text-stone-600 dark:text-stone-400"}},n=r[t]||r.pending;return(0,e.jsx)("span",{className:v("px-2 py-0.5 rounded text-xs font-medium",n.bg,n.text),children:t})};if(et)return(0,e.jsx)("div",{className:"flex items-center justify-center min-h-[400px]",children:(0,e.jsx)(w,{className:"w-6 h-6 animate-spin text-stone-400"})});if(ke||!s)return(0,e.jsxs)("div",{className:"space-y-4",children:[(0,e.jsxs)(ge,{to:"/admin/books",className:"inline-flex items-center gap-2 text-stone-500 hover:text-stone-700",children:[(0,e.jsx)(Oe,{className:"w-4 h-4"}),"Back to Books"]}),(0,e.jsxs)("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-6 text-center",children:[(0,e.jsx)(A,{className:"w-8 h-8 text-red-500 mx-auto mb-2"}),(0,e.jsx)("p",{className:"text-red-700 dark:text-red-300",children:ke||"Book not found"})]})]});const ze=s.totalChapters>0?Math.min(100,Math.round(s.completedChapters/s.totalChapters*100)):0,Ct=f.filter(t=>t.infographicStatus==="complete").length,_t=f.filter(t=>t.audioStatus==="complete").length,de=rt.find(t=>t.slug===s.domain_slug),Rt=f.some(t=>t.infographicStatus==="generating"||t.audioStatus==="generating");return(0,e.jsxs)("div",{className:"space-y-6",children:[fe(s.reviewStatus)&&(0,e.jsxs)("div",{className:"flex items-start gap-3 px-4 py-3 bg-red-50 dark:bg-red-950/40 border border-red-200 dark:border-red-800 rounded-lg text-sm",children:[(0,e.jsx)(he,{className:"w-4 h-4 text-red-500 mt-0.5 flex-shrink-0"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-semibold text-red-700 dark:text-red-400",children:"Legal Hold — Hidden from public"}),s.reviewNotes&&(0,e.jsx)("p",{className:"text-red-600 dark:text-red-500 mt-0.5",children:s.reviewNotes}),s.evidenceUrl&&(0,e.jsxs)("a",{href:s.evidenceUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-red-600 dark:text-red-400 hover:underline mt-1",children:[(0,e.jsx)(E,{className:"w-3 h-3"})," Evidence"]})]})]}),Xe(s.reviewStatus)&&(0,e.jsxs)("div",{className:"flex items-start gap-3 px-4 py-3 bg-amber-50 dark:bg-amber-950/40 border border-amber-200 dark:border-amber-800 rounded-lg text-sm",children:[(0,e.jsx)(A,{className:"w-4 h-4 text-amber-500 mt-0.5 flex-shrink-0"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-semibold text-amber-700 dark:text-amber-400",children:"Under Review"}),s.reviewNotes&&(0,e.jsx)("p",{className:"text-amber-600 dark:text-amber-500 mt-0.5",children:s.reviewNotes})]})]}),(0,e.jsxs)("div",{className:"flex flex-col items-start gap-4 sm:flex-row sm:justify-between",children:[(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsxs)(ge,{to:"/admin/books",className:"inline-flex items-center gap-2 text-stone-500 hover:text-stone-700 mb-2",children:[(0,e.jsx)(Oe,{className:"w-4 h-4"}),"Back to Books"]}),k&&a?(0,e.jsx)("input",{"aria-label":"Book title",type:"text",value:a.title,onChange:t=>p({...a,title:t.target.value}),className:"text-2xl font-bold text-stone-900 dark:text-white bg-transparent border-b-2 border-gold-500 focus:outline-none w-full min-h-11 text-base"}):(0,e.jsx)(H,{variant:"h1",children:s.title}),k&&a?(0,e.jsx)("input",{"aria-label":"Book author",type:"text",value:a.author,onChange:t=>p({...a,author:t.target.value}),className:"text-stone-500 bg-transparent border-b border-stone-300 focus:outline-none focus:border-gold-500 mt-1 min-h-11 text-base"}):(0,e.jsx)("p",{className:"text-stone-500",children:s.author})]}),(0,e.jsx)("div",{className:"flex w-full flex-wrap gap-2 sm:w-auto sm:justify-end",children:k?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("button",{onClick:xt,className:"inline-flex min-h-11 items-center gap-2 rounded-lg border border-stone-300 px-4 py-2 hover:bg-stone-100 dark:border-stone-600 dar
3k:hover:bg-stone-800",children:[(0,e.jsx)(Qt,{className:"w-4 h-4"}),"Cancel"]}),(0,e.jsxs)("button",{onClick:()=>ae.mutate(),disabled:ae.isPending,className:"inline-flex min-h-11 items-center gap-2 rounded-lg bg-emerald-600 px-4 py-2 text-white hover:bg-emerald-700 disabled:opacity-50",children:[ae.isPending?(0,e.jsx)(w,{className:"w-4 h-4 animate-spin"}):(0,e.jsx)(It,{className:"w-4 h-4"}),"Save"]})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("button",{onClick:mt,className:"inline-flex min-h-11 items-center gap-2 rounded-lg border border-stone-300 px-4 py-2 hover:bg-stone-100 dark:border-stone-600 dark:hover:bg-stone-800",children:[(0,e.jsx)(Ut,{className:"w-4 h-4"}),"Edit"]}),(0,e.jsx)(Kt,{targetType:"book",targetId:s.id,targetName:s.title}),s.status==="published"&&(0,e.jsxs)(ge,{to:`/domain/${s.domain_slug}/topic/${s.slug}`,className:"inline-flex items-center gap-2 px-4 py-2 border border-stone-300 dark:border-stone-600 rounded-lg hover:bg-stone-100 dark:hover:bg-stone-800",children:[(0,e.jsx)(E,{className:"w-4 h-4"}),"View"]}),s.status==="dev_published"&&(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsxs)("button",{onClick:t=>O("approve_publish",t.currentTarget),"aria-label":`Approve and publish ${s.title}`,disabled:ne.isPending,className:"inline-flex min-h-11 items-center gap-2 rounded-lg bg-emerald-600 px-4 py-2 text-white hover:bg-emerald-700 disabled:opacity-50",children:[(0,e.jsx)(pe,{className:"w-4 h-4"}),"Approve & Publish"]}),(0,e.jsx)("button",{onClick:t=>ft(t.currentTarget),disabled:ie.isPending,className:"inline-flex min-h-11 items-center gap-2 rounded-lg bg-gold-500 px-4 py-2 text-white hover:bg-gold-600 disabled:opacity-50",children:"Reject"})]}),s.status==="published"&&(0,e.jsxs)("span",{className:"inline-flex items-center gap-2 px-4 py-2 text-emerald-600 dark:text-emerald-400 font-medium",children:[(0,e.jsx)(pe,{className:"w-4 h-4"}),"Live"]}),Rt&&(0,e.jsxs)("span",{className:"inline-flex items-center gap-1.5 px-3 py-2 text-xs font-semibold text-emerald-700 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-900/20 border border-emerald-200 dark:border-emerald-800 rounded-lg",children:[(0,e.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"}),"Live"]}),(0,e.jsxs)("button",{onClick:t=>O("generate_all",t.currentTarget),"aria-label":`Generate all chapters for ${s.title}`,disabled:G.isPending,className:"inline-flex items-center gap-2 px-4 py-2 bg-gold-600 text-white rounded-lg hover:bg-gold-700 disabled:opacity-50",children:[G.isPending?(0,e.jsx)(w,{className:"w-4 h-4 animate-spin"}):(0,e.jsx)(Ye,{className:"w-4 h-4"}),"Generate All"]}),(0,e.jsxs)("div",{className:"flex items-center gap-2 border-l border-stone-700 pl-3",children:[(0,e.jsx)("span",{className:"text-xs text-stone-500",children:"Engine:"}),["local","github_actions"].map(t=>(0,e.jsx)("button",{onClick:()=>{ut(t),localStorage.setItem(`exec_engine_${i}`,t)},className:`px-2 py-1 rounded text-xs font-medium transition-colors ${z===t?"bg-amber-600 text-white":"bg-stone-800 text-stone-400 hover:bg-stone-700"}`,children:t==="local"?"Local":"⚡ GitHub"},t)),(0,e.jsxs)("button",{onClick:t=>O("run_pending",t.currentTarget),"aria-label":`Run pending chapters for ${s.title}`,disabled:B,title:"Run only pending/failed chapters",className:"inline-flex items-center gap-1.5 px-3 py-1.5 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg text-xs font-medium disabled:opacity-50 transition-colors",children:[B?(0,e.jsx)(w,{className:"w-3 h-3 animate-spin"}):(0,e.jsx)(Ye,{className:"w-3 h-3"}),"Pending"]}),(0,e.jsxs)("button",{onClick:t=>O("run_all",t.currentTarget),"aria-label":`Run all chapters for ${s.title}`,disabled:B,title:"Run all chapters via selected engine",className:"inline-flex items-center gap-1.5 px-3 py-1.5 bg-violet-600 hover:bg-violet-700 text-white rounded-lg text-xs font-medium disabled:opacity-50 transition-colors",children:[B?(0,e.jsx)(w,{className:"w-3 h-3 animate-spin"}):(0,e.jsx)(He,{className:"w-3 h-3"}),"All"]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[s.cover_url&&!s.cover_url.includes("books.google.com")&&!s.cover_url.includes("covers.openlibrary.org")&&(0,e.jsx)("img",{src:s.cover_url,alt:"Current cover",className:"w-7 h-10 object-cover rounded border border-stone-200 dark:border-stone-700 flex-shrink-0"}),(0,e.jsxs)("button",{onClick:()=>kt(!!(s.cover_url&&!s.cover_url.includes("books.google.com")&&!s.cover_url.includes("covers.openlibrary.org"))),disabled:le.isPending,title:s.cover_url&&!s.cover_url.includes("books.google.com")&&!s.cover_url.includes("covers.openlibrary.org")?"Regenerate AI cover":"Generate AI cover",className:"inline-flex items-center gap-2 px-3 py-2 bg-stone-700 text-gold-400 border border-stone-600 rounded-lg hover:bg-stone-600 disabled:opacity-50 text-sm",children:[le.isPending?(0,e.jsx)(w,{className:"w-4 h-4 animate-spin"}):(0,e.jsx)(Dt,{className:"w-4 h-4"}),s.cover_url&&!s.cover_url.includes("books.google.com")&&!s.cover_url.includes("covers.openlibrary.org")?"Regen Cover":"AI Cover"]})]}),$e&&(0,e.jsx)("span",{className:"text-xs text-stone-500 dark:text-stone-400 max-w-[160px] leading-tight",children:$e})]})})]}),Ae&&(0,e.jsx)("div",{role:"status","aria-live":"polite",className:"rounded-lg border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-700 dark:border-emerald-800 dark:bg-emerald-900/20 dark:text-emerald-300",children:Ae}),fe(s.reviewStatus)&&(0,e.jsxs)("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-start gap-3",children:[(0,e.jsx)(A,{className:"w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-semibold text-red-900 dark:text-red-100",children:"Legal Hold — hidden from users"}),(0,e.jsx)("p",{className:"text-sm text-red-700 dark:text-red-300 mt-1",children:"This book is flagged and should not appear on public or non-admin surfaces."})]})]}),!fe(s.reviewStatus)&&Xe(s.reviewStatus)&&(0,e.jsxs)("div",{className:"bg-gold-50 dark:bg-gold-900/20 border border-gold-200 dark:border-gold-800 rounded-lg p-4 flex items-start gap-3",children:[(0,e.jsx)(A,{className:"w-5 h-5 text-gold-600 dark:text-gold-400 mt-0.5 flex-shrink-0"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-semibold text-gold-900 dark:text-gold-100",children:"Under Review"}),(0,e.jsx)("p",{className:"text-sm text-gold-700 dark:text-gold-300 mt-1",children:"This book is still visible to users, but should be monitored and reviewed."})]})]}),(0,e.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 border border-stone-200 dark:border-stone-700 rounded-lg p-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-stone-500 mb-1",children:[(0,e.jsx)(qt,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"text-xs uppercase tracking-wide",children:"Chapters"})]}),(0,e.jsxs)("p",{className:"text-2xl font-bold text-stone-900 dark:text-white",children:[s.completedChapters,"/",s.totalChapters]}
3),(0,e.jsx)("div",{className:"mt-2 h-2 bg-stone-100 dark:bg-stone-800 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:v("h-full rounded-full transition-all",ze===100?"bg-emerald-500":"bg-gold-500"),style:{width:`${ze}%`}})})]}),(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 border border-stone-200 dark:border-stone-700 rounded-lg p-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-stone-500 mb-1",children:[(0,e.jsx)(I,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"text-xs uppercase tracking-wide",children:"Infographics"})]}),(0,e.jsxs)("p",{className:"text-2xl font-bold text-stone-900 dark:text-white",children:[Ct,"/",f.length]})]}),(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 border border-stone-200 dark:border-stone-700 rounded-lg p-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-stone-500 mb-1",children:[(0,e.jsx)(K,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"text-xs uppercase tracking-wide",children:"Audio"})]}),(0,e.jsxs)("p",{className:"text-2xl font-bold text-stone-900 dark:text-white",children:[_t,"/",f.length]})]}),(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 border border-stone-200 dark:border-stone-700 rounded-lg p-4",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2 text-stone-500 mb-1",children:[(0,e.jsx)($t,{className:"w-4 h-4"}),(0,e.jsx)("span",{className:"text-xs uppercase tracking-wide",children:"Status"})]}),k&&a?(0,e.jsxs)("select",{value:a.status,onChange:t=>p({...a,status:t.target.value}),className:"w-full px-2 py-1 bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded",children:[(0,e.jsx)("option",{value:"planned",children:"Planned"}),(0,e.jsx)("option",{value:"in_progress",children:"In Progress"}),(0,e.jsx)("option",{value:"dev_published",children:"Dev Published"}),(0,e.jsx)("option",{value:"published",children:"Published"}),(0,e.jsx)("option",{value:"needs_review",children:"Needs Review"})]}):(0,e.jsxs)("select",{value:s.status,disabled:qe.isPending,onChange:t=>gt(t.target.value),className:"w-full px-2 py-1.5 bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded text-sm font-medium text-stone-900 dark:text-white capitalize focus:ring-2 focus:ring-gold-500 focus:outline-none disabled:opacity-50",children:[(0,e.jsx)("option",{value:"planned",children:"Planned"}),(0,e.jsx)("option",{value:"in_progress",children:"In Progress"}),(0,e.jsx)("option",{value:"dev_published",children:"Dev Published"}),(0,e.jsx)("option",{value:"published",children:"Published"}),(0,e.jsx)("option",{value:"needs_review",children:"Needs Review"})]})]})]}),(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 border border-stone-200 dark:border-stone-700 rounded-lg p-6",children:[(0,e.jsx)(H,{variant:"h3",as:"h2",className:"mb-4",children:"Book Information"}),(0,e.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 text-sm",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-stone-500",children:"Domain"}),(0,e.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[de&&(0,e.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:de.color||"#6366F1"}}),(0,e.jsx)("p",{className:"font-medium text-stone-900 dark:text-white capitalize",children:de?.name||s.domain_slug.replace(/-/g," ")})]})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-stone-500",children:"Priority"}),k&&a?(0,e.jsxs)("select",{value:a.priority,onChange:t=>p({...a,priority:t.target.value}),className:"w-full mt-1 px-2 py-2 text-base bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded",children:[(0,e.jsx)("option",{value:"P1",children:"P1 (High)"}),(0,e.jsx)("option",{value:"P2",children:"P2 (Medium)"}),(0,e.jsx)("option",{value:"P3",children:"P3 (Low)"})]}):(0,e.jsx)("p",{className:v("font-medium mt-1",s.priority==="P1"?"text-red-600":s.priority==="P2"?"text-gold-600":"text-stone-600"),children:s.priority})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-stone-500",children:"Publication Year"}),(0,e.jsx)("p",{className:"font-medium text-stone-900 dark:text-white mt-1",children:s.publicationYear||"-"})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-stone-500",children:"Goodreads Rating"}),(0,e.jsx)("p",{className:"font-medium text-stone-900 dark:text-white mt-1",children:s.goodreadsRating?`${s.goodreadsRating}/5`:"-"})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-stone-500",children:"Review Status"}),k&&a?(0,e.jsxs)("select",{value:a.reviewStatus,onChange:t=>p({...a,reviewStatus:t.target.value}),className:"w-full mt-1 px-2 py-2 text-base bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded",children:[(0,e.jsx)("option",{value:"approved",children:"approved"}),(0,e.jsx)("option",{value:"under_review",children:"under_review"}),(0,e.jsx)("option",{value:"flagged",children:"flagged"})]}):(0,e.jsx)("p",{className:"font-medium text-stone-900 dark:text-white mt-1",children:s.reviewStatus||"approved"})]})]}),k&&a?(0,e.jsxs)("div",{className:"mt-4",children:[(0,e.jsx)("p",{className:"text-stone-500 text-sm mb-1",children:"Description"}),(0,e.jsx)("textarea",{value:a.description,onChange:t=>p({...a,description:t.target.value}),rows:3,className:"w-full px-3 py-2 text-base bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-gold-500",placeholder:"Add a description..."})]}):s.description?(0,e.jsxs)("div",{className:"mt-4",children:[(0,e.jsx)("p",{className:"text-stone-500 text-sm mb-1",children:"Description"}),(0,e.jsx)("p",{className:"text-stone-700 dark:text-stone-300",children:s.description})]}):null,(0,e.jsxs)("div",{className:"mt-4 grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-stone-500 text-sm mb-1",children:"Affiliate Link"}),k&&a?(0,e.jsx)("input",{value:a.amazonUrl,onChange:t=>p({...a,amazonUrl:t.target.value}),className:"w-full px-3 py-2 text-base bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-gold-500",placeholder:"https://www.amazon.com/..."}):s.amazonUrl?(0,e.jsxs)("a",{href:s.amazonUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 text-gold-600 hover:underline mt-1",children:["Buy link ",(0,e.jsx)(E,{className:"w-3.5 h-3.5"})]}):(0,e.jsx)("p",{className:"text-stone-400 mt-1",children:"Missing"})]}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-stone-500 text-sm mb-1",children:"Evidence URL"}),k&&a?(0,e.jsx)("input",{value:a.evidenceUrl,onChange:t=>p({...a,evidenceUrl:t.target.value}),className:"w-full px-3 py-2 text-base bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-gold-500",placeholder:"https://..."}):s.evidenceUrl?(0,e.jsxs)("a",{href:s.evidenceUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 text-gold-600 hover:underline mt-1",children:["Supporting evidence ",(0,e.jsx)(E,{className:"w-3.5 h-3.5"})]}):(0,e.jsx)("p",{className:"text-stone-400 mt-1",children:"Missing"})]})]}),(0,e.jsxs)("div",{className:"mt-4 rounded-lg border border-stone-200 dark:border-stone-700",children:[(0,e.jsxs)("button",{type:"button",onClick:()=>lt(t=>!t),"aria-expanded":Z,className:"flex min-h-11 w-full items-center justify-between gap-3 px-4 py-3 text-left",children:[(0,e.jsx)("span",{className:"font-medium text-stone-900 dark:text-white",children:"Show legal and pipeline diagnostics"}),(0,e.jsx)("span",{className:"text-sm text-gold-600 dark:text-gold-400",children:Z?"Hide":"Show"})]}),Z&&(0,e.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 border-t border-stone-200 dark:border-stone-700 p-4 text-sm",children:[(0,e.jsxs)("div",{className:"bg-stone-50 dark:bg-stone-800 rounded-lg p-3",children:[(0,e.jsx)("p",{className:"text-stone-500 mb-1",children:"Legal Audit"}),(0,e.jsxs)("p",{className:"font-medium text-stone-900 dark:text-white",children:["Risk: ",s.contentRiskTier||"—"," ",s.contentRiskScore!=null?`(${s.contentRiskScore})`:""]}
3),(0,e.jsxs)("p",{className:"text-stone-600 dark:text-stone-400 mt-1",children:["Publisher category: ",s.publisherCategory||"—"]}),(0,e.jsxs)("p",{className:"text-stone-600 dark:text-stone-400 mt-1",children:["Rights: ",s.rightsStatus||"unknown"]}),(0,e.jsxs)("p",{className:"text-stone-600 dark:text-stone-400 mt-1",children:["Owner: ",s.rightsOwner||"—"]}),(0,e.jsxs)("p",{className:"text-stone-600 dark:text-stone-400 mt-1",children:["Scope: ",s.licenseScope||"—"]})]}),(0,e.jsxs)("div",{className:"bg-stone-50 dark:bg-stone-800 rounded-lg p-3",children:[(0,e.jsx)("p",{className:"text-stone-500 mb-1",children:"Review Notes"}),k&&a?(0,e.jsx)("textarea",{value:a.reviewNotes,onChange:t=>p({...a,reviewNotes:t.target.value}),rows:4,className:"w-full px-3 py-2 text-base bg-white dark:bg-stone-900 border border-stone-200 dark:border-stone-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-gold-500",placeholder:"Explain why this book is approved, under review, or on legal hold..."}):(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("p",{className:"text-stone-700 dark:text-stone-300 whitespace-pre-wrap",children:s.reviewNotes||s.rightsNotes||"No notes yet."}),o&&(0,e.jsxs)("div",{className:"rounded border border-stone-200 dark:border-stone-700 bg-white/60 dark:bg-stone-900/60 px-3 py-2",children:[(0,e.jsx)("p",{className:"text-stone-500 text-xs uppercase tracking-wide",children:"Pipeline summary"}),(0,e.jsxs)("p",{className:"mt-1 text-stone-700 dark:text-stone-300 text-sm break-all",children:["Authoring model: ",o.authoringModel||"—"]})]})]})]})]})]})]}),o&&(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 border border-stone-200 dark:border-stone-700 rounded-lg overflow-hidden",children:[(0,e.jsxs)("button",{onClick:()=>at(t=>!t),className:"w-full p-4 flex items-center justify-between hover:bg-stone-50 dark:hover:bg-stone-800/50 transition-colors",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)(Lt,{className:"w-5 h-5 text-gold-500"}),(0,e.jsx)(H,{variant:"h3",as:"h2",children:"Quality Scorecard"}),(0,e.jsxs)("span",{className:v("px-2 py-0.5 rounded text-sm font-bold",o.overallScore>=75?"bg-emerald-100 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-400":o.overallScore>=45?"bg-gold-100 dark:bg-gold-900/30 text-gold-700 dark:text-gold-400":"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400"),children:[o.overallScore,"/100"]}),o.flags.length>0&&(0,e.jsxs)("span",{className:"flex items-center gap-1 text-xs text-gold-600 dark:text-gold-400",children:[(0,e.jsx)(he,{className:"w-3.5 h-3.5"}),o.flags.length," flag",o.flags.length!==1?"s":""]})]}),(0,e.jsx)(Ke,{className:v("w-4 h-4 text-stone-400 transition-transform",!je&&"rotate-180")})]}),je&&(0,e.jsxs)("div",{className:"border-t border-stone-200 dark:border-stone-700 p-6 space-y-6",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"text-sm font-semibold text-stone-700 dark:text-stone-300 mb-3 uppercase tracking-wide",children:"Score Breakdown"}),(0,e.jsx)("div",{className:"space-y-2",children:[{label:"Authoring",score:o.authoringScore,max:20},{label:"Infographic",score:o.infographicScore,max:20},{label:"Completeness",score:o.completenessScore,max:20},{label:"Audio",score:o.audioScore,max:15},{label:"Uniqueness",score:o.uniquenessScore,max:10},{label:"QA Gate",score:o.qaScore,max:10},{label:"Web Signal",score:o.webSignalScore,max:5}].map(({label:t,score:r,max:n})=>{const u=Math.round(r/n*100);return(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("span",{className:"text-xs text-stone-500 w-24 flex-shrink-0",children:t}),(0,e.jsx)("div",{className:"flex-1 h-2 bg-stone-100 dark:bg-stone-800 rounded-full overflow-hidden",children:(0,e.jsx)("div",{className:v("h-full rounded-full",u>=75?"bg-emerald-500":u>=45?"bg-gold-500":"bg-red-400"),style:{width:`${u}%`}})}),(0,e.jsxs)("span",{className:"text-xs tabular-nums text-stone-600 dar
3k:text-stone-400 w-14 text-right",children:[r,"/",n]})]},t)})})]}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("h3",{className:"text-sm font-semibold text-stone-700 dark:text-stone-300 mb-3 uppercase tracking-wide flex items-center gap-2",children:[(0,e.jsx)(He,{className:"w-3.5 h-3.5"}),"Pipeline Metadata"]}),(0,e.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 text-xs",children:[{label:"Authoring Model",value:o.authoringModel},{label:"Prompt Version",value:o.promptVersionLabel||o.promptVersion},{label:"Infographic Model",value:o.infographicModel},{label:"Audio Model",value:o.audioPrimaryModel},{label:"Audio Fallback",value:o.audioFallbackTier||"None"},{label:"Composition Planner",value:o.compositionPlannerUsed?"Yes":"No"},{label:"Visual QA Run",value:o.visualQaRun?"Yes":"No"},{label:"Scored By",value:o.scoredBy||"—"},{label:"Scored At",value:o.scoredAt?new Date(o.scoredAt).toLocaleDateString():"—"}].map(({label:t,value:r})=>(0,e.jsxs)("div",{className:"bg-stone-50 dark:bg-stone-800 rounded p-2",children:[(0,e.jsx)("p",{className:"text-stone-400 mb-0.5",children:t}),(0,e.jsx)("p",{className:"font-medium text-stone-700 dark:text-stone-300 truncate",title:r??"—",children:r||"—"})]},t))})]}),o.flags.length>0&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("h3",{className:"text-sm font-semibold text-stone-700 dark:text-stone-300 mb-2 uppercase tracking-wide flex items-center gap-2",children:[(0,e.jsx)(he,{className:"w-3.5 h-3.5 text-gold-500"}),"Flags"]}),(0,e.jsx)("ul",{className:"space-y-1",children:o.flags.map((t,r)=>(0,e.jsx)("li",{className:"text-xs text-gold-700 dark:text-gold-400 bg-gold-50 dark:bg-gold-900/20 border border-gold-200 dark:border-gold-800 rounded px-3 py-1.5",children:t},r))})]}),o.recommendations.length>0&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("h3",{className:"text-sm font-semibold text-stone-700 dark:text-stone-300 mb-2 uppercase tracking-wide flex items-center gap-2",children:[(0,e.jsx)(zt,{className:"w-3.5 h-3.5 text-gold-500"}),"Recommendations"]}),(0,e.jsx)("ul",{className:"space-y-1",children:o.recommendations.map((t,r)=>(0,e.jsx)("li",{className:"text-xs text-gold-700 dark:text-gold-400 bg-gold-50 dark:bg-gold-900/20 border border-gold-200 dark:border-gold-800 rounded px-3 py-1.5",children:t},r))})]})]})]}),(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 border border-stone-200 dark:border-stone-700 rounded-lg p-6",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,e.jsxs)(H,{variant:"h3",className:"flex items-center gap-2",children:[(0,e.jsx)(Ve,{className:"w-5 h-5 text-gold-500"}),"Scroll Video"]}),(0,e.jsx)("button",{onClick:()=>re.mutate(),disabled:re.isPending,className:"inline-flex items-center gap-2 px-4 py-2 bg-gold-500 text-white rounded-lg hover:bg-gold-600 disabled:opacity-50 text-sm font-medium transition-colors",children:re.isPending?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(w,{className:"w-4 h-4 animate-spin"})," Generating..."]}):b?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Je,{className:"w-4 h-4"})," Regenerate"]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Ve,{className:"w-4 h-4"})," Generate Scroll"]})})]}),b?(0,e.jsxs)("div",{className:"flex gap-4",children:[b.thumbnail_url&&(0,e.jsx)("img",{src:b.thumbnail_url,className:"w-24 h-40 object-cover rounded",alt:"Scroll thumbnail"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{className:"flex items-center gap-2 mb-2",children:(0,e.jsx)("span",{className:v("px-2 py-1 rounded text-xs font-medium",b.status==="complete"?"bg-emerald-100 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-400":b.status==="failed"?"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400":"bg-gold-100 dark:bg-gold-900/30 text-gold-700 dark:text-gold-400"),children:(b.status??"").replace(/_/g," ")})}),(0,e.jsxs)("div",{className:"text-sm text-stone-500 space-y-1",children:[(0,e.jsxs)("p",{children:["Views: ",b.view_count??0," · Likes: ",b.like_count??0]}),(0,e.jsxs)("p",{children:["Created: ",b.created_at?new Date(b.created_at).toLocaleDateString():"—"]})]}),b.video_url&&(0,e.jsxs)("a",{href:b.video_url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 hover:text-blue-300 text-sm mt-2 inline-flex items-center gap-1",children:[(0,e.jsx)(E,{className:"w-3.5 h-3.5"})," Preview video"]})]})]}):(0,e.jsx)("p",{className:"text-stone-500 text-sm",children:"No scroll generated yet."})]}),(0,e.jsxs)(ve,{open:nt,onOpenChange:t=>{t||Ie()},title:`Reject ${s?.title??"book"}?`,ariaLabel:`Reject ${s?.title??"book"}`,description:"Send back for another review pass.",placement:"center",initialFocusRef:Ce,returnFocusRef:_e,dismissible:!R,contentClassName:"space-y-3 px-5 py-3",headerClassName:"px-5 py-3",backdropClassName:"bg-black/75",className:"w-[min(30rem,calc(100vw-1.5rem))]",children:[ye?(0,e.jsx)("div",{role:"alert",className:"rounded-[var(--sb-radius-control)] border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-800 dark:bg-red-900/20 dark:text-red-300",children:ye}):null,(0,e.jsxs)("div",{children:[(0,e.jsxs)("label",{htmlFor:"book-rejection-reason",className:"mb-1 block text-sm font-medium text-stone-700 dark:text-stone-300",children:["Reason ",(0,e.jsx)("span",{className:"font-normal text-stone-400",children:"(optional)"})]}),(0,e.jsx)("textarea",{ref:Ce,id:"book-rejection-reason","aria-label":"Rejection reason (optional)",value:we,onChange:t=>X(t.target.value),disabled:R,rows:1,placeholder:"What needs another pass?",className:"min-h-11 w-full resize-none rounded-[var(--sb-radius-control)] border border-[var(--sb-border)] bg-[var(--sb-surface)] px-3 py-2 text-base text-[var(--sb-ink)] focus-visible:border-stone-500 focus-visible:!outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-stone-400 dark:focus-visible:border-stone-400 dark:focus-visible:ring-stone-500 disabled:opacity-60"})]}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,e.jsx)("button",{type:"button",onClick:Ie,"aria-disabled":R,className:"inline-flex min-h-11 items-center justify-center rounded-[var(--sb-radius-control)] border border-[var(--sb-border-strong)] px-4 text-sm font-medium text-[var(--sb-ink-muted)] hover:bg-[var(--sb-surface-subtle)] focu
3s-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)] aria-disabled:cursor-wait aria-disabled:opacity-50",children:"Cancel"}),(0,e.jsxs)("button",{type:"button",onClick:vt,"aria-disabled":R,"aria-label":R?"Rejecting book":"Reject & Send Back",className:"inline-flex min-h-11 items-center justify-center gap-2 rounded-[var(--sb-radius-control)] bg-[var(--sb-accent)] px-4 text-sm font-semibold text-white hover:brightness-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)] aria-disabled:cursor-wait aria-disabled:opacity-60",children:[R?(0,e.jsx)(w,{className:"h-4 w-4 animate-spin"}):(0,e.jsx)(A,{className:"h-4 w-4"}),R?"Rejecting…":"Reject"]})]})]}),(0,e.jsxs)(ve,{open:c!==null,onOpenChange:t=>{t||Le()},title:Nt,ariaLabel:jt,description:wt,placement:"center",initialFocusRef:Re,returnFocusRef:Pe,dismissible:!q,contentClassName:"space-y-2 px-5 py-2",headerClassName:"px-5 py-3",backdropClassName:"bg-black/75",className:"w-[min(30rem,calc(100vw-1.5rem))]",children:[c?.error?(0,e.jsx)("div",{role:"alert",className:"rounded-[var(--sb-radius-control)] border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-800 dark:bg-red-900/20 dark:text-red-300",children:c.error}):null,(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,e.jsx)("button",{ref:Re,type:"button",onClick:Le,"aria-disabled":q,className:"inline-flex min-h-11 items-center justify-center rounded-[var(--sb-radius-control)] border border-[var(--sb-border-strong)] px-4 text-sm font-medium text-[var(--sb-ink-muted)] hover:bg-[var(--sb-surface-subtle)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)] aria-disabled:cursor-wait aria-disabled:opacity-50",children:"Cancel"}),(0,e.jsx)("button",{type:"button",onClick:St,"aria-disabled":q,"aria-label":q?"Working":yt,className:"inline-flex min-h-11 items-center justify-center rounded-[var(--sb-radius-control)] bg-[var(--sb-accent)] px-5 text-sm font-semibold text-white hover:brightness-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)] aria-disabled:cursor-wait aria-disabled:opacity-60",children:q?"Working…":"Confirm"})]})]}),(0,e.jsxs)("div",{children:[(0,e.jsxs)("div",{className:"flex overflow-x-auto rounded-t-lg border-b border-stone-200 bg-white dark:border-stone-700 dark:bg-stone-900",children:[["chapters","blueprint","gallery"].map(t=>(0,e.jsx)("button",{onClick:()=>ct(t),className:v("-mb-px shrink-0 whitespace-nowrap border-b-2 px-5 py-3 text-sm font-medium capitalize transition-colors",M===t?"border-gold-500 text-gold-600 dark:text-gold-400":"border-transparent text-stone-500 hover:text-stone-700 dark:hover:text-stone-300"),children:t==="blueprint"?"Blueprint Editor":t==="gallery"?"Infographic Gallery":"Chapters"},t)),M==="chapters"&&(0,e.jsx)("button",{onClick:()=>{x.invalidateQueries({queryKey:m.books.detail(i)}),x.invalidateQueries({queryKey:m.books.scorecard(i)}),x.invalidateQueries({queryKey:m.books.scroll(i)})},className:"ml-auto mr-2 self-center p-1.5 rounded hover:bg-stone-100 dark:hover:bg-stone-800 text-stone-500",title:"Refresh",children:(0,e.jsx)(w,{className:"w-4 h-4"})})]}),Be&&(0,e.jsx)("div",{className:"px-4 pb-3",children:(0,e.jsx)(Ot,{run:Be,onStatusChange:()=>{L.getActiveRun(s?.id??"").then(t=>se(t)).catch(()=>{})}})}),M==="blueprint"&&(0,e.jsx)("div",{className:"bg-white dark:bg-stone-900 border border-x border-b border-stone-200 dark:border-stone-700 rounded-b-lg divide-y divide-stone-100 dark:divide-stone-800",children:f.length===0?(0,e.jsx)("p",{className:"p-8 text-center text-stone-500",children:"No chapters yet."}):f.map(t=>{const r=ee.get(t.id)||{},n=r.audioScript??t.audioScript??"",u=n.trim().split(/\s+/).filter(Boolean).length;return(0,e.jsxs)("details",{className:"group",children:[(0,e.jsxs)("summary",{className:"px-4 py-3 flex items-center justify-between cursor-pointer hover:bg-stone-50 dark:hover:bg-stone-800/50 list-none",children:[(0,e.jsxs)("span",{className:"font-medium text-stone-800 dark:text-stone-200",children:[t.chapterNumber,". ",t.title]}),(0,e.jsxs)("span",{className:v("text-xs px-2 py-0.5 rounded",u>=150?"bg-emerald-100 text-emerald-700":u>=80?"bg-gold-100 text-gold-700":"bg-red-100 text-red-700"),children:[u,"w"]})]}),(0,e.jsxs)("div",{className:"px-4 pb-4 space-y-4 border-t border-stone-100 dar
3k:border-stone-800 pt-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"text-xs font-semibold text-stone-500 uppercase mb-1 block",children:"Audio Script"}),(0,e.jsx)("textarea",{rows:6,value:n,onChange:g=>$(j=>new Map(j).set(t.id,{...r,audioScript:g.target.value})),className:"w-full px-3 py-2 text-sm bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-gold-500 resize-y"})]}),["keyTakeaways","ahaMoments","keyStats","quotes"].map(g=>{const j=r[g]??t[g]??[];return(0,e.jsxs)("div",{children:[(0,e.jsx)("label",{className:"text-xs font-semibold text-stone-500 uppercase mb-1 block",children:{keyTakeaways:"Key Takeaways",ahaMoments:"AHA Moments",keyStats:"Key Stats",quotes:"Quotes"}[g]}),(0,e.jsxs)("div",{className:"space-y-1",children:[j.map((ce,ue)=>(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsx)("input",{value:ce,onChange:me=>{const U=[...j];U[ue]=me.target.value,$(xe=>new Map(xe).set(t.id,{...r,[g]:U}))},className:"flex-1 px-2 py-1 text-sm bg-stone-50 dark:bg-stone-800 border border-stone-200 dark:border-stone-700 rounded focus:outline-none focus:ring-1 focus:ring-gold-500"}),(0,e.jsx)("button",{onClick:()=>{const me=j.filter((U,xe)=>xe!==ue);$(U=>new Map(U).set(t.id,{...r,[g]:me}))},className:"px-2 text-red-400 hover:text-red-600",children:"✕"})]},ue)),(0,e.jsx)("button",{onClick:()=>$(ce=>new Map(ce).set(t.id,{...r,[g]:[...j,""]})),className:"text-xs text-gold-500 hover:underline",children:"+ Add"})]})]},g)}),ee.has(t.id)&&(0,e.jsx)("button",{onClick:()=>T.mutate(t),disabled:T.isPending&&T.variables?.id===t.id,className:"px-4 py-2 bg-emerald-600 text-white text-sm rounded-lg hover:bg-emerald-700 disabled:opacity-50",children:T.isPending&&T.variables?.id===t.id?"Saving…":"Save Blueprint"})]})]},t.id)})}),M==="gallery"&&(0,e.jsxs)("div",{className:"bg-white dark:bg-stone-900 border border-x border-b border-stone-200 dark:border-stone-700 rounded-b-lg p-6",children:[f.filter(t=>t.infographicUrl).length===0?(0,e.jsxs)("div",{className:"text-center py-12 text-stone-400",children:[(0,e.jsx)(I,{className:"w-10 h-10 mx-auto mb-3 opacity-30"}),(0,e.jsx)("p",{children:"No infographics yet. Generate chapters first."})]}):(0,e.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4",children:f.map(t=>{const r=t.infographicUrl;return(0,e.jsxs)("div",{className:v("border-2 rounded-lg overflow-hidden group relative",t.infographicStatus==="complete"?"border-emerald-300 dark:border-emerald-700":t.infographicStatus==="error"?"border-red-300 dark:border-red-700":"border-stone-200 dark:border-stone-700"),children:[r?(0,e.jsx)("button",{type:"button",onClick:n=>{Fe.current=n.currentTarget,Ee({url:r,title:t.title})},"aria-label":`Preview infographic for chapter ${t.chapterNumber}: ${t.title}`,className:"block w-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--sb-focus)]",children:(0,e.jsx)("img",{src:r,alt:"",className:"aspect-[4/5] w-full object-cover",loading:"lazy"})}):(0,e.jsx)("div",{className:"w-full aspect-[4/5] bg-stone-100 dark:bg-stone-800 flex items-center justify-center",children:(0,e.jsx)(We,{className:"w-6 h-6 text-stone-300"})}),(0,e.jsxs)("div",{className:"p-2 bg-white dark:bg-stone-900",children:[(0,e.jsxs)("p",{className:"text-xs font-medium text-stone-700 dark:text-stone-300 truncate",children:[t.chapterNumber,". ",t.title]}),(0,e.jsxs)("div",{className:"flex gap-1 mt-1 items-center",children:[(0,e.jsx)("button",{onClick:()=>oe(t,"infographic"),className:"text-xs text-gold-600 hover:underline",children:"Regen"}),r&&(0,e.jsx)("button",{onClick:()=>navigator.clipboard.writeText(r),className:"text-xs text-stone-400 hover:text-stone-600 ml-auto",children:"Copy URL"})]})]})]},t.id)})}),(0,e.jsx)(ve,{open:S!==null,onOpenChange:t=>{t||Ee(null)},title:S?.title??"Chapter visual",ariaLabel:`${S?.title??"Chapter"} infographic`,placement:"center",initialFocusRef:Me,returnFocusRef:Fe,closeLabel:"Close infographic preview",contentClassName:"flex min-h-0 flex-1 items-center justify-center overflow-hidden bg-black p-2 sm:p-3",headerClassName:"border-white/10 bg-black px-4 py-2 text-white",backdropClassName:"bg-black/85",className:"!max-h-[calc(100dvh-3rem)] w-[min(72rem,calc(100vw-1rem))] bg-black text-white",headerActions:S?(0,e.jsx)("a",{ref:Me,href:S.url,target:"_blank",rel:"noreferrer","aria-label":"Open full size",className:"inline-flex h-11 w-11 shrink-0 items-center justify-center rounded-[var(--sb-radius-control)] border border-white/15 bg-white/5 text-white/80 ring-2 ring-[var(--sb-focus)] ring-offset-2 ring-offset-black hover:bg-white/10 hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--sb-focus)]",children:(0,e.jsx)(E,{className:"h-5 w-5","aria-hidden":"true"})}):null,children:S?(0,e.jsx)("img",{src:S.url,alt:`${S.title} infographic`,className:"h-full w-full object-contain",style:{maxHeight:"calc(100dvh - 7.5rem)"},loading:"eager"}):null})]}),M==="chapters"&&(0,e.jsx)("div",{className:"bg-white dark:bg-stone-900 border border-x border-b border-stone-200 dark:border-stone-700 rounded-b-lg overflow-hidden",children:(0,e.jsx)("div",{className:"divide-y divide-stone-100 dar
3k:divide-stone-800",children:f.length===0?(0,e.jsx)("div",{className:"px-4 py-8 text-center text-stone-500",children:"No chapters found. Run the pipeline to initialize chapters."}):f.map(t=>(0,e.jsxs)("div",{className:"hover:bg-stone-50 dark:hover:bg-stone-800/50",children:[(0,e.jsxs)("div",{className:"px-4 py-3 flex items-center justify-between",children:[(0,e.jsxs)("div",{className:"flex items-center gap-4 flex-1",children:[(0,e.jsx)("span",{className:"text-stone-400 w-8",children:t.chapterNumber}),(0,e.jsxs)("div",{className:"flex-1",children:[(0,e.jsx)("p",{className:"font-medium text-stone-900 dark:text-white",children:t.title}),t.subtitle&&(0,e.jsx)("p",{className:"text-sm text-stone-500",children:t.subtitle})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-6",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(I,{className:"w-4 h-4 text-stone-400"}),De(t.infographicStatus),Qe(t.infographicStatus)]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(K,{className:"w-4 h-4 text-stone-400"}),De(t.audioStatus),Qe(t.audioStatus)]}),(0,e.jsxs)("div",{className:"flex items-center gap-1",children:[t.remediationFlag&&t.remediationFlag!=="ok"&&(0,e.jsx)("span",{className:v("px-1.5 py-0.5 rounded text-[10px] font-semibold border mr-1",t.remediationFlag==="regen_full"?"bg-red-50 text-red-600 border-red-200 dark:bg-red-900/20 dark:text-red-400":t.remediationFlag==="regen_media"?"bg-orange-50 text-orange-600 border-orange-200 dark:bg-orange-900/20 dark:text-orange-400":t.remediationFlag==="regen_audio"?"bg-purple-50 text-purple-600 border-purple-200 dark:bg-purple-900/20 dark:text-purple-400":t.remediationFlag==="regen_infographic"?"bg-blue-50 text-blue-600 border-blue-200 dark:bg-blue-900/20 dark:text-blue-400":"bg-gold-50 text-gold-600 border-gold-200 dark:bg-gold-900/20 dark:text-gold-400"),children:t.remediationFlag.replace("regen_","").replace("_"," ")}),t.infographicPrompt?(0,e.jsx)("button",{onClick:()=>oe(t,"infographic"),disabled:_.isPending&&_.variables?.chapter.id===t.id||t.infographicStatus==="generating",className:"p-2 rounded hover:bg-gold-100 dark:hover:bg-gold-900/30 text-gold-600 disabled:opacity-50",title:t.infographicStatus==="complete"?"Regenerate Infographic (prompt ready)":"Generate Infographic (prompt ready)",children:_.isPending&&_.variables?.chapter.id===t.id?(0,e.jsx)(w,{className:"w-4 h-4 animate-spin"}):t.infographicStatus==="complete"?(0,e.jsx)(Je,{className:"w-4 h-4"}):(0,e.jsx)(I,{className:"w-4 h-4"})}):(0,e.jsx)("button",{disabled:!0,className:"p-2 rounded text-stone-300 dark:text-stone-600 cursor-not-allowed",title:"No infographic_prompt — run batch-blueprint-book.ts first",children:(0,e.jsx)(I,{className:"w-4 h-4"})}),t.audioScript&&typeof t.audioScript=="string"?(0,e.jsx)("button",{onClick:()=>oe(t,"audio"),disabled:_.isPending&&_.variables?.chapter.id===t.id||t.audioStatus==="generating",className:"p-2 rounded hover:bg-gold-100 dark:hover:bg-gold-900/30 text-gold-600 disabled:opacity-50",title:t.audioStatus==="complete"?"Regenerate Audio (script ready)":"Generate Audio (script ready)",children:(0,e.jsx)(K,{className:"w-4 h-4"})}):(0,e.jsx)("button",{disabled:!0,className:"p-2 rounded text-stone-300 dark:text-stone-600 cursor-not-allowed",title:"No audio_script — run batch-blueprint-book.ts first",children:(0,e.jsx)(K,{className:"w-4 h-4"})}),(t.infographicUrl||t.audioUrl)&&(0,e.jsx)("button",{onClick:()=>ot(J===t.id?null:t.id),className:"p-2 rounded hover:bg-stone-100 dark:hover:bg-stone-700 text-stone-500",title:"Preview",children:J===t.id?(0,e.jsx)(Ke,{className:"w-4 h-4"}):(0,e.jsx)(Tt,{className:"w-4 h-4"})})]})]})]}),J===t.id&&(0,e.jsx)("div",{className:"px-4 py-4 bg-stone-50 dark:bg-stone-800/50 border-t border-stone-200 dark:border-stone-700",children:(0,e.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[t.infographicUrl&&(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm font-medium text-stone-600 dar
3k:text-stone-400 mb-2",children:"Infographic"}),(0,e.jsx)("img",{src:t.infographicUrl,alt:t.title,className:"w-full max-h-64 object-contain rounded-lg border border-stone-200 dark:border-stone-700 bg-white"})]}),t.audioUrl&&(0,e.jsxs)("div",{children:[(0,e.jsxs)("p",{className:"text-sm font-medium text-stone-600 dark:text-stone-400 mb-2",children:["Audio ",t.audioDuration&&`(${Math.round(t.audioDuration/60)}:${String(t.audioDuration%60).padStart(2,"0")})`]}),(0,e.jsx)("audio",{controls:!0,className:"w-full",children:(0,e.jsx)("source",{src:t.audioUrl,type:"audio/mpeg"})})]}),t.lastError&&(0,e.jsx)("div",{className:"col-span-2 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-3",children:(0,e.jsxs)("p",{className:"text-sm text-red-700 dark:text-red-300",children:[(0,e.jsx)("strong",{children:"Last Error:"})," ",t.lastError]})})]})})]},t.id))})})]})]})}export{Fs as BookDetailPage,Fs 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.