openwriter 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -206,7 +206,7 @@ Run: npm update -g openwriter`,children:["v",T.latestVersion]})]}),c.jsxs("div",
|
|
|
206
206
|
`);et.trim()&&fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:n,text:et,note:G.trim(),nodeId:Le[Le.length-1],nodeIds:Le})}).then(()=>{s(!1),z(!1),D("")}).catch(ot=>{console.error("[ContextMenu] Comment create failed:",ot)})},[t,n,G,U]),nt=x.useCallback(()=>{se&&(q({id:se.id,text:se.text}),D(se.note),z(!0),V(null))},[se]),ht=x.useCallback(()=>{se&&fetch("/api/comments/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[se.id]})}).then(()=>{s(!1),V(null)}).catch(te=>{console.error("[ContextMenu] Comment resolve failed:",te)})},[se]),Fe=x.useCallback(()=>{se&&fetch("/api/comments",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[se.id]})}).then(()=>{s(!1),V(null)}).catch(te=>{console.error("[ContextMenu] Comment delete failed:",te)})},[se]),ve=x.useCallback((te,de)=>{const fe=We.current||t.current;if(fe){const Je=te.docId?Tp({docId:te.docId,nodeId:de==null?void 0:de.nodeId,quote:de==null?void 0:de.quote}):Tp({filename:te.filename});fe.chain().focus().setLink({href:Je}).run()}fetch("/api/auto-tag-link",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetFile:te.filename})}).catch(()=>{}),s(!1),w(!1),oe(null)},[t]),X=x.useCallback(te=>{if(!te.docId){ve(te);return}oe({docId:te.docId,filename:te.filename,title:te.title,paragraphs:[],loading:!0}),fetch(`/api/documents/by-doc-id/${te.docId}/paragraphs`).then(de=>de.json()).then(de=>{oe(fe=>fe&&fe.docId===te.docId?{...fe,paragraphs:Array.isArray(de.paragraphs)?de.paragraphs:[],loading:!1}:fe)}).catch(()=>{oe(de=>de&&de.docId===te.docId?{...de,paragraphs:[],loading:!1}:de)})},[ve]),Be=x.useCallback(()=>{const te=O.trim();if(!te)return;const de=We.current||t.current;de&&(fetch("/api/create-link-doc",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:te})}).then(fe=>fe.json()).then(fe=>{if(fe.filename){const Je=Tp(fe.docId?{docId:fe.docId}:{filename:fe.filename});de.chain().focus().setLink({href:Je}).run()}}).catch(()=>{}),s(!1),w(!1),A(!1),B(""))},[t,O]);return r?c.jsx("div",{ref:xe,className:"context-menu",style:{left:i.x,top:i.y},children:l?c.jsx("div",{className:"context-menu-loading",children:"Applying..."}):J?c.jsxs("div",{className:"context-menu-comment-editor",children:[(()=>{const te=(U==null?void 0:U.text)??(()=>{const de=We.current||t.current,fe=we.current;return!de||!fe||fe.from===fe.to?"":de.state.doc.textBetween(fe.from,fe.to,`
|
|
207
207
|
`)})();return te?c.jsx("div",{className:"context-menu-comment-quote",children:te}):null})(),c.jsx("textarea",{autoFocus:!0,className:"context-menu-comment-textarea",value:G,onChange:te=>D(te.target.value),onKeyDown:te=>{te.key==="Enter"&&(te.metaKey||te.ctrlKey)&&(te.preventDefault(),at()),te.key==="Escape"&&(s(!1),z(!1),D(""),q(null))},placeholder:"Note for agent (optional)...",rows:4}),c.jsxs("div",{className:"context-menu-comment-actions",children:[c.jsx("span",{className:"context-menu-comment-hint",children:"⌘↵ to save · Esc to cancel"}),c.jsx("button",{onClick:at,children:U?"Save":"Comment"})]})]}):se?c.jsxs(c.Fragment,{children:[c.jsx("button",{className:"context-menu-item",onClick:nt,children:c.jsx("span",{children:"Edit comment"})}),c.jsx("button",{className:"context-menu-item",onClick:ht,children:c.jsx("span",{children:"Resolve comment"})}),c.jsx("button",{className:"context-menu-item",onClick:Fe,children:c.jsx("span",{children:"Delete comment"})})]}):m?c.jsxs("div",{className:"context-menu-custom",children:[c.jsx("input",{autoFocus:!0,value:f,onChange:te=>h(te.target.value),onKeyDown:te=>{te.key==="Enter"&&ft(),te.key==="Escape"&&s(!1)},placeholder:"Custom instruction..."}),c.jsx("button",{onClick:ft,children:"Apply"})]}):ge?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsxs("div",{className:"context-menu-link-header",children:[c.jsx("button",{className:"context-menu-link-back",onClick:()=>oe(null),title:"Back to doc list",children:"←"}),c.jsxs("span",{children:['Pick paragraph in "',ge.title,'"']})]}),c.jsx("button",{className:"context-menu-item context-menu-new-link",onClick:()=>ve({filename:ge.filename,docId:ge.docId}),children:c.jsx("span",{children:"Link whole doc"})}),c.jsx("div",{className:"context-menu-link-list",children:ge.loading?c.jsx("div",{className:"context-menu-loading",children:"Loading…"}):ge.paragraphs.length===0?c.jsx("div",{className:"context-menu-loading",children:"No paragraphs"}):ge.paragraphs.map(te=>{const de=te.preview.replace(/…$/,"").slice(0,50),fe=te.type==="heading"?Math.max(0,(te.level||1)-1)*12:12;return c.jsx("button",{className:`context-menu-item context-menu-paragraph-row context-menu-paragraph-row--${te.type}`,style:{paddingLeft:8+fe},onClick:()=>ve({filename:ge.filename,docId:ge.docId},{nodeId:te.nodeId,quote:de}),children:c.jsx("span",{children:te.preview})},te.nodeId)})})]}):j&&re?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsxs("div",{className:"context-menu-link-header",children:["Linked from ",re.entries.length," ",re.entries.length===1?"place":"places"]}),c.jsx("div",{className:"context-menu-link-list",children:re.entries.map((te,de)=>{const fe=S.find(Le=>Le.docId===te.from_doc),Je=(fe==null?void 0:fe.title)||te.from_doc;return c.jsxs("button",{className:"context-menu-item",onClick:()=>{window.dispatchEvent(new CustomEvent("ow-navigate-to-link",{detail:{docId:te.from_doc,nodeId:te.from_node,filename:null,quote:null}})),s(!1),L(!1)},children:[c.jsx("span",{children:Je}),c.jsxs("span",{className:"context-menu-shortcut",children:['"',te.text,'"']})]},`${te.from_doc}-${te.from_node}-${de}`)})})]}):k?c.jsxs("div",{className:"context-menu-link-picker",children:[c.jsx("div",{className:"context-menu-link-header",children:"Link to document"}),_?c.jsxs("div",{className:"context-menu-custom",children:[c.jsx("input",{autoFocus:!0,value:O,onChange:te=>B(te.target.value),onKeyDown:te=>{te.key==="Enter"&&Be(),te.key==="Escape"&&A(!1)},placeholder:"New document title..."}),c.jsx("button",{onClick:Be,children:"Create"})]}):c.jsx("button",{className:"context-menu-item context-menu-new-link",onClick:()=>A(!0),children:c.jsx("span",{children:"+ New link doc"})}),c.jsxs("div",{className:"context-menu-link-list",children:[T.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-section-header",children:"Linked in this doc"}),S.filter(te=>vk(te,T)).map(te=>c.jsxs("div",{className:"context-menu-link-row",children:[c.jsx("button",{className:"context-menu-item context-menu-link-row__main",onClick:()=>ve(te),children:c.jsx("span",{children:te.title})}),te.docId&&c.jsx("button",{className:"context-menu-link-row__drill",title:"Pick a paragraph in this doc",onClick:()=>X(te),children:"▸"})]},`linked-${te.filename}`))]}),c.jsx("div",{className:"context-menu-section-header",children:"All documents"}),S.filter(te=>!vk(te,T)).map(te=>c.jsxs("div",{className:"context-menu-link-row",children:[c.jsx("button",{className:"context-menu-item context-menu-link-row__main",onClick:()=>ve(te),children:c.jsx("span",{children:te.title})}),te.docId&&c.jsx("button",{className:"context-menu-link-row__drill",title:"Pick a paragraph in this doc",onClick:()=>X(te),children:"▸"})]},te.filename)),S.length===0&&c.jsx("div",{className:"context-menu-loading",children:"No documents"})]})]}):(()=>{const te=mt();let de;return te.map((fe,Je)=>{const Le=fe.isPlugin&&fe.pluginDisplayName&&fe.pluginDisplayName!==de,et=de!==void 0;fe.isPlugin?de=fe.pluginDisplayName:de=void 0;const ot=!fe.isPlugin&&et;return c.jsxs("span",{children:[Le&&c.jsx("div",{className:"context-menu-section-header",children:fe.pluginDisplayName}),ot&&c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{className:"context-menu-item",onClick:()=>gt(fe),children:[c.jsx("span",{children:fe.label}),fe.shortcut&&c.jsx("span",{className:"context-menu-shortcut",children:fe.shortcut})]})]},fe.action)})})()}):null}const n8=80,jp=8,qo=8,r8=400;function yk(t){return t.nodeIds&&t.nodeIds.length>0?t.nodeIds:[t.nodeId]}function bk(t,e){const n=new Set(e);return t.every(r=>n.has(r))}function s8(t,e){const n=e.find(s=>s.id===t);if(!n)return[];const r=yk(n);return e.filter(s=>{if(s.id===n.id)return!0;const i=yk(s);return bk(i,r)||bk(r,i)}).sort((s,i)=>(s.createdAt||"").localeCompare(i.createdAt||""))}function i8({documentId:t}){const[e,n]=x.useState(null),[r,s]=x.useState({kind:"view"}),[i,o]=x.useState(""),[l,d]=x.useState(0),[f,h]=x.useState({left:0,top:0,placement:"above"}),m=x.useRef(null),g=x.useRef(null),v=x.useRef(null),b=x.useRef(null),k=x.useRef({kind:"view"});x.useEffect(()=>{b.current=e},[e]),x.useEffect(()=>{k.current=r},[r]),x.useEffect(()=>{const G=()=>d(D=>D+1);return window.addEventListener("ow-comments-changed",G),()=>window.removeEventListener("ow-comments-changed",G)},[]);const w=x.useCallback(()=>{v.current!==null&&(window.clearTimeout(v.current),v.current=null)},[]),S=x.useCallback(()=>{w(),v.current=window.setTimeout(()=>{k.current.kind==="view"&&n(null)},n8)},[w]),N=x.useCallback(()=>{w(),n(null),s({kind:"view"}),o("")},[w]),T=x.useMemo(()=>e?s8(e.commentId,Ou()):[],[e,l]);x.useEffect(()=>{e&&T.length===0&&N()},[e,T.length,N]),x.useLayoutEffect(()=>{if(!e)return;const G=m.current;if(!G)return;const D=G.getBoundingClientRect(),{rect:U}=e,q=U.top,se=window.innerHeight-U.bottom,V=q>=D.height+jp||q>=se?"above":"below",re=V==="above"?Math.max(qo,U.top-D.height-jp):Math.min(window.innerHeight-D.height-qo,U.bottom+jp);let K=U.left;K+D.width>window.innerWidth-qo&&(K=window.innerWidth-D.width-qo),K<qo&&(K=qo),h({left:K,top:re,placement:V})},[e,r,T.length,l]),x.useEffect(()=>{const G=se=>{var K,j,L;const V=se.target,re=(K=V==null?void 0:V.closest)==null?void 0:K.call(V,"[data-comment-id]");if(re){const ee=re.getAttribute("data-comment-id");if(!ee)return;if(((j=b.current)==null?void 0:j.commentId)===ee){w();return}w(),s({kind:"view"}),o(""),n({commentId:ee,rect:re.getBoundingClientRect()});return}if((L=m.current)!=null&&L.contains(V)){w();return}b.current&&S()},D=se=>{var re,K;const V=se.relatedTarget;if(V&&((re=m.current)!=null&&re.contains(V))){w();return}V&&((K=V.closest)!=null&&K.call(V,"[data-comment-id]"))||b.current&&S()},U=se=>{if(se.key==="Escape"&&b.current){if(se.preventDefault(),k.current.kind!=="view"){s({kind:"view"}),o("");return}N()}},q=se=>{var V;b.current&&k.current.kind==="view"&&((V=m.current)!=null&&V.contains(se.target)||N())};return document.addEventListener("mouseover",G),document.addEventListener("mouseout",D),document.addEventListener("keydown",U),document.addEventListener("scroll",q,!0),()=>{document.removeEventListener("mouseover",G),document.removeEventListener("mouseout",D),document.removeEventListener("keydown",U),document.removeEventListener("scroll",q,!0),w()}},[w,S,N]),x.useEffect(()=>{var G;r.kind!=="view"&&((G=g.current)==null||G.focus())},[r]);const M=x.useCallback(G=>{const D=Ou().find(U=>U.id===G);D&&(o(D.note||""),s({kind:"edit",commentId:G}))},[]),_=x.useCallback(G=>{o(""),s({kind:"compose",parentCommentId:G})},[]),A=x.useCallback(()=>{s({kind:"view"}),o("")},[]),O=x.useCallback(()=>{r.kind!=="edit"||!t||fetch("/api/comments",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:t,id:r.commentId,note:i.trim()})}).then(()=>{s({kind:"view"}),o("")}).catch(G=>console.error("[CommentPopover] Save failed:",G))},[r,t,i]),B=x.useCallback(()=>{if(r.kind!=="compose"||!t)return;const G=Ou().find(D=>D.id===r.parentCommentId);G&&fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:t,text:G.text,note:i.trim(),nodeId:G.nodeId,nodeIds:G.nodeIds})}).then(()=>{s({kind:"view"}),o("")}).catch(D=>console.error("[CommentPopover] Create failed:",D))},[r,t,i]),$=x.useCallback(G=>{fetch("/api/comments/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[G]})}).catch(D=>console.error("[CommentPopover] Resolve failed:",D))},[]),W=x.useCallback(G=>{fetch("/api/comments",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:[G]})}).catch(D=>console.error("[CommentPopover] Delete failed:",D))},[]);if(!e||T.length===0)return null;const J=r.kind!=="view",z=r.kind==="compose"?"Adding a new comment on the same range":null;return c.jsx("div",{ref:m,className:`ow-comment-popover ow-comment-popover-${f.placement}`,style:{left:f.left,top:f.top,maxHeight:r8},onMouseEnter:w,onMouseLeave:S,children:J?c.jsxs(c.Fragment,{children:[z&&c.jsx("div",{className:"ow-comment-popover-empty",children:z}),c.jsx("textarea",{ref:g,className:"ow-comment-popover-textarea",value:i,onChange:G=>o(G.target.value),onKeyDown:G=>{G.key==="Enter"&&(G.metaKey||G.ctrlKey)&&(G.preventDefault(),r.kind==="edit"?O():r.kind==="compose"&&B()),G.key==="Escape"&&(G.preventDefault(),A())},rows:4,placeholder:"Note for agent (optional)..."}),c.jsxs("div",{className:"ow-comment-popover-actions",children:[c.jsx("span",{className:"ow-comment-popover-hint",children:"⌘↵ to save · Esc to cancel"}),c.jsx("button",{className:"ow-icon-btn",onClick:r.kind==="edit"?O:B,title:"Save",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M20 6 9 17l-5-5"})})})]})]}):c.jsx("div",{className:"ow-comment-popover-stack",children:T.map((G,D)=>c.jsxs("div",{className:`ow-comment-popover-card${D>0?" ow-comment-popover-card-divider":""}`,children:[G.note?c.jsx("div",{className:"ow-comment-popover-text",children:G.note}):c.jsx("div",{className:"ow-comment-popover-empty",children:"No note"}),c.jsxs("div",{className:"ow-comment-popover-actions",children:[c.jsx("button",{className:"ow-icon-btn",onClick:()=>M(G.id),title:"Edit comment",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12 20h9"}),c.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})]})}),c.jsx("button",{className:"ow-icon-btn",onClick:()=>_(G.id),title:"Add another comment on this range",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12 5v14"}),c.jsx("path",{d:"M5 12h14"})]})}),c.jsx("button",{className:"ow-icon-btn",onClick:()=>$(G.id),title:"Resolve (mark addressed)",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M20 6 9 17l-5-5"})})}),c.jsx("button",{className:"ow-icon-btn ow-icon-btn-danger",onClick:()=>W(G.id),title:"Delete (remove permanently)",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M18 6 6 18"}),c.jsx("path",{d:"m6 6 12 12"})]})})]})]},G.id))})})}function vu(t){return t.type==="doc"?t.file:t.id}function Ml(t,e){for(const n of t)n.type==="doc"?e.add(n.file):n.type==="container"&&Ml(n.items,e)}function ST(t,e,n,r){for(const s of t){if(s.type==="doc"&&s.file===e)return n||r;if(s.type==="container"){const i=s.autoAccept===!0,o=ST(s.items,e,n,r||i);if(o!==null)return o}}return null}function Ad(t,e){for(const n of t){const r=n.workspace;if(!r)continue;const s=r.autoAccept===!0;if(ST(r.root,e,s,!1)===!0)return!0}return!1}function ua(t){const e=new Date(t),n=Date.now()-e.getTime();return n<6e4?"just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<6048e5?`${Math.floor(n/864e5)}d ago`:e.toLocaleDateString()}function Ls(t){return/^[A-Z]:[/\\]|^\//.test(t)}function ET(t){const e=t.replace(/\\/g,"/").split("/");return e.length>=2?e[e.length-2]:""}function o8(t){const e=new Date(t),n=new Date,r=new Date(n.getFullYear(),n.getMonth(),n.getDate()),s=new Date(r.getTime()-864e5),i=new Date(e.getFullYear(),e.getMonth(),e.getDate());return i.getTime()===r.getTime()?"Today":i.getTime()===s.getTime()?"Yesterday":n.getTime()-i.getTime()<6048e5?e.toLocaleDateString(void 0,{weekday:"long"}):e.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function a8(t,e){const[n,r]=x.useState([]),[s,i]=x.useState([]),o=x.useRef(null),l=x.useRef(new Set),d=x.useCallback(g=>{l.current.add(g)},[]),f=x.useMemo(()=>{const g=new Set;for(const v of s)v.workspace&&Ml(v.workspace.root,g);return g},[s]),h=x.useCallback(()=>{fetch("/api/documents").then(g=>g.json()).then(g=>{if(!Array.isArray(g))return;const v=l.current;if(v.size>0){const k=new Set(g.map(w=>w.filename));for(const w of[...v])k.has(w)||v.delete(w)}const b=v.size>0?g.filter(k=>!v.has(k.filename)):g;r(b)}).catch(()=>{})},[]),m=x.useCallback(()=>{fetch("/api/workspaces").then(g=>g.json()).then(async g=>{if(!Array.isArray(g))return;const v=await Promise.all(g.map(async b=>{try{const w=await(await fetch(`/api/workspaces/${encodeURIComponent(b.filename)}`)).json();return{...b,workspace:w}}catch{return b}}));i(v)}).catch(()=>{})},[]);return x.useEffect(()=>{h()},[h,t]),x.useEffect(()=>{m()},[m,e]),x.useEffect(()=>{const g=requestAnimationFrame(()=>{var b;const v=(b=o.current)==null?void 0:b.querySelector(".sidebar-item.active");v==null||v.scrollIntoView({block:"nearest",behavior:"instant"})});return()=>cancelAnimationFrame(g)},[n]),{docs:n,setDocs:r,workspaces:s,setWorkspaces:i,assignedFiles:f,fetchDocs:h,fetchWorkspaces:m,scrollRef:o,markPendingDelete:d}}function Qg(t,e){return t.filter(n=>!e(n)).map(n=>n.type==="container"?{...n,items:Qg(n.items,e)}:n)}function NT(t,e,n){return t.map(r=>r.type==="container"&&r.id===e?{...r,name:n}:r.type==="container"?{...r,items:NT(r.items,e,n)}:r)}function l8(t,e,n,r,s,i){const o=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),i==null||i(_),fetch(`/api/documents/${encodeURIComponent(_)}`,{method:"DELETE"}).catch(()=>t())},[n,t]),l=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),fetch(`/api/documents/${encodeURIComponent(_)}/archive`,{method:"POST"}).catch(()=>t())},[n,t]),d=x.useCallback(_=>{n(A=>A.filter(O=>O.filename!==_)),fetch(`/api/documents/${encodeURIComponent(_)}/unarchive`,{method:"POST"}).catch(()=>t())},[n,t]),f=x.useCallback((_,A,O)=>{!O.trim()||O.trim()===A||(n(B=>B.map($=>$.filename===_?{...$,title:O.trim()}:$)),fetch(`/api/documents/${encodeURIComponent(_)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:O.trim()})}).catch(()=>t()))},[n,t]),h=x.useCallback(_=>{r(A=>A.filter(O=>O.filename!==_)),fetch(`/api/workspaces/${encodeURIComponent(_)}`,{method:"DELETE"}).catch(()=>e())},[r,e]),m=x.useCallback((_,A)=>{A.trim()&&(r(O=>O.map(B=>B.filename===_?{...B,title:A.trim()}:B)),fetch(`/api/workspaces/${encodeURIComponent(_)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:A.trim()})}).catch(()=>e()))},[r,e]),g=x.useCallback((_,A)=>{r(O=>O.map(B=>B.filename!==_||!B.workspace?B:{...B,docCount:Math.max(0,B.docCount-1),workspace:{...B.workspace,root:Qg(B.workspace.root,$=>$.type==="doc"&&$.file===A)}})),fetch(`/api/workspaces/${encodeURIComponent(_)}/docs/${encodeURIComponent(A)}`,{method:"DELETE"}).catch(()=>e())},[r,e]),v=x.useCallback((_,A,O=!1)=>{r($=>$.map(W=>W.filename!==_||!W.workspace?W:{...W,workspace:{...W.workspace,root:Qg(W.workspace.root,J=>J.type==="container"&&J.id===A)}}));const B=`/api/workspaces/${encodeURIComponent(_)}/containers/${encodeURIComponent(A)}${O?"?cascade=true":""}`;fetch(B,{method:"DELETE"}).then(()=>{O&&t()}).catch(()=>e())},[r,e,t]),b=x.useCallback((_,A,O)=>{O.trim()&&(r(B=>B.map($=>$.filename!==_||!$.workspace?$:{...$,workspace:{...$.workspace,root:NT($.workspace.root,A,O.trim())}})),fetch(`/api/workspaces/${encodeURIComponent(_)}/containers/${encodeURIComponent(A)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:O.trim()})}).catch(()=>e()))},[r,e]),k=x.useCallback(()=>{fetch("/api/workspaces",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:"Untitled Workspace"})}).catch(()=>{})},[]),w=x.useCallback((_,A,O)=>{fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(O?{metadata:O}:{})}).then(B=>B.json()).then(B=>{if(B.filename)return fetch(`/api/workspaces/${encodeURIComponent(_)}/docs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:B.filename,title:B.title||"Untitled",containerId:A})})}).catch(()=>{})},[]),S=x.useCallback((_,A)=>{fetch(`/api/workspaces/${encodeURIComponent(_)}/containers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:"Untitled",parentContainerId:A})}).catch(()=>{})},[]),N=x.useCallback(_=>{const A=s.find(O=>O.filename===_);return(A==null?void 0:A.tags)??[]},[s]),T=x.useCallback((_,A)=>{const O=A.trim();O&&(n(B=>B.map($=>{if($.filename!==_)return $;const W=$.tags??[];return W.includes(O)?$:{...$,tags:[...W,O]}})),fetch(`/api/doc-tags/${encodeURIComponent(_)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tag:O})}).catch(()=>{}))},[n]),M=x.useCallback((_,A)=>{n(O=>O.map(B=>{if(B.filename!==_)return B;const $=B.tags??[],W=$.filter(J=>J!==A);return W.length===$.length?B:W.length>0?{...B,tags:W}:{...B,tags:void 0}})),fetch(`/api/doc-tags/${encodeURIComponent(_)}/${encodeURIComponent(A)}`,{method:"DELETE"}).catch(()=>{})},[n]);return{fetchDocs:t,handleDelete:o,handleArchive:l,handleUnarchive:d,handleRename:f,handleCreateWorkspace:k,handleDeleteWorkspace:h,handleCreateInWorkspace:w,handleRemoveFromWorkspace:g,handleCreateContainer:S,handleDeleteContainer:v,handleRenameContainer:b,handleRenameWorkspace:m,getDocTags:N,handleAddTag:T,handleRemoveTag:M}}function CT({docs:t,workspaces:e,assignedFiles:n,scrollRef:r,setCollapsedSections:s}){const[i,o]=x.useState(null),[l,d]=x.useState(null),f=x.useRef(null),h=x.useRef(null),m=x.useRef(null),g=x.useRef(null),v=x.useRef(null),b=5,k=(W,J,z)=>z==="before"?J>0?vu(W[J-1]):null:vu(W[J]),w=x.useCallback((W,J)=>{if(J===null){const D=t.filter(q=>!n.has(q.filename)).map(q=>({type:"doc",file:q.filename,title:q.title})),U=D.findIndex(q=>vu(q)===W);return U>=0?{siblings:D,index:U,containerId:null}:null}const z=e.find(D=>D.filename===J);if(!(z!=null&&z.workspace))return null;const G=(D,U)=>{for(let q=0;q<D.length;q++){if(vu(D[q])===W)return{siblings:D,index:q,containerId:U};if(D[q].type==="container"){const se=G(D[q].items,D[q].id);if(se)return se}}return null};return G(z.workspace.root,null)},[t,n,e]),S=x.useCallback(()=>{o(null),d(null),v.current=null,g.current=null,m.current&&(m.current.remove(),m.current=null),f.current&&(clearTimeout(f.current),f.current=null),h.current&&(cancelAnimationFrame(h.current),h.current=null),document.body.style.userSelect=""},[]),N=x.useCallback((W,J)=>{if(!W||!J)return;if(W.type==="workspace"){const V=J.itemId;if(V===W.filename)return;const re=e.map(L=>L.filename),K=re.indexOf(W.filename);if(K<0)return;re.splice(K,1);let j=re.indexOf(V);if(j<0)return;J.position==="after"&&(j+=1),re.splice(j,0,W.filename),fetch("/api/workspaces/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:re})}).catch(()=>{});return}const{wsFilename:z,containerId:G,afterId:D}=J,U=W.type==="doc"?W.file:W.id,q=W.sourceWs;if(J.itemId===U)return;if(W.type==="container"){if(z===null&&G===null&&J.itemId!=="__section__"){const V=J.itemId,re=J.position==="after"?V:(()=>{const K=e.findIndex(j=>j.filename===V);return K>0?e[K-1].filename:null})();fetch("/api/workspaces/promote-container",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,containerId:U,afterWorkspaceFilename:re})}).catch(()=>{});return}if(q!==z&&z){fetch(`/api/workspaces/${encodeURIComponent(z)}/containers/${encodeURIComponent(U)}/cross-move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,targetContainerId:G??null,afterIdentifier:D})}).catch(()=>{});return}if(!z)return;fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(U)}/move`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetContainerId:G??null,afterFile:D})}).catch(()=>{});return}const se=W.file;if(q===null&&z===null){const V=t.filter(ee=>!n.has(ee.filename)).map(ee=>ee.filename),re=V.indexOf(se);if(re<0)return;V.splice(re,1);let K=D?V.indexOf(D):-1;K>=0?K+=1:K=0,V.splice(K,0,se);const j=[];let L=0;for(const ee of t)n.has(ee.filename)?j.push(ee.filename):j.push(V[L++]);fetch("/api/documents/reorder",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:j})}).catch(()=>{});return}if(q===null&&z!==null){fetch(`/api/workspaces/${encodeURIComponent(z)}/docs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file:se,title:se.replace(/\.md$/,""),containerId:G??null,afterFile:D})}).catch(()=>{});return}if(q!==null&&z===null){fetch(`/api/workspaces/${encodeURIComponent(q)}/docs/${encodeURIComponent(se)}`,{method:"DELETE"}).catch(()=>{});return}if(q===z&&z!==null){fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(se)}/move`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetContainerId:G??null,afterFile:D})}).catch(()=>{});return}q!==null&&z!==null&&fetch(`/api/workspaces/${encodeURIComponent(z)}/docs/${encodeURIComponent(se)}/cross-move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceWorkspace:q,containerId:G??null,afterFile:D,title:se.replace(/\.md$/,"")})}).catch(()=>{})},[e,t,n]),T=x.useCallback((W,J)=>{const z=m.current;z&&(z.style.display="none");const G=document.elementFromPoint(W,J);if(z&&(z.style.display=""),!G)return null;if((i==null?void 0:i.type)==="workspace"||(i==null?void 0:i.type)==="container"){const ee=G.closest("[data-ws-drag]");if(ee){const he=ee.dataset.wsDrag,ge=ee.getBoundingClientRect(),oe=(J-ge.top)/ge.height;return{itemId:he,position:oe<.5?"before":"after",wsFilename:null,containerId:null,afterId:null}}if((i==null?void 0:i.type)==="workspace")return null}if((i==null?void 0:i.type)==="doc"){const ee=G.closest("[data-ws-drag]");if(ee)return{itemId:"__section__",position:"inside",wsFilename:ee.dataset.wsDrag,containerId:null,afterId:null}}const D=G.closest("[data-drag-id]");if(!D){const ee=G.closest("[data-drop-ws]");return ee?{itemId:"__section__",position:"inside",wsFilename:ee.dataset.dropWs==="__docs__"?null:ee.dataset.dropWs,containerId:ee.dataset.dropContainer||null,afterId:null}:null}const U=D.dataset.dragId,q=D.dataset.dragType,se=D.dataset.dragWs==="__docs__"?null:D.dataset.dragWs,V=D.getBoundingClientRect(),re=(J-V.top)/V.height;if(q==="container-header"){const ee=U,he=D.dataset.dragParent||null,ge=w(ee,se);if(!ge)return null;const oe=(i==null?void 0:i.type)==="container"?.33:.25;return re<oe?{itemId:ee,position:"before",wsFilename:se,containerId:he,afterId:k(ge.siblings,ge.index,"before")}:re>1-oe?{itemId:ee,position:"after",wsFilename:se,containerId:he,afterId:k(ge.siblings,ge.index,"after")}:{itemId:ee,position:"inside",wsFilename:se,containerId:ee,afterId:null}}const K=D.dataset.dragContainer||null,j=w(U,se);if(!j)return null;const L=re<.5?"before":"after";return{itemId:U,position:L,wsFilename:se,containerId:K,afterId:k(j.siblings,j.index,L)}},[w,i]),M=x.useCallback(W=>{const J=r.current;if(!J)return;const z=J.getBoundingClientRect(),G=80,D=18;let U=0;if(W<z.top+G?U=-D*Math.max(0,1-(W-z.top)/G):W>z.bottom-G&&(U=D*Math.max(0,1-(z.bottom-W)/G)),h.current&&(cancelAnimationFrame(h.current),h.current=null),U!==0){const q=()=>{J.scrollTop+=U,h.current=requestAnimationFrame(q)};h.current=requestAnimationFrame(q)}},[r]),_=x.useCallback((W,J)=>{const z=m.current;z&&(z.style.display="none");const G=document.elementFromPoint(W,J);z&&(z.style.display="");const D=G==null?void 0:G.closest("[data-section-key]");if(!D){f.current&&(clearTimeout(f.current),f.current=null);return}const U=D.dataset.sectionKey;f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{s(q=>{if(!q.has(U))return q;const se=new Set(q);return se.delete(U),se})},500)},[s]);x.useEffect(()=>{if(!i)return;const W=z=>{m.current&&(m.current.style.left=`${z.clientX+12}px`,m.current.style.top=`${z.clientY-8}px`),d(T(z.clientX,z.clientY)),M(z.clientY),_(z.clientX,z.clientY)},J=z=>{N(i,T(z.clientX,z.clientY)),S()};return window.addEventListener("pointermove",W),window.addEventListener("pointerup",J),()=>{window.removeEventListener("pointermove",W),window.removeEventListener("pointerup",J)}},[i,T,N,S,M,_]);const A=x.useCallback((W,J,z)=>{if(W.button!==0||W.target.closest("input, button, .sidebar-tag-remove, .sidebar-tag-add, .sidebar-container-actions, .sidebar-delete-btn, .sidebar-confirm-delete, .sidebar-inline-confirm"))return;g.current={x:W.clientX,y:W.clientY},v.current=J;const D=q=>{if(!g.current||!v.current)return;const se=q.clientX-g.current.x,V=q.clientY-g.current.y;if(Math.abs(se)+Math.abs(V)>=b){document.body.style.userSelect="none",window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",U),o(v.current),v.current=null;const re=document.createElement("div");re.style.cssText="position:fixed;pointer-events:none;z-index:9999;padding:4px 10px;background:var(--bg-surface, white);border:1px solid var(--border, #cbd5e1);border-radius:6px;font-size:12px;box-shadow:0 2px 8px rgba(0,0,0,0.12);max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--ink-dark, #334155);",re.textContent=z,document.body.appendChild(re),m.current=re,re.style.left=`${q.clientX+12}px`,re.style.top=`${q.clientY-8}px`}},U=()=>{window.removeEventListener("pointermove",D),window.removeEventListener("pointerup",U),g.current=null,v.current=null,document.body.style.userSelect=""};window.addEventListener("pointermove",D),window.addEventListener("pointerup",U)},[]);return{draggedItem:i,dropIndicator:l,handlePointerDown:A,dropClass:W=>!l||l.itemId!==W?"":l.position==="before"?"drop-before":l.position==="after"?"drop-after":l.position==="inside"?"drop-inside":"",isDragging:W=>i?i.type==="doc"?i.file===W:i.type==="workspace"?i.filename===W:i.id===W:!1,isContainerDropTarget:W=>!l||!i?!1:l.containerId===W}}const c8=[{key:"document",label:"Document"},{key:"tweet",label:"Tweet"},{key:"article",label:"Article"},{key:"linkedin",label:"LinkedIn"},{key:"newsletter",label:"Newsletter"},{key:"blog",label:"Blog"}];function u8({onPick:t}){const[e,n]=x.useState(!1),r=x.useRef(null),s=x.useRef(null),[i,o]=x.useState({});return x.useLayoutEffect(()=>{if(!e||!r.current||!s.current)return;const l=s.current.getBoundingClientRect(),d=r.current.getBoundingClientRect(),f=8;let h=l.right-4,m=l.top-4;h+d.width+f>window.innerWidth&&(h=l.left-d.width+4),m+d.height+f>window.innerHeight&&(m=window.innerHeight-d.height-f),m<f&&(m=f),o({position:"fixed",left:h,top:m})},[e]),c.jsxs("span",{onMouseLeave:()=>n(!1),children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{ref:s,className:"context-menu-item context-menu-submenu-trigger",onMouseEnter:()=>n(!0),onClick:()=>n(l=>!l),children:[c.jsx("span",{children:"Create variant"}),c.jsx("span",{className:"context-menu-submenu-arrow",children:"▸"})]}),e&&c.jsx("div",{ref:r,className:"context-menu context-menu-submenu",style:i,children:c8.map(l=>c.jsx("button",{className:"context-menu-item",onClick:()=>t(l.key),children:c.jsx("span",{children:l.label})},l.key))})]})}function d8({items:t,onAction:e}){const[n,r]=x.useState(null),s=x.useRef(null),i=x.useRef({}),o=x.useMemo(()=>{const h=new Map;for(const m of t){const g=m.pluginDisplayName||"_ungrouped",v=h.get(g)||[];v.push(m),h.set(g,v)}return h},[t]),[l,d]=x.useState({});x.useLayoutEffect(()=>{const h=n?i.current[n]:null;if(!n||!s.current||!h)return;const m=h.getBoundingClientRect(),g=s.current.getBoundingClientRect(),v=8;let b=m.right-4,k=m.top-4;b+g.width+v>window.innerWidth&&(b=m.left-g.width+4),k+g.height+v>window.innerHeight&&(k=window.innerHeight-g.height-v),k<v&&(k=v),d({position:"fixed",left:b,top:k})},[n]);const f=[];for(const[h,m]of o)if(h!=="_ungrouped"&&m.length>=3)f.push(c.jsxs("span",{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("button",{ref:g=>{i.current[h]=g},className:"context-menu-item context-menu-submenu-trigger",onMouseEnter:()=>r(h),onClick:()=>r(n===h?null:h),children:[c.jsx("span",{children:"Transform"}),c.jsx("span",{className:"context-menu-submenu-arrow",children:"▸"})]}),n===h&&c.jsx("div",{ref:s,className:"context-menu context-menu-submenu",style:l,onMouseLeave:()=>r(null),children:m.map(g=>c.jsx("button",{className:"context-menu-item",onClick:()=>e(g),children:c.jsx("span",{children:g.label})},g.action))})]},`sub-${h}`));else{let g=!0;for(const v of m){const b=g&&h!=="_ungrouped";g=!1,f.push(c.jsxs("span",{children:[b&&c.jsx("div",{className:"context-menu-divider"}),b&&c.jsx("div",{className:"context-menu-section-header",children:h}),c.jsx("button",{className:"context-menu-item",onClick:()=>e(v),children:c.jsx("span",{children:v.label})})]},v.action))}}return c.jsx(c.Fragment,{children:f})}function Rd({x:t,y:e,filename:n,title:r,onClose:s,onDuplicate:i,onCreateVariant:o,onRename:l,onArchive:d,onDelete:f,onPluginAction:h,pluginItems:m,onSchedulePost:g,onPostNow:v,isAlreadyPublished:b,onViewAnalytics:k,viewAnalyticsLabel:w,onMarkSent:S,isAlreadySent:N,isApproved:T,onToggleApprove:M,isAutoAccept:_,onToggleAutoAccept:A,sortState:O,sortProposalLabel:B,sortProposalReasoning:$,onRequestSort:W,onCancelSort:J,onAcceptSortProposal:z,onRejectSortProposal:G,folderMode:D,onNewDoc:U,onNewContainer:q,onAcceptAll:se,onRejectAll:V,folderAutoAccept:re,onToggleFolderAutoAccept:K,folderAutoAcceptLabel:j,onRequestSortAll:L,folderDocCount:ee,onDeleteWithDocs:he,bulkCount:ge,onBulkDelete:oe,onBulkRequestSort:xe}){const we=x.useRef(null),[We,He]=x.useState(!1),[Ze,Oe]=x.useState(!1),[Ke,mt]=x.useState({left:t,top:e});x.useLayoutEffect(()=>{const pe=we.current;if(!pe)return;const gt=pe.getBoundingClientRect(),ft=8;let at=t,nt=e;e+gt.height+ft>window.innerHeight&&(nt=e-gt.height),t+gt.width+ft>window.innerWidth&&(at=t-gt.width),nt<ft&&(nt=ft),at<ft&&(at=ft),mt({left:at,top:nt})},[t,e]),x.useEffect(()=>{const pe=gt=>{we.current&&!we.current.contains(gt.target)&&s()};return document.addEventListener("mousedown",pe),()=>document.removeEventListener("mousedown",pe)},[s]),x.useEffect(()=>{const pe=gt=>{gt.key==="Escape"&&s()};return document.addEventListener("keydown",pe),()=>document.removeEventListener("keydown",pe)},[s]);const Ye=x.useCallback(pe=>{h(pe.action,pe),s()},[h,s]);return ge&&ge>1&&oe?c.jsxs("div",{ref:we,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsxs("div",{className:"context-menu-section-header",children:[ge," selected"]}),xe&&c.jsx("button",{className:"context-menu-item",onClick:()=>{xe(),s()},children:c.jsxs("span",{children:["Request sort (",ge,")"]})}),We?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsxs("span",{children:["Delete ",ge,"?"]}),c.jsx("button",{onClick:()=>{oe(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsxs("span",{children:["Delete (",ge,")"]})})]}):D?c.jsxs("div",{ref:we,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsx("button",{className:"context-menu-item",onClick:()=>{l(),s()},children:c.jsx("span",{children:"Rename"})}),U&&c.jsx("button",{className:"context-menu-item",onClick:pe=>{U(pe),s()},children:c.jsx("span",{children:"New Document"})}),q&&c.jsx("button",{className:"context-menu-item",onClick:()=>{q(),s()},children:c.jsx("span",{children:"New Container"})}),(se||V)&&c.jsx("div",{className:"context-menu-divider"}),se&&c.jsx("button",{className:"context-menu-item",onClick:()=>{se(),s()},children:c.jsx("span",{children:"Accept All Changes"})}),V&&c.jsx("button",{className:"context-menu-item",onClick:()=>{V(),s()},children:c.jsx("span",{children:"Reject All Changes"})}),K&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{K(),s()},children:c.jsx("span",{children:re?`Turn off auto-accept${j?" "+j:""}`:`Turn on auto-accept${j?" "+j:""}`})})]}),L&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{L(),s()},children:c.jsx("span",{children:"Request sort all"})})]}),c.jsx("div",{className:"context-menu-divider"}),We?ee&&ee>0&&he?c.jsxs("div",{className:"sidebar-ctx-folder-delete",onClick:pe=>pe.stopPropagation(),children:[c.jsx("div",{className:"sidebar-ctx-folder-delete-prompt",children:"Delete this folder?"}),c.jsxs("button",{className:"context-menu-item sidebar-ctx-delete-option",onClick:()=>{f(),s()},children:[c.jsx("span",{children:"Folder only"}),c.jsxs("span",{className:"sidebar-ctx-delete-hint",children:[ee," doc",ee===1?"":"s"," → Documents"]})]}),c.jsxs("button",{className:"context-menu-item sidebar-ctx-delete-option sidebar-ctx-delete",onClick:()=>{he(),s()},children:[c.jsxs("span",{children:["Folder + ",ee," doc",ee===1?"":"s"]}),c.jsx("span",{className:"sidebar-ctx-delete-hint",children:"permanently deletes files"})]}),c.jsx("button",{className:"context-menu-item sidebar-ctx-delete-cancel",onClick:()=>He(!1),children:c.jsx("span",{children:"Cancel"})})]}):c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:"Delete?"}),c.jsx("button",{onClick:()=>{f(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsx("span",{children:"Delete"})})]}):c.jsxs("div",{ref:we,className:"context-menu",style:{left:Ke.left,top:Ke.top},children:[c.jsx("button",{className:"context-menu-item",onClick:()=>{i(),s()},children:c.jsx("span",{children:"Duplicate"})}),o&&c.jsx(u8,{onPick:pe=>{o(pe),s()}}),c.jsx("button",{className:"context-menu-item",onClick:()=>{l(),s()},children:c.jsx("span",{children:"Rename"})}),Ze?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:"Archive?"}),c.jsx("button",{onClick:()=>{d(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>Oe(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item",onClick:()=>Oe(!0),children:c.jsx("span",{children:"Archive"})}),We?c.jsxs("div",{className:"context-menu-item sidebar-ctx-confirm",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{children:Ls(n)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{f(),s()},children:"Yes"}),c.jsx("button",{onClick:()=>He(!1),children:"No"})]}):c.jsx("button",{className:"context-menu-item sidebar-ctx-delete",onClick:()=>He(!0),children:c.jsx("span",{children:Ls(n)?"Remove":"Delete"})}),M&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{M(),s()},children:c.jsx("span",{children:T?"Remove Approval":"Approve"})})]}),A&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{A(),s()},children:c.jsx("span",{children:_?"Turn off auto-accept":"Turn on auto-accept"})})]}),O==="proposal"&&z&&G&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("div",{className:"sidebar-ctx-sort-proposal",onClick:pe=>pe.stopPropagation(),children:[c.jsxs("div",{className:"sidebar-ctx-sort-proposal-label",children:["Sort to ",B]}),$&&c.jsx("div",{className:"sidebar-ctx-sort-proposal-reason",children:$}),c.jsxs("div",{className:"sidebar-ctx-sort-proposal-actions",children:[c.jsx("button",{onClick:()=>{z(),s()},children:"Accept"}),c.jsx("button",{onClick:()=>{G(),s()},children:"Reject"})]})]})]}),O==="pending"&&J&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsxs("div",{className:"sidebar-ctx-sort-pending",onClick:pe=>pe.stopPropagation(),children:[c.jsx("span",{className:"sidebar-ctx-sort-pending-label",children:"Sort requested"}),c.jsx("button",{onClick:()=>{J(),s()},children:"Cancel"})]})]}),O==="none"&&W&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{W(),s()},children:c.jsx("span",{children:"Request sort"})})]}),g&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{g(),s()},children:c.jsx("span",{children:"Schedule Post"})})]}),v&&c.jsx("button",{className:"context-menu-item",onClick:()=>{v(),s()},children:c.jsx("span",{children:b?"Republish to Blog":"Post to Blog Now"})}),S&&!N&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{S(),s()},children:c.jsx("span",{children:"Mark as Sent"})})]}),k&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"context-menu-divider"}),c.jsx("button",{className:"context-menu-item",onClick:()=>{k(),s()},children:c.jsx("span",{children:w||"View Analytics"})})]}),m.length>0&&c.jsx(d8,{items:m,onAction:Ye})]})}const xk=5e3;function _T(t,e){return!t.promptForFocus||!e?!1:e.wordCount>xk?(kT(`Document too large to transform: ${e.wordCount.toLocaleString()} words (max ${xk.toLocaleString()}). Trim it down first.`,"error"),!0):!1}function TT({actionLabel:t,docTitle:e,onConfirm:n,onClose:r}){const[s,i]=x.useState(""),o=x.useRef(null);x.useEffect(()=>{var d;(d=o.current)==null||d.focus()},[]),x.useEffect(()=>{const d=f=>{f.key==="Escape"&&r()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[r]);const l=x.useCallback(()=>{n(s.trim())},[s,n]);return c.jsx("div",{className:"focus-modal-overlay",onClick:r,children:c.jsxs("div",{className:"focus-modal",onClick:d=>d.stopPropagation(),children:[c.jsxs("div",{className:"focus-modal-header",children:[c.jsx("h2",{children:t}),c.jsx("button",{className:"focus-modal-close",onClick:r,children:"×"})]}),c.jsxs("div",{className:"focus-modal-body",children:[c.jsxs("label",{children:['Focus instructions for "',e,'"',c.jsx("textarea",{ref:o,value:s,onChange:d=>i(d.target.value.slice(0,500)),placeholder:"Optional: guide the transformation (e.g. 'focus on the intro section', 'keep it professional')...",onKeyDown:d=>{d.key==="Enter"&&(d.ctrlKey||d.metaKey)&&l()}})]}),c.jsxs("div",{className:"focus-modal-hint",children:[s.length,"/500"]}),c.jsxs("div",{className:"focus-modal-actions",children:[c.jsx("button",{className:"focus-modal-btn secondary",onClick:r,children:"Cancel"}),c.jsx("button",{className:"focus-modal-btn primary",onClick:l,children:"Go"})]})]})]})})}function Ap(t,e){if(!e)return[t];const n=[],r=t.toLowerCase(),s=e.toLowerCase();let i=0;for(;i<t.length;){const o=r.indexOf(s,i);if(o===-1){n.push(t.slice(i));break}o>i&&n.push(t.slice(i,o)),n.push(c.jsx("mark",{children:t.slice(o,o+e.length)},o)),i=o+e.length}return n}function wk({r:t,query:e,onClick:n}){return c.jsxs("div",{className:`sidebar-item search-result-item ${t.isActive?"active":""} ${t.isArchived?"search-result-archived":""}`,onClick:n,children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-item-title-text",children:t.matchType==="title"?Ap(t.title,e):t.title}),t.isArchived&&c.jsx("span",{className:"search-archived-badge",children:"archived"})]}),t.matchType==="tag"&&t.matchedTag&&c.jsxs("div",{className:"search-result-tag",children:["Tag: ",Ap(t.matchedTag,e)]}),t.matchType==="content"&&t.snippet&&c.jsx("div",{className:"search-result-snippet",children:Ap(t.snippet,e)}),c.jsxs("div",{className:"sidebar-item-meta",children:[t.wordCount.toLocaleString()," words · ",ua(t.lastModified)]})]})}function Qd({results:t,query:e,onSwitchDocument:n,actions:r}){if(t.length===0)return c.jsx("div",{className:"sidebar-scroll",children:c.jsxs("div",{className:"search-empty",children:['No results for "',e,'"']})});const s=t.filter(o=>!o.isArchived),i=t.filter(o=>o.isArchived);return c.jsx("div",{className:"sidebar-scroll",children:c.jsxs("div",{className:"search-results",children:[s.map(o=>c.jsx(wk,{r:o,query:e,onClick:()=>n(o.filename)},o.filename)),i.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"search-archived-divider",children:c.jsx("span",{children:"Archived"})}),i.map(o=>c.jsx(wk,{r:o,query:e,onClick:()=>r.handleUnarchive(o.filename)},o.filename))]})]})})}async function Rp(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();return(i=(s=r.content)==null?void 0:s[0])!=null&&i.text?JSON.parse(r.content[0].text):r}function Op(t,e){return e?(t/e*100).toFixed(1)+"%":"0%"}function kk(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function Sk(t,e=50){try{const n=new URL(t),r=n.hostname+n.pathname+n.search;return r.length>e?r.slice(0,e)+"...":r}catch{return t.length>e?t.slice(0,e)+"...":t}}function MT({docId:t,title:e,onClose:n}){const[r,s]=x.useState("loading"),[i,o]=x.useState([]),[l,d]=x.useState(""),[f,h]=x.useState(null),[m,g]=x.useState(null),[v,b]=x.useState("links"),[k,w]=x.useState("all"),[S,N]=x.useState(!1),[T,M]=x.useState(!1),[_,A]=x.useState(""),[O,B]=x.useState(!1),[$,W]=x.useState(null),J=x.useRef(null);x.useEffect(()=>{let oe=!1;return(async()=>{try{const xe=await Rp("list_newsletter_issues",{limit:20});if(oe)return;if(!xe.issues||xe.issues.length===0){s("no-data");return}o(xe.issues);const we=xe.issues[0].id;d(we)}catch(xe){oe||(g(xe.message),s("error"))}})(),()=>{oe=!0}},[]),x.useEffect(()=>{if(!l)return;let oe=!1;return N(!0),M(!1),W(null),A(""),(async()=>{try{const xe=await Rp("get_newsletter_analytics",{issue_id:l});if(oe)return;if(xe.error){g(xe.error),s("error");return}h(xe),s("loaded")}catch(xe){oe||(g(xe.message),s("error"))}finally{oe||N(!1)}})(),()=>{oe=!0}},[l]),x.useEffect(()=>{const oe=xe=>{J.current&&!J.current.contains(xe.target)&&n()};return document.addEventListener("mousedown",oe),()=>document.removeEventListener("mousedown",oe)},[n]),x.useEffect(()=>{const oe=xe=>{xe.key==="Escape"&&n()};return document.addEventListener("keydown",oe),()=>document.removeEventListener("keydown",oe)},[n]);const z=f?h8(f.subscriber_events):[],G=(f==null?void 0:f.issue.recipient_count)??0,D=f?f.stats.delivered||G-f.stats.bounces:0,U=f?new Set(f.subscriber_events.filter(oe=>{var xe;return oe.event_type==="click"&&((xe=oe.url)==null?void 0:xe.includes("/newsletter/unsubscribe/"))}).map(oe=>oe.email)).size:0,q=f?f.stats.unsubscribes||U:0,se=f?f.subscriber_events.filter(oe=>oe.event_type==="dropped").length:0,V=f?Math.max(0,G-f.stats.unique_opens):0,re=f!=null&&f.issue.sent_at?Date.now()-new Date(f.issue.sent_at).getTime():0,K=Math.floor(re/36e5),j=!!(f!=null&&f.issue.resent_at||$),L=oe=>{const xe=Math.floor(oe/36e5);return xe<1?"just now":xe<24?`${xe}h ago`:`${Math.floor(xe/24)}d ${xe%24}h ago`},ee=async()=>{if(!(!_.trim()||O)){B(!0);try{const oe=await Rp("resend_to_unopened",{issue_id:l,subject:_});oe.error?(g(oe.error),s("error")):(W({sent:oe.sent,failed:oe.failed}),M(!1))}catch(oe){g(oe.message),s("error")}finally{B(!1)}}},he=oe=>{var xe;return oe.event_type==="unsubscribe"||oe.event_type==="click"&&!!((xe=oe.url)!=null&&xe.includes("/newsletter/unsubscribe/"))},ge=f?f8(f.subscriber_events.filter(oe=>k==="all"?!0:k==="unsubscribe"?he(oe):oe.event_type===k)):[];return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"na-modal",ref:J,children:[c.jsxs("div",{className:"na-header",children:[c.jsx("h3",{children:"Newsletter Analytics"}),c.jsx("button",{className:"newsletter-modal__close",onClick:n,children:"×"})]}),r==="loading"&&!f&&c.jsx("div",{className:"na-body",children:c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:"Loading analytics..."})]})}),r==="no-data"&&c.jsxs("div",{className:"na-body",children:[c.jsx("div",{className:"newsletter-modal__status",children:c.jsx("span",{children:"No newsletter sends found yet."})}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:n,children:"Done"})})]}),r==="error"&&c.jsxs("div",{className:"na-body",children:[c.jsx("div",{className:"newsletter-modal__error",children:m}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:n,children:"Done"})})]}),r==="loaded"&&f&&c.jsxs("div",{className:"na-body",children:[i.length>1&&c.jsx("select",{className:"newsletter-modal__select na-issue-select",value:l,onChange:oe=>d(oe.target.value),children:i.map(oe=>c.jsxs("option",{value:oe.id,children:[oe.subject," — ",kk(oe.sent_at)]},oe.id))}),S?c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:"Loading..."})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"na-kpi-row",children:[c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:D.toLocaleString()}),c.jsx("div",{className:"na-kpi__label",children:"Delivered"}),c.jsxs("div",{className:"na-kpi__sub",children:[G.toLocaleString()," sent"]})]}),c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:Op(f.stats.unique_opens,D)}),c.jsx("div",{className:"na-kpi__label",children:"Open rate"}),c.jsxs("div",{className:"na-kpi__sub",children:[f.stats.unique_opens.toLocaleString()," opens"]})]}),c.jsxs("div",{className:"na-kpi",children:[c.jsx("div",{className:"na-kpi__value",children:Op(f.stats.unique_clicks,D)}),c.jsx("div",{className:"na-kpi__label",children:"Click rate"}),c.jsxs("div",{className:"na-kpi__sub",children:[f.stats.unique_clicks.toLocaleString()," clicks"]})]})]}),c.jsxs("div",{className:"na-kpi-row na-kpi-row--secondary",children:[c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:f.stats.bounces}),c.jsx("span",{className:"na-kpi__label--sm",children:"Bounces"})]}),c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:q}),c.jsx("span",{className:"na-kpi__label--sm",children:"Unsubs"})]}),c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:se}),c.jsx("span",{className:"na-kpi__label--sm",children:"Dropped"})]}),f.stats.complaints>0&&c.jsxs("div",{className:"na-kpi na-kpi--sm",children:[c.jsx("span",{className:"na-kpi__value--sm",children:f.stats.complaints}),c.jsx("span",{className:"na-kpi__label--sm",children:"Spam"})]})]}),V>0&&!j&&c.jsx("div",{className:"na-resend",children:T?c.jsxs("div",{className:"na-resend-panel",children:[c.jsxs("div",{className:"na-resend-label-row",children:[c.jsx("span",{className:"na-resend-label",children:"New subject line"}),c.jsxs("span",{className:"na-resend-meta",children:["sent ",L(re),K<48?" · consider waiting 48h":""]})]}),c.jsx("input",{className:"na-resend-input",type:"text",value:_,onChange:oe=>A(oe.target.value),placeholder:"Try a different angle"}),c.jsxs("div",{className:"na-resend-actions",children:[c.jsx("button",{className:"na-resend-cancel",onClick:()=>M(!1),children:"Cancel"}),c.jsx("button",{className:"na-resend-send",onClick:ee,disabled:O||!_.trim(),children:O?"Sending...":`Send to ${V.toLocaleString()}`})]})]}):c.jsxs("button",{className:"na-resend-toggle",onClick:()=>{M(!0),A(f.issue.subject)},children:["Resend to ",V.toLocaleString()," non-openers ",c.jsx("span",{style:{float:"right"},children:"›"})]})}),j&&c.jsxs("div",{className:"na-resend-done",children:["Resent ",f.issue.resent_at?L(Date.now()-new Date(f.issue.resent_at).getTime()):"just now",$?` — ${$.sent} sent`:"",f.issue.resend_subject?` — "${f.issue.resend_subject}"`:""]}),c.jsxs("div",{className:"na-tabs",children:[c.jsxs("button",{className:`na-tab${v==="links"?" active":""}`,onClick:()=>b("links"),children:["Links (",z.length,")"]}),c.jsxs("button",{className:`na-tab${v==="activity"?" active":""}`,onClick:()=>b("activity"),children:["Activity (",f.subscriber_events.length,")"]})]}),v==="links"&&c.jsx("div",{className:"na-table-wrap",children:z.length===0?c.jsx("div",{className:"na-empty",children:"No link clicks recorded yet."}):c.jsxs("table",{className:"na-table",children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Link"}),c.jsx("th",{children:"Unique"}),c.jsx("th",{children:"Total"}),c.jsx("th",{children:"CTR"})]})}),c.jsx("tbody",{children:z.map(oe=>c.jsxs("tr",{children:[c.jsx("td",{className:"na-table__url",title:oe.url,children:c.jsx("a",{href:oe.url,target:"_blank",rel:"noopener noreferrer",children:Sk(oe.url)})}),c.jsx("td",{children:oe.uniqueClicks}),c.jsx("td",{children:oe.totalClicks}),c.jsx("td",{children:Op(oe.uniqueClicks,D)})]},oe.url))})]})}),v==="activity"&&c.jsxs("div",{className:"na-activity",children:[c.jsx("div",{className:"na-filter-row",children:["all","open","click","bounce","dropped","unsubscribe"].map(oe=>c.jsx("button",{className:`na-filter-btn${k===oe?" active":""}`,onClick:()=>w(oe),children:oe==="all"?"All":oe.charAt(0).toUpperCase()+oe.slice(1)+"s"},oe))}),c.jsxs("div",{className:"na-table-wrap",children:[ge.length===0?c.jsxs("div",{className:"na-empty",children:["No ",k==="all"?"":k+" ","events recorded."]}):c.jsxs("table",{className:"na-table",children:[c.jsx("thead",{children:c.jsxs("tr",{children:[c.jsx("th",{children:"Email"}),c.jsx("th",{children:"Event"}),c.jsx("th",{children:"Detail"}),c.jsx("th",{children:"Time"})]})}),c.jsx("tbody",{children:ge.slice(0,100).map(oe=>c.jsxs("tr",{children:[c.jsx("td",{className:"na-table__email",children:oe.email}),c.jsxs("td",{children:[c.jsx("span",{className:`na-badge na-badge--${oe.event_type}`,children:oe.event_type}),oe.count>1&&c.jsxs("span",{className:"na-count",children:[oe.count,"x"]})]}),c.jsx("td",{className:"na-table__url",children:oe.url?c.jsx("a",{href:oe.url,target:"_blank",rel:"noopener noreferrer",children:Sk(oe.url,35)}):"—"}),c.jsx("td",{className:"na-table__time",children:kk(oe.latestTimestamp)})]},oe.key))})]}),ge.length>100&&c.jsxs("div",{className:"na-truncated",children:["Showing 100 of ",ge.length," events"]})]})]})]})]})]})})}function f8(t){const e=new Map;for(const n of t){const r=`${n.email}|${n.event_type}|${n.url||""}`,s=e.get(r);s?(s.count++,n.timestamp>s.latestTimestamp&&(s.latestTimestamp=n.timestamp)):e.set(r,{key:r,email:n.email,event_type:n.event_type,url:n.url,latestTimestamp:n.timestamp,count:1})}return Array.from(e.values()).sort((n,r)=>new Date(r.latestTimestamp).getTime()-new Date(n.latestTimestamp).getTime())}function h8(t){const e=t.filter(r=>r.event_type==="click"&&r.url),n=new Map;for(const r of e){const s=r.url;let i=n.get(s);i||(i={emails:new Set,total:0},n.set(s,i)),i.emails.add(r.email),i.total++}return Array.from(n.entries()).map(([r,{emails:s,total:i}])=>({url:r,uniqueClicks:s.size,totalClicks:i})).sort((r,s)=>s.uniqueClicks-r.uniqueClicks)}function p8(t){return t.tweetContext?"tweet":t.articleContext?"article":t.linkedinContext?"linkedin":t.newsletterContext?"newsletter":t.blogContext?"blog":"tweet"}function Pl({filename:t,title:e,onClose:n}){const[r,s]=x.useState("queue"),[i,o]=x.useState(null),[l,d]=x.useState(null),[f,h]=x.useState(""),[m,g]=x.useState(!1),[v,b]=x.useState(null),[k,w]=x.useState(null);x.useEffect(()=>{fetch(`/api/documents/${encodeURIComponent(t)}/text`).then(T=>{if(!T.ok)throw new Error("Failed to load document");return T.json()}).then(T=>{d(T.text||""),o(p8(T.meta||{}))}).catch(T=>w(T.message))},[t]);const S=async()=>{var T;if(!(!l||!i)){g(!0);try{const M={content:l,content_type:i,mode:r};r==="custom"&&f&&(M.scheduled_at=new Date(f).toISOString());const _=await fetch("/api/scheduler/queue",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)}),A=await _.json();if(_.ok){const O=(T=A.item)!=null&&T.scheduled_at?new Date(A.item.scheduled_at).toLocaleString():"now";b({success:!0,message:`Scheduled for ${O}`})}else b({success:!1,message:A.error||"Failed to schedule"})}catch(M){b({success:!1,message:M.message})}finally{g(!1)}}},N=i===null&&!k;return c.jsx("div",{className:"schedule-post-overlay",onClick:n,children:c.jsxs("div",{className:"schedule-post-modal",onClick:T=>T.stopPropagation(),children:[c.jsxs("div",{className:"schedule-post-modal-header",children:[c.jsx("h3",{children:"Schedule Post"}),c.jsx("button",{className:"schedule-post-modal-close",onClick:n,children:"×"})]}),c.jsx("div",{className:"schedule-post-modal-doc",children:e}),k?c.jsxs("div",{className:"schedule-post-modal-result error",children:[k,c.jsx("button",{className:"schedule-post-modal-done",onClick:n,children:"Done"})]}):v?c.jsxs("div",{className:`schedule-post-modal-result ${v.success?"success":"error"}`,children:[v.message,c.jsx("button",{className:"schedule-post-modal-done",onClick:n,children:"Done"})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Content Type"}),c.jsx("div",{className:"schedule-post-modal-type",children:N?"...":i})]}),c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Mode"}),c.jsxs("div",{className:"schedule-post-modal-modes",children:[c.jsx("button",{className:`schedule-post-mode ${r==="queue"?"active":""}`,onClick:()=>s("queue"),children:"Queue Next"}),c.jsx("button",{className:`schedule-post-mode ${r==="now"?"active":""}`,onClick:()=>s("now"),children:"Post Now"}),c.jsx("button",{className:`schedule-post-mode ${r==="custom"?"active":""}`,onClick:()=>s("custom"),children:"Custom Time"})]})]}),r==="custom"&&c.jsxs("div",{className:"schedule-post-modal-field",children:[c.jsx("label",{children:"Date & Time"}),c.jsx("input",{type:"datetime-local",value:f,onChange:T=>h(T.target.value)})]}),c.jsxs("div",{className:"schedule-post-modal-actions",children:[c.jsx("button",{className:"schedule-post-modal-cancel",onClick:n,children:"Cancel"}),c.jsx("button",{className:"schedule-post-modal-submit",onClick:S,disabled:m||N||r==="custom"&&!f,children:m?"Scheduling...":r==="now"?"Post Now":"Schedule"})]})]})]})})}const Ek=[{key:"document",label:"Document"},{key:"tweet",label:"Tweet",metadata:{content_type:"tweet",tweetContext:{mode:"tweet"}}},{key:"reply",label:"Reply",needsUrl:!0,urlPlaceholder:"Paste tweet URL...",metadata:{content_type:"reply",tweetContext:{mode:"reply"}}},{key:"quote",label:"Quote Tweet",needsUrl:!0,urlPlaceholder:"Paste tweet URL...",metadata:{content_type:"quote",tweetContext:{mode:"quote"}}},{key:"article",label:"Article",metadata:{content_type:"article",articleContext:{active:!0}}},{key:"linkedin",label:"LinkedIn",metadata:{content_type:"linkedin",linkedinContext:{active:!0}}},{key:"newsletter",label:"Newsletter",metadata:{content_type:"newsletter",newsletterContext:{active:!0}}},{key:"blog",label:"Blog",metadata:{content_type:"blog",blogContext:{active:!0}}}];function jT({anchorRect:t,onSelect:e,onClose:n}){const r=x.useRef(null),[s,i]=x.useState(null),[o,l]=x.useState(""),d=x.useRef(null),[f,h]=x.useState({left:t.left,top:t.bottom+4});x.useLayoutEffect(()=>{const b=r.current;if(!b)return;const k=b.getBoundingClientRect(),w=8;let S=t.left,N=t.bottom+4;N+k.height+w>window.innerHeight&&(N=t.top-k.height-4),S+k.width+w>window.innerWidth&&(S=t.right-k.width),N<w&&(N=w),S<w&&(S=w),h({left:S,top:N})},[t]),x.useEffect(()=>{const b=k=>{r.current&&!r.current.contains(k.target)&&n()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[n]),x.useEffect(()=>{const b=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[n]),x.useEffect(()=>{s&&setTimeout(()=>{var b;return(b=d.current)==null?void 0:b.focus()},0)},[s]);const m=b=>{if(b.needsUrl){i(b.key),l("");return}e(b.metadata)},g=()=>{if(!s||!o.trim())return;const b=o.trim();if(!b.includes("x.com")&&!b.includes("twitter.com"))return;const k=Ek.find(S=>S.key===s);if(!(k!=null&&k.metadata))return;const w=JSON.parse(JSON.stringify(k.metadata));w.tweetContext&&(w.tweetContext.url=b),e(w)},v=o.trim().includes("x.com")||o.trim().includes("twitter.com");return c.jsx("div",{ref:r,className:"create-doc-dropdown",style:{left:f.left,top:f.top},children:Ek.map(b=>c.jsxs("div",{children:[c.jsx("button",{className:`create-doc-dropdown-item${s===b.key?" active":""}`,onClick:()=>m(b),children:b.label}),s===b.key&&c.jsxs("div",{className:"create-doc-dropdown-url",children:[c.jsx("input",{ref:d,type:"text",placeholder:b.urlPlaceholder,value:o,onChange:k=>l(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),g()),k.key==="Escape"&&(i(null),l(""))}}),c.jsx("button",{onClick:g,disabled:!v,children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})]},b.key))})}const m8=[{id:"full",label:"Full"},{id:"compact",label:"Compact"},{id:"minimal",label:"Minimal"}];function AT(t,e){for(const n of t){if(n.type==="doc"&&n.file===e)return[];if(n.type==="container"){const r=AT(n.items,e);if(r)return[n.id,...r]}}return null}function g8({docs:t,archivedDocs:e,workspaces:n,assignedFiles:r,pendingDocs:s,onSwitchDocument:i,onCreateDocument:o,actions:l,scrollRef:d,writingTitle:f,writingTarget:h,pendingWriteFilenames:m,searchQuery:g,searchResults:v,onSearchChange:b}){const k=I=>!!m&&m.has(I),[w,S]=x.useState(null),[N,T]=x.useState(""),[M,_]=x.useState(null),[A,O]=x.useState(()=>{try{const I=localStorage.getItem("ow-collapsed-sections");return I?new Set(JSON.parse(I)):new Set}catch{return new Set}}),[B,$]=x.useState(null),[W,J]=x.useState(null),[z,G]=x.useState(""),[D,U]=x.useState(null),[q,se]=x.useState(""),[V,re]=x.useState(null),[K,j]=x.useState(""),[L,ee]=x.useState(null),[he,ge]=x.useState(null),[oe,xe]=x.useState([]),[we,We]=x.useState(!1),[He,Ze]=x.useState(null),[Oe,Ke]=x.useState(null),[mt,Ye]=x.useState(null),[pe,gt]=x.useState(null),[ft,at]=x.useState(null),[nt,ht]=x.useState(TE),Fe=x.useRef(null);x.useEffect(()=>{if(!ft)return;const I=ne=>{Fe.current&&!Fe.current.contains(ne.target)&&at(null)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[ft]);const ve=I=>{ht(I),wj(I),at(null)},X=I=>{I.preventDefault(),at({x:I.clientX,y:I.clientY})},Be=x.useCallback((I,ne)=>{fetch("/api/documents/batch-resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:I,action:ne})}).catch(()=>{})},[]),{draggedItem:te,dropIndicator:de,handlePointerDown:fe,dropClass:Je,isDragging:Le,isContainerDropTarget:et}=CT({docs:t,workspaces:n,assignedFiles:r,scrollRef:d,setCollapsedSections:O}),ot=x.useCallback(()=>{fetch("/api/plugins").then(I=>I.json()).then(I=>{const ne=[];let ye=!1;for(const Me of I.plugins||[]){const Ee=Me.displayName||void 0;for(const ke of Me.sidebarMenuItems||[])ne.push({...ke,pluginDisplayName:Ee});Me.name==="@openwriter/plugin-publish"&&Me.enabled&&(ye=!0)}xe(ne),We(ye)}).catch(()=>{})},[]);x.useEffect(()=>{ot()},[ot]),x.useEffect(()=>{const I=()=>ot();return window.addEventListener("ow-plugins-changed",I),()=>window.removeEventListener("ow-plugins-changed",I)},[ot]);const{variantsByMaster:bt,variantFilenames:Ge}=x.useMemo(()=>{const I=new Map,ne=new Set;for(const ye of t)if(ye.masterDocId){const Me=I.get(ye.masterDocId)||[];Me.push(ye),I.set(ye.masterDocId,Me),ne.add(ye.filename)}return{variantsByMaster:I,variantFilenames:ne}},[t]),it=x.useCallback((I,ne)=>{I.preventDefault(),I.stopPropagation(),ee({x:I.clientX,y:I.clientY,filename:ne.filename,title:ne.title,docId:ne.docId,lastSent:ne.lastSent,postedUrl:ne.postedUrl,isNewsletter:ne.isNewsletter})},[]),pt=x.useCallback(I=>{fetch("/api/documents/duplicate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:I})}).catch(()=>{})},[]),Nt=x.useCallback((I,ne,ye)=>{fetch("/api/documents/variant",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:I,masterDocId:ne,variantType:ye})}).catch(()=>{})},[]),Ie=x.useCallback((I,ne,ye,Me,Ee)=>{if(!_T(ne,t.find(ke=>ke.filename===ye))){if(ne.promptForFocus&&Ee===void 0){Ze({action:I,label:ne.label,filename:ye,title:Me});return}fetch("/api/plugins/sidebar-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:I,filename:ye,title:Me,instructions:Ee||"",label:ne.label})}).catch(()=>{})}},[t]),je=I=>{O(ne=>{const ye=new Set(ne);return ye.has(I)?ye.delete(I):ye.add(I),localStorage.setItem("ow-collapsed-sections",JSON.stringify([...ye])),ye})},qe=t.find(I=>I.isActive),F=x.useRef(n);if(F.current=n,x.useEffect(()=>{var I;if(qe)for(const ne of F.current){const ye=AT(((I=ne.workspace)==null?void 0:I.root)||[],qe.filename);if(ye){O(Me=>{const Ee=[ne.filename,...ye.map(me=>`container-${me}`)];if(Ee.every(me=>!Me.has(me)))return Me;const ke=new Set(Me);for(const me of Ee)ke.delete(me);return localStorage.setItem("ow-collapsed-sections",JSON.stringify([...ke])),ke});break}}},[qe==null?void 0:qe.filename]),v!==null)return c.jsx(Qd,{results:v,query:g,onSwitchDocument:i,actions:l});const ce=t.filter(I=>!r.has(I.filename)&&!Ge.has(I.filename)),Ne=(I,ne,ye,Me,Ee,ke=!1)=>c.jsxs("div",{className:`sidebar-item ${I.isActive?"active":""} ${Le(I.filename)?"dragging":""} ${Je(I.filename)}`,"data-drag-id":I.filename,"data-drag-type":"doc","data-drag-ws":ne||"__docs__","data-drag-container":ye||"",onPointerDown:me=>fe(me,{type:"doc",file:I.filename,sourceWs:ne||null},I.title),onClick:()=>!I.isActive&&!te&&i(I.filename),onDoubleClick:()=>{S(I.filename),T(I.title)},onContextMenu:me=>it(me,I),children:[w===I.filename?c.jsx("input",{className:"sidebar-rename-input",value:N,onChange:me=>T(me.target.value),onBlur:()=>{l.handleRename(I.filename,I.title,N),S(null)},onKeyDown:me=>{me.key==="Enter"&&(l.handleRename(I.filename,I.title,N),S(null)),me.key==="Escape"&&S(null)},autoFocus:!0,onClick:me=>me.stopPropagation()}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-item-title-text",children:I.title}),I.variantType&&c.jsx("span",{className:"files-badge-variant",children:I.variantType}),l.getDocTags(I.filename).includes("✓")&&c.jsx("svg",{className:"sidebar-approved-icon",title:"Approved",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),I.lastSent&&c.jsx("svg",{className:"sidebar-sent-icon",title:"Sent",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),(I.autoAccept===!0||I.autoAccept!==!1&&ke)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:I.autoAccept===!0?"Auto-accept on":"Auto-accept inherited"}),s.filenames.includes(I.filename)&&c.jsx("span",{className:"sidebar-pending-dot"})]}),Ls(I.filename)&&c.jsx("div",{className:"sidebar-item-context",children:ET(I.filename)}),c.jsxs("div",{className:"sidebar-item-meta",children:[I.wordCount.toLocaleString()," words · ",ua(I.lastModified)]}),c.jsxs("div",{className:"sidebar-tags",children:[l.getDocTags(I.filename).filter(me=>me!=="✓").map(me=>c.jsxs("span",{className:"sidebar-tag",onClick:Se=>Se.stopPropagation(),children:[me,c.jsx("span",{className:"sidebar-tag-remove",onClick:Se=>{Se.stopPropagation(),l.handleRemoveTag(I.filename,me)},children:"×"})]},me)),V===I.filename?c.jsx("input",{className:"sidebar-tag-input",value:K,onChange:me=>j(me.target.value),onBlur:()=>{K.trim()&&l.handleAddTag(I.filename,K),re(null)},onKeyDown:me=>{me.key==="Enter"&&(l.handleAddTag(I.filename,K),re(null),j("")),me.key==="Escape"&&(re(null),j(""))},autoFocus:!0,onClick:me=>me.stopPropagation(),placeholder:"tag..."}):c.jsx("button",{className:"sidebar-tag-add",onClick:me=>{me.stopPropagation(),re(I.filename),j("")},children:"+"})]})]}),M===I.filename?c.jsxs("div",{className:"sidebar-confirm-delete",onClick:me=>me.stopPropagation(),children:[c.jsx("span",{children:Ls(I.filename)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{l.handleDelete(I.filename),_(null)},children:"Yes"}),c.jsx("button",{onClick:()=>_(null),children:"No"})]}):c.jsx("button",{className:"sidebar-delete-btn",onClick:me=>{me.stopPropagation(),_(I.filename)},title:Ls(I.filename)?"Remove document":"Delete document",children:"×"})]},I.filename),P=(I,ne,ye,Me,Ee,ke=!1)=>{const me=I.docId?bt.get(I.docId):void 0,Se=f&&(h==null?void 0:h.parentDocId)&&h.parentDocId===I.docId;if(!(me&&me.length>0||Se))return Ne(I,ne,ye,Me,Ee,ke);const Zt=`variants-${I.docId}`,Nn=!A.has(Zt);return c.jsxs("div",{className:"sidebar-variant-group",children:[c.jsxs("div",{className:"sidebar-variant-master",onClick:en=>{en.target.closest(".sidebar-variant-chevron")&&(en.stopPropagation(),je(Zt))},children:[Ne(I,ne,ye,Me,Ee,ke),c.jsx("span",{className:`sidebar-variant-chevron${Nn?"":" collapsed"}`,children:c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),Nn&&c.jsxs("div",{className:"sidebar-variant-children",children:[me==null?void 0:me.map((en,Mn)=>Ne(en,ne,ye,Me,Mn,ke)),Se&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]})]})]},`vg-${I.filename}`)},Z=(I,ne,ye,Me,Ee,ke,me=!1)=>{if(I.type==="doc"){const xt=t.find(Pt=>Pt.filename===I.file);return xt?Ge.has(xt.filename)?c.jsx(c.Fragment,{}):P(xt,ye,Me,Ee,ke,me):Ls(I.file)?c.jsx("div",{className:"sidebar-item sidebar-unavailable",children:c.jsxs("div",{className:"sidebar-item-title",children:[I.title||I.file," (unavailable)"]})},I.file):c.jsxs("div",{className:"sidebar-item sidebar-missing",children:[c.jsxs("div",{className:"sidebar-item-title",children:[I.title||I.file," (missing)"]}),c.jsx("button",{className:"sidebar-delete-btn",onClick:()=>l.handleRemoveFromWorkspace(ye,I.file),title:"Remove",children:"×"})]},I.file)}const Se=I,Ct=`container-${Se.id}`,Zt=A.has(Ct),Nn=ne<=2?`depth-${ne}`:"depth-2",en=Se.autoAccept===!0,Mn=en||me;return c.jsxs("div",{className:`sidebar-container ${Nn} ${Zt?"collapsed":""} ${Je(Se.id)} ${et(Se.id)?"drop-inside":""}`,children:[c.jsxs("div",{className:`sidebar-container-header ${(de==null?void 0:de.itemId)===Se.id&&de.position==="inside"?"drop-inside":""}`,"data-drag-id":Se.id,"data-drag-type":"container-header","data-drag-ws":ye,"data-drag-parent":Me||"","data-section-key":Ct,onPointerDown:xt=>fe(xt,{type:"container",id:Se.id,sourceWs:ye},Se.name),onClick:()=>!te&&je(Ct),onContextMenu:xt=>{xt.preventDefault(),xt.stopPropagation(),gt({x:xt.clientX,y:xt.clientY,type:"container",wsFilename:ye,containerId:Se.id,title:Se.name,nodes:Se.items,autoAccept:en})},children:[c.jsx("span",{className:`sidebar-chevron ${Zt?"collapsed":""}`,children:"▾"}),W===Se.id?c.jsx("input",{className:"sidebar-rename-input",value:z,onChange:xt=>G(xt.target.value),onBlur:()=>{l.handleRenameContainer(ye,Se.id,z),J(null)},onKeyDown:xt=>{xt.key==="Enter"&&(l.handleRenameContainer(ye,Se.id,z),J(null)),xt.key==="Escape"&&J(null)},autoFocus:!0,onClick:xt=>xt.stopPropagation()}):c.jsx("span",{className:"sidebar-container-name",onDoubleClick:xt=>{xt.stopPropagation(),J(Se.id),G(Se.name)},children:Se.name}),Mn&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:en?"Auto-accept on for this container":"Auto-accept inherited from workspace"}),c.jsxs("div",{className:"sidebar-container-actions",children:[c.jsx("button",{className:"sidebar-new-btn",onClick:xt=>{xt.stopPropagation(),Ye({anchor:xt.target.getBoundingClientRect(),wsFilename:ye,containerId:Se.id})},title:"New doc",children:"+"}),ne<2&&c.jsx("button",{className:"sidebar-new-btn",onClick:xt=>{xt.stopPropagation(),l.handleCreateContainer(ye,Se.id)},title:"New sub-container",children:"☐"}),c.jsx("button",{className:"sidebar-new-btn sidebar-container-delete",onClick:xt=>{xt.stopPropagation(),l.handleDeleteContainer(ye,Se.id)},title:"Delete container",children:"×"})]})]}),!Zt&&c.jsxs("div",{className:"sidebar-container-list","data-drop-ws":ye,"data-drop-container":Se.id,children:[f&&!(h!=null&&h.parentDocId)&&(h==null?void 0:h.wsFilename)===ye&&h.containerId===Se.id&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),Se.items.filter(xt=>xt.type!=="doc"?!0:!(k(xt.file)||f&&(h==null?void 0:h.wsFilename)===ye&&h.containerId===Se.id&&xt.title===f)).map((xt,Pt)=>Z(xt,ne+1,ye,Se.id,Se.items,Pt,Mn)),Se.items.length===0&&!f&&c.jsx("div",{className:"sidebar-empty",children:te?"Drop here":"Empty"})]})]},Se.id)};return c.jsxs("div",{className:"sidebar-scroll",ref:d,children:[c.jsxs("div",{className:`sidebar-section sidebar-docs-section ${A.has("docs")?"docs-collapsed":""}`,children:[c.jsxs("div",{className:"sidebar-section-header","data-section-key":"docs",onClick:()=>je("docs"),onContextMenu:X,children:[c.jsx("span",{className:`sidebar-chevron ${A.has("docs")?"collapsed":""}`,children:"▾"}),c.jsx("span",{className:"sidebar-label",children:"Documents"}),c.jsx("button",{className:"sidebar-new-btn",onClick:I=>{I.stopPropagation(),Ye({anchor:I.target.getBoundingClientRect()})},title:"New document",children:"+"})]}),!A.has("docs")&&c.jsxs("div",{className:"sidebar-section-list","data-drop-ws":"__docs__",children:[f&&!(h!=null&&h.parentDocId)&&(!h||!n.some(I=>I.filename===(h==null?void 0:h.wsFilename)))&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ce.filter(I=>!k(I.filename)&&(!f||I.title!==f)).map((I,ne)=>{const ye=ce.map(Me=>({type:"doc",file:Me.filename,title:Me.title}));return P(I,void 0,null,ye,ne)}),ce.length===0&&c.jsx("div",{className:"sidebar-empty",children:te?"Drop here to unassign":"No unassigned documents"})]})]}),n.map(I=>{var Ee,ke,me;const ne=((Ee=I.workspace)==null?void 0:Ee.root)||[],ye=A.has(I.filename),Me=((ke=I.workspace)==null?void 0:ke.autoAccept)===!0||I.autoAccept===!0;return c.jsxs("div",{className:`sidebar-section sidebar-workspace-section ${ye?"ws-collapsed":""} ${Le(I.filename)?"dragging":""} ${(de==null?void 0:de.itemId)===I.filename?de.position==="before"?"drop-before":"drop-after":""}`,children:[c.jsxs("div",{className:"sidebar-section-header","data-section-key":I.filename,"data-ws-drag":I.filename,onPointerDown:Se=>fe(Se,{type:"workspace",filename:I.filename},I.title),onClick:()=>!te&&je(I.filename),onContextMenu:Se=>{var Ct;Se.preventDefault(),Se.stopPropagation(),gt({x:Se.clientX,y:Se.clientY,type:"workspace",wsFilename:I.filename,title:I.title,nodes:ne,autoAccept:((Ct=I.workspace)==null?void 0:Ct.autoAccept)===!0||I.autoAccept===!0})},children:[c.jsx("span",{className:`sidebar-chevron ${ye?"collapsed":""}`,children:"▾"}),D===I.filename?c.jsx("input",{className:"sidebar-rename-input",value:q,onChange:Se=>se(Se.target.value),onBlur:()=>{l.handleRenameWorkspace(I.filename,q),U(null)},onKeyDown:Se=>{Se.key==="Enter"&&(l.handleRenameWorkspace(I.filename,q),U(null)),Se.key==="Escape"&&U(null)},autoFocus:!0,onClick:Se=>Se.stopPropagation()}):c.jsx("span",{className:"sidebar-label sidebar-workspace-label",onDoubleClick:Se=>{Se.stopPropagation(),U(I.filename),se(I.title)},children:I.title}),(((me=I.workspace)==null?void 0:me.autoAccept)===!0||I.autoAccept===!0)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:"Auto-accept on for this workspace"}),c.jsxs("div",{className:"sidebar-workspace-actions",children:[c.jsx("button",{className:"sidebar-new-btn",onClick:Se=>{Se.stopPropagation(),Ye({anchor:Se.target.getBoundingClientRect(),wsFilename:I.filename,containerId:null})},title:"New document",children:"+"}),c.jsx("button",{className:"sidebar-new-btn",onClick:Se=>{Se.stopPropagation(),l.handleCreateContainer(I.filename,null)},title:"New container",children:"☐"}),B===I.filename?c.jsxs("span",{className:"sidebar-inline-confirm",onClick:Se=>Se.stopPropagation(),children:[c.jsx("button",{onClick:()=>{l.handleDeleteWorkspace(I.filename),$(null)},children:"Yes"}),c.jsx("button",{onClick:()=>$(null),children:"No"})]}):c.jsx("button",{className:"sidebar-new-btn sidebar-workspace-delete",onClick:Se=>{Se.stopPropagation(),$(I.filename)},title:"Delete workspace",children:"×"})]})]}),!ye&&c.jsxs("div",{className:"sidebar-section-list","data-drop-ws":I.filename,children:[f&&!(h!=null&&h.parentDocId)&&(h==null?void 0:h.wsFilename)===I.filename&&h.containerId===null&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:f})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ne.filter(Se=>Se.type!=="doc"?!0:!(k(Se.file)||f&&(h==null?void 0:h.wsFilename)===I.filename&&h.containerId===null&&Se.title===f)).map((Se,Ct)=>Z(Se,0,I.filename,null,ne,Ct,Me)),ne.length===0&&!f&&c.jsx("div",{className:"sidebar-empty",children:te?"Drop here to add":"Empty workspace"})]})]},I.filename)}),c.jsx("div",{className:"sidebar-new-workspace",children:c.jsx("button",{onClick:l.handleCreateWorkspace,children:"+ New Workspace"})}),pe&&c.jsx(Rd,{x:pe.x,y:pe.y,filename:pe.wsFilename,title:pe.title,onClose:()=>gt(null),onDuplicate:()=>{},onRename:()=>{pe.type==="workspace"?(U(pe.wsFilename),se(pe.title)):pe.containerId&&(J(pe.containerId),G(pe.title)),gt(null)},onArchive:()=>{},onDelete:()=>{pe.type==="workspace"?l.handleDeleteWorkspace(pe.wsFilename):pe.containerId&&l.handleDeleteContainer(pe.wsFilename,pe.containerId)},onPluginAction:()=>{},pluginItems:[],folderMode:!0,onNewDoc:I=>{Ye({anchor:I.target.getBoundingClientRect(),wsFilename:pe.wsFilename,containerId:pe.type==="container"?pe.containerId:null}),gt(null)},onNewContainer:()=>{l.handleCreateContainer(pe.wsFilename,pe.type==="container"?pe.containerId:null),gt(null)},onAcceptAll:()=>{const I=new Set;Ml(pe.nodes,I),I.size&&Be([...I],"accept"),gt(null)},onRejectAll:()=>{const I=new Set;Ml(pe.nodes,I),I.size&&Be([...I],"reject"),gt(null)},folderAutoAccept:pe.autoAccept,folderAutoAcceptLabel:pe.type==="workspace"?"for workspace":"for container",onToggleFolderAutoAccept:()=>{fetch("/api/auto-accept/inherit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wsFile:pe.wsFilename,...pe.type==="container"?{containerId:pe.containerId}:{},enabled:!pe.autoAccept})}).catch(()=>{})}}),L&&c.jsx(Rd,{x:L.x,y:L.y,filename:L.filename,title:L.title,onClose:()=>ee(null),onDuplicate:()=>pt(L.filename),onCreateVariant:L.docId?I=>Nt(L.filename,L.docId,I):void 0,onRename:()=>{S(L.filename),T(L.title)},onArchive:()=>l.handleArchive(L.filename),onDelete:()=>l.handleDelete(L.filename),onPluginAction:(I,ne)=>Ie(I,ne,L.filename,L.title),pluginItems:oe,onSchedulePost:we?()=>{Ke({filename:L.filename,title:L.title}),ee(null)}:void 0,onViewAnalytics:L.docId&&L.lastSent&&(L.postedUrl||L.isNewsletter)?()=>{L.isNewsletter?ge({docId:L.docId,title:L.title}):L.postedUrl&&window.open(L.postedUrl,"_blank"),ee(null)}:void 0,viewAnalyticsLabel:L.isNewsletter?"View Analytics":L.postedUrl?"View on X":"View Analytics",isApproved:l.getDocTags(L.filename).includes("✓"),onToggleApprove:()=>{l.getDocTags(L.filename).includes("✓")?l.handleRemoveTag(L.filename,"✓"):(l.handleAddTag(L.filename,"✓"),setTimeout(()=>window.dispatchEvent(new CustomEvent("ow-accept-all")),50))},isAutoAccept:(()=>{var ne;const I=(ne=t.find(ye=>ye.filename===L.filename))==null?void 0:ne.autoAccept;return I===!0?!0:I===!1?!1:Ad(n,L.filename)})(),onToggleAutoAccept:()=>{var ye;const I=(ye=t.find(Me=>Me.filename===L.filename))==null?void 0:ye.autoAccept,ne=I===!0?!0:I===!1?!1:Ad(n,L.filename);fetch("/api/auto-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:L.filename,enabled:!ne})}).then(()=>l.fetchDocs()).catch(()=>{})},isAlreadySent:!!L.lastSent,onMarkSent:()=>{const I=L.filename;l.getDocTags(I).includes("✓")&&l.handleRemoveTag(I,"✓"),i(I),setTimeout(()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({manualPost:{postedAt:new Date().toISOString()}})}).then(()=>l.fetchDocs()).catch(()=>{})},100),ee(null)}}),He&&c.jsx(TT,{actionLabel:He.label,docTitle:He.title,onClose:()=>Ze(null),onConfirm:I=>{const ne=oe.find(ye=>ye.action===He.action);ne&&Ie(He.action,ne,He.filename,He.title,I),Ze(null)}}),he&&c.jsx(MT,{docId:he.docId,title:he.title,onClose:()=>ge(null)}),Oe&&c.jsx(Pl,{filename:Oe.filename,title:Oe.title,onClose:()=>Ke(null)}),mt&&c.jsx(jT,{anchorRect:mt.anchor,onClose:()=>Ye(null),onSelect:I=>{Ye(null),mt.wsFilename?l.handleCreateInWorkspace(mt.wsFilename,mt.containerId??null,I):I?fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({metadata:I})}).catch(()=>{}):o()}}),ft&&c.jsx("div",{ref:Fe,className:"sidebar-density-dropdown",style:{position:"fixed",left:ft.x,top:ft.y,zIndex:200},children:m8.map(I=>c.jsx("button",{className:`sidebar-density-option ${nt===I.id?"active":""}`,onClick:()=>ve(I.id),children:I.label},I.id))})]})}function v8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,onCreateDocument:i,actions:o,scrollRef:l,searchQuery:d,searchResults:f}){const[h,m]=x.useState(null);if(f!==null)return c.jsx(Qd,{results:f,query:d,onSwitchDocument:s});const g=[...t].sort((w,S)=>new Date(S.lastModified).getTime()-new Date(w.lastModified).getTime()),v=[];let b="";for(const w of g){const S=o8(w.lastModified);S!==b&&(v.push({label:S,docs:[]}),b=S),v[v.length-1].docs.push(w)}const k=w=>{for(const S of e){if(!S.workspace)continue;const N=T=>{for(const M of T)if(M.type==="doc"&&M.file===w||M.type==="container"&&N(M.items))return!0;return!1};if(N(S.workspace.root))return S.title}return null};return c.jsxs("div",{className:"sidebar-scroll tl-scroll",ref:l,children:[c.jsxs("div",{className:"tl-header",children:[c.jsx("span",{className:"tl-title",children:"Timeline"}),c.jsx("button",{className:"sidebar-new-btn",onClick:i,title:"New document",children:"+"})]}),v.map(w=>c.jsxs("div",{className:"tl-group",children:[c.jsx("div",{className:"tl-date",children:w.label}),w.docs.map(S=>{const N=k(S.filename);return c.jsxs("div",{className:`tl-item ${S.isActive?"active":""}`,onClick:()=>!S.isActive&&s(S.filename),children:[c.jsx("div",{className:"tl-dot"}),c.jsxs("div",{className:"tl-content",children:[c.jsxs("div",{className:"tl-item-title",children:[c.jsx("span",{children:S.title}),r.filenames.includes(S.filename)&&c.jsx("span",{className:"sidebar-pending-dot"})]}),Ls(S.filename)&&c.jsx("div",{className:"tl-item-context",children:ET(S.filename)}),c.jsxs("div",{className:"tl-item-meta",children:[S.wordCount.toLocaleString()," words · ",ua(S.lastModified)]}),N&&c.jsx("div",{className:"tl-badge",children:N})]}),h===S.filename?c.jsxs("div",{className:"sidebar-confirm-delete",onClick:T=>T.stopPropagation(),children:[c.jsx("span",{children:Ls(S.filename)?"Remove?":"Delete?"}),c.jsx("button",{onClick:()=>{o.handleDelete(S.filename),m(null)},children:"Yes"}),c.jsx("button",{onClick:()=>m(null),children:"No"})]}):c.jsx("button",{className:"sidebar-delete-btn",onClick:T=>{T.stopPropagation(),m(S.filename)},title:Ls(S.filename)?"Remove":"Delete",children:"×"})]},S.filename)})]},w.label)),t.length===0&&c.jsx("div",{className:"sidebar-empty",children:"No documents yet"})]})}function y8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,actions:i,scrollRef:o,searchQuery:l,searchResults:d,onSearchChange:f}){const[h,m]=x.useState([]),[g,v]=x.useState(null),[b,k]=x.useState(null),w=x.useRef(null);x.useEffect(()=>{if(!g)return;const j=L=>{w.current&&!w.current.contains(L.target)&&v(null)};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[g]);const S=(j,L)=>{for(const ee of j)if(ee.type==="container"){if(ee.id===L)return ee;const he=S(ee.items,L);if(he)return he}return null},N=j=>{let L=0;for(const ee of j)ee.type==="doc"?L++:ee.type==="container"&&(L+=N(ee.items));return L},T=j=>{const L=[];for(const ee of j)ee.type==="doc"?L.push(ee.file):ee.type==="container"&&L.push(...T(ee.items));return L},M=x.useMemo(()=>{if(h.length===0)return[];const j=h[h.length-1],L=e.find(he=>he.filename===j.wsFilename);if(!(L!=null&&L.workspace))return[];if(j.type==="workspace")return L.workspace.root;const ee=S(L.workspace.root,j.key);return ee?ee.items:[]},[h,e]),_=M.filter(j=>j.type==="container"),A=x.useMemo(()=>{const j=M.filter(L=>L.type==="doc").map(L=>L.file);return t.filter(L=>j.includes(L.filename))},[M,t]),O=j=>{const L=T(j.items);return t.filter(ee=>L.includes(ee.filename))},B=j=>{const L=e.find(he=>he.filename===j);if(!(L!=null&&L.workspace))return[];const ee=T(L.workspace.root);return t.filter(he=>ee.includes(he.filename))},$=x.useMemo(()=>t.filter(j=>!n.has(j.filename)),[t,n]),W=j=>{m(L=>[...L,j]),v(null)},J=()=>{m(j=>j.slice(0,-1)),v(null)},z=(j,L)=>{if(g===j){v(null);return}const he=L.currentTarget.getBoundingClientRect();k({top:he.bottom+4,left:he.left}),v(j)},G=j=>{s(j),v(null)},D=h.length>1?h[h.length-2].title:"All",U=x.useRef(null),q=x.useRef(null),[se,V]=x.useState(null),re=x.useCallback(j=>{const ee=j.currentTarget.getBoundingClientRect();V({top:ee.bottom+4,left:ee.left})},[]);x.useEffect(()=>{if(!d)return;const j=L=>{q.current&&!q.current.contains(L.target)&&U.current&&!U.current.contains(L.target)&&f("")};return document.addEventListener("mousedown",j),()=>document.removeEventListener("mousedown",j)},[d,f]);const K=()=>{if(!g)return[];if(g==="__unassigned__")return $;if(g==="__level-docs__")return A;const j=e.find(L=>L.filename===g);if(j)return B(j.filename);for(const L of e){if(!L.workspace)continue;const ee=S(L.workspace.root,g);if(ee)return O(ee)}return[]};return c.jsxs("div",{className:"board-scroll",ref:o,children:[c.jsxs("div",{className:"board-search-pill",children:[c.jsxs("svg",{className:"board-search-icon",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"11",cy:"11",r:"8"}),c.jsx("path",{d:"m21 21-4.3-4.3"})]}),c.jsx("input",{ref:U,className:"board-search-input",type:"text",placeholder:"Search...",value:l,onChange:j=>f(j.target.value),onFocus:re}),l&&c.jsx("button",{className:"board-search-clear",onClick:()=>f(""),children:"×"})]}),h.length===0?c.jsx("button",{className:"board-back board-back--static",tabIndex:-1,children:"All"}):c.jsxs("button",{className:"board-back",onClick:J,title:`Back to ${D}`,children:["← ",D]}),h.length===0&&c.jsxs(c.Fragment,{children:[$.length>0&&c.jsxs("button",{className:`board-chip ${g==="__unassigned__"?"open":""}`,onClick:j=>z("__unassigned__",j),children:["Documents ",c.jsx("span",{className:"board-chip-count",children:$.length})]}),e.map(j=>{var ee;const L=(ee=j.workspace)==null?void 0:ee.root.some(he=>he.type==="container");return c.jsxs("button",{className:`board-chip ${g===j.filename?"open":""}`,onClick:he=>L?W({type:"workspace",key:j.filename,title:j.title,wsFilename:j.filename}):z(j.filename,he),children:[j.title," ",c.jsx("span",{className:"board-chip-count",children:j.docCount}),L&&c.jsx("span",{className:"board-chip-arrow",children:"›"})]},j.filename)}),c.jsx("button",{className:"board-chip board-chip-add",onClick:i.handleCreateWorkspace,title:"New workspace",children:"+"})]}),h.length>0&&c.jsxs(c.Fragment,{children:[A.length>0&&c.jsxs("button",{className:`board-chip board-chip-docs ${g==="__level-docs__"?"open":""}`,onClick:j=>z("__level-docs__",j),children:["Docs ",c.jsx("span",{className:"board-chip-count",children:A.length})]}),_.map(j=>{const L=j.items.some(ee=>ee.type==="container");return c.jsxs("button",{className:`board-chip ${g===j.id?"open":""}`,onClick:ee=>L?W({type:"container",key:j.id,title:j.name,wsFilename:h[h.length-1].wsFilename}):z(j.id,ee),children:[j.name," ",c.jsx("span",{className:"board-chip-count",children:N(j.items)}),L&&c.jsx("span",{className:"board-chip-arrow",children:"›"})]},j.id)})]}),g&&b&&(()=>{const j=K();return c.jsxs("div",{className:"board-dropdown",ref:w,style:{position:"fixed",top:b.top,left:b.left},children:[j.map(L=>c.jsxs("div",{className:`board-dropdown-item ${L.isActive?"active":""}`,onClick:()=>G(L.filename),children:[c.jsxs("span",{className:"board-dropdown-title",children:[L.title,r.filenames.includes(L.filename)&&c.jsx("span",{className:"board-pending-dot"})]}),c.jsxs("span",{className:"board-dropdown-meta",children:[L.wordCount.toLocaleString()," words · ",ua(L.lastModified)]})]},L.filename)),j.length===0&&c.jsx("div",{className:"board-dropdown-empty",children:"No documents"})]})})(),d&&se&&c.jsxs("div",{className:"board-dropdown board-search-dropdown",ref:q,style:{position:"fixed",top:se.top,left:se.left},children:[d.map(j=>c.jsxs("div",{className:`board-dropdown-item ${j.isActive?"active":""}`,onClick:()=>{s(j.filename),f("")},children:[c.jsx("span",{className:"board-dropdown-title",children:j.title}),j.matchType==="tag"&&j.matchedTag&&c.jsxs("span",{className:"board-dropdown-meta",children:["Tag: ",j.matchedTag]}),j.matchType==="content"&&j.snippet&&c.jsx("span",{className:"board-dropdown-meta board-search-snippet",children:j.snippet}),c.jsxs("span",{className:"board-dropdown-meta",children:[j.wordCount.toLocaleString()," words · ",ua(j.lastModified)]})]},j.filename)),d.length===0&&c.jsx("div",{className:"board-dropdown-empty",children:"No results"})]})]})}function b8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,actions:i,scrollRef:o,searchQuery:l,searchResults:d}){const[f,h]=x.useState([]);if(d!==null)return c.jsx(Qd,{results:d,query:l,onSwitchDocument:s});const m=(M,_)=>{for(const A of M)if(A.type==="container"){if(A.id===_)return A;const O=m(A.items,_);if(O)return O}return null},g=M=>{let _=0;for(const A of M)A.type==="doc"?_++:A.type==="container"&&(_+=g(A.items));return _},v=x.useMemo(()=>{if(f.length===0)return[];const M=f[f.length-1],_=e.find(O=>O.filename===M.wsFilename);if(!(_!=null&&_.workspace))return[];if(M.type==="workspace")return _.workspace.root;const A=m(_.workspace.root,M.key);return A?A.items:[]},[f,e]),b=v.filter(M=>M.type==="container"),k=x.useMemo(()=>{if(f.length===0)return t.filter(_=>!n.has(_.filename));const M=v.filter(_=>_.type==="doc").map(_=>_.file);return t.filter(_=>M.includes(_.filename))},[f,v,t,n]),w=M=>h(_=>[..._,M]),S=()=>h(M=>M.slice(0,-1)),N=f.length>1?f[f.length-2].title:"Shelf",T=f.length>0?f[f.length-1].title:"Documents";return c.jsxs("div",{className:"shelf-wrapper",children:[c.jsxs("div",{className:"shelf-spines",ref:o,children:[f.length>0&&c.jsxs("button",{className:"shelf-back",onClick:S,title:`Back to ${N}`,children:[c.jsx("span",{className:"shelf-back-arrow",children:"←"}),c.jsx("span",{className:"shelf-back-label",children:N})]}),f.length===0&&c.jsxs(c.Fragment,{children:[e.map(M=>c.jsxs("div",{className:"shelf-section-spine",onClick:()=>w({type:"workspace",key:M.filename,title:M.title,wsFilename:M.filename}),title:M.title,children:[c.jsx("span",{className:"shelf-section-title",children:M.title}),c.jsx("span",{className:"shelf-section-count",children:M.docCount})]},M.filename)),c.jsx("button",{className:"shelf-add",onClick:i.handleCreateWorkspace,title:"New workspace",children:"+"})]}),f.length>0&&b.map(M=>c.jsxs("div",{className:"shelf-section-spine shelf-section-container",onClick:()=>w({type:"container",key:M.id,title:M.name,wsFilename:f[f.length-1].wsFilename}),title:M.name,children:[c.jsx("span",{className:"shelf-section-title",children:M.name}),c.jsx("span",{className:"shelf-section-count",children:g(M.items)})]},M.id))]}),c.jsxs("div",{className:"shelf-docs",children:[c.jsx("div",{className:"shelf-docs-header",children:T}),c.jsxs("div",{className:"shelf-docs-list",children:[k.map(M=>c.jsxs("div",{className:`shelf-doc-item ${M.isActive?"active":""}`,onClick:()=>s(M.filename),children:[c.jsxs("div",{className:"shelf-doc-title",children:[c.jsx("span",{children:M.title}),r.filenames.includes(M.filename)&&c.jsx("span",{className:"shelf-pending-dot"})]}),c.jsxs("div",{className:"shelf-doc-meta",children:[M.wordCount.toLocaleString()," words · ",ua(M.lastModified)]})]},M.filename)),k.length===0&&c.jsx("div",{className:"shelf-docs-empty",children:"No documents"})]})]})]})}async function Nk(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();if((i=(s=r==null?void 0:r.content)==null?void 0:s[0])!=null&&i.text)try{return JSON.parse(r.content[0].text)}catch{return r.content[0].text}return r}function RT({filename:t,title:e,isActive:n,onSwitchDocument:r,onClose:s}){const[i,o]=x.useState("loading"),[l,d]=x.useState([]),[f,h]=x.useState(null),[m,g]=x.useState(null),[v,b]=x.useState(null);x.useEffect(()=>{Nk("list_blog_sites").then(S=>{if(S.error){g(S.error),o("error");return}const N=S.sites||[];d(N),N.length===0?o("pick"):N.length===1?(h(N[0].id),o("confirm")):o("pick")}).catch(S=>{g((S==null?void 0:S.message)||"Failed to load blog sites"),o("error")})},[]);const k=l.find(S=>S.id===f)||null,w=async()=>{if(k){o("posting"),g(null),n||(r(t),await new Promise(S=>setTimeout(S,350)));try{const S=await Nk("post_to_blog",{site_id:k.id});if(S!=null&&S.error){g(S.error),o("error");return}const N=S.commit?`https://github.com/${k.owner}/${k.repo}/commit/${S.commit}`:void 0;b({message:S.message,file:S.file,commit:S.commit,images_committed:S.images_committed,liveUrl:S.live_url,commitUrl:N,warning:S.warning}),o("done")}catch(S){g((S==null?void 0:S.message)||"Publish failed"),o("error")}}};return c.jsx("div",{className:"post-blog-overlay",onClick:()=>{i!=="posting"&&s()},children:c.jsxs("div",{className:"post-blog-modal",onClick:S=>S.stopPropagation(),children:[c.jsxs("div",{className:"post-blog-modal-header",children:[c.jsx("h3",{children:"Post to Blog"}),c.jsx("button",{className:"post-blog-modal-close",onClick:s,disabled:i==="posting",children:"×"})]}),c.jsx("div",{className:"post-blog-modal-doc",children:e}),i==="loading"&&c.jsx("div",{className:"post-blog-modal-loading",children:"Loading blog sites…"}),i==="pick"&&l.length===0&&c.jsxs("div",{className:"post-blog-modal-empty",children:["No blog sites registered. Add one in ",c.jsx("strong",{children:"Settings → Plugins → GitHub"})," first.",c.jsx("button",{className:"post-blog-modal-done",onClick:s,children:"Close"})]}),i==="pick"&&l.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"post-blog-modal-label",children:"Choose a destination"}),c.jsx("div",{className:"post-blog-modal-sites",children:l.map(S=>c.jsxs("button",{className:`post-blog-modal-site${f===S.id?" post-blog-modal-site--selected":""}`,onClick:()=>{h(S.id),o("confirm")},children:[c.jsx("div",{className:"post-blog-modal-site-label",children:S.label}),c.jsxs("div",{className:"post-blog-modal-site-repo",children:[S.owner,"/",S.repo,"@",S.branch]})]},S.id))})]}),i==="confirm"&&k&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"post-blog-modal-confirm",children:["Publish to ",c.jsxs("strong",{children:[k.owner,"/",k.repo,"@",k.branch]}),"?",c.jsxs("div",{className:"post-blog-modal-target-dir",children:["→ ",k.content_dir]})]}),c.jsxs("div",{className:"post-blog-modal-actions",children:[c.jsx("button",{className:"post-blog-modal-btn post-blog-modal-btn--primary",onClick:w,children:"Publish now"}),l.length>1&&c.jsx("button",{className:"post-blog-modal-btn",onClick:()=>o("pick"),children:"Back"}),c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Cancel"})]})]}),i==="posting"&&c.jsx("div",{className:"post-blog-modal-loading",children:"Publishing…"}),i==="done"&&v&&c.jsxs("div",{className:"post-blog-modal-result post-blog-modal-result--success",children:[c.jsx("div",{children:v.message||"Published"}),v.file&&c.jsx("div",{className:"post-blog-modal-meta",children:v.file}),typeof v.images_committed=="number"&&v.images_committed>0&&c.jsxs("div",{className:"post-blog-modal-meta",children:[v.images_committed," image",v.images_committed===1?"":"s"," committed"]}),v.warning&&c.jsx("div",{className:"post-blog-modal-warning",children:v.warning}),c.jsxs("div",{className:"post-blog-modal-actions",children:[v.liveUrl?c.jsx("button",{className:"post-blog-modal-btn post-blog-modal-btn--primary",onClick:()=>window.open(v.liveUrl,"_blank"),children:"View Post"}):v.commitUrl?c.jsx("button",{className:"post-blog-modal-btn post-blog-modal-btn--primary",onClick:()=>window.open(v.commitUrl,"_blank"),children:"View commit"}):null,c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Done"})]}),v.liveUrl&&v.commitUrl&&c.jsx("button",{className:"post-blog-modal-commit-link",onClick:()=>window.open(v.commitUrl,"_blank"),children:"View commit"})]}),i==="error"&&c.jsxs("div",{className:"post-blog-modal-result post-blog-modal-result--error",children:[c.jsx("div",{children:m||"Publish failed"}),c.jsx("div",{className:"post-blog-modal-actions",children:c.jsx("button",{className:"post-blog-modal-btn",onClick:s,children:"Close"})})]})]})})}const x8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M20 20H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h4l2 2h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2z"}),c.jsx("line",{x1:"9",y1:"14",x2:"15",y2:"14",opacity:"0.5"})]}),w8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("polyline",{points:"14 2 14 8 20 8"}),c.jsx("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),c.jsx("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}),k8=()=>c.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})}),S8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("path",{d:"M7 15l-4-3.5L7 8",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),E8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("path",{d:"M3 8V6.5C3 5.67 3.67 5 4.5 5h2C7.33 5 8 5.67 8 6.5V8c0 2-1.5 3-3 3",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),N8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:[c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z",opacity:"0.5"}),c.jsx("rect",{x:"2",y:"16",width:"8",height:"7",rx:"1.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),c.jsx("line",{x1:"4",y1:"18.5",x2:"8",y2:"18.5",stroke:"currentColor",strokeWidth:"1",opacity:"0.7"}),c.jsx("line",{x1:"4",y1:"20.5",x2:"7",y2:"20.5",stroke:"currentColor",strokeWidth:"1",opacity:"0.7"})]}),C8=()=>c.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",children:c.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 0 1-2.063-2.065 2.064 2.064 0 1 1 2.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"})}),_8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),c.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),T8=()=>c.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("path",{d:"M2 12h20"}),c.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]}),Ck=()=>c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})});function M8({type:t}){switch(t){case"tweet":return c.jsx(k8,{});case"reply":return c.jsx(S8,{});case"quote":return c.jsx(E8,{});case"article":return c.jsx(N8,{});case"linkedin":return c.jsx(C8,{});case"newsletter":return c.jsx(_8,{});case"blog":return c.jsx(T8,{});default:return c.jsx(w8,{})}}function Iu(t){let e=0;for(const n of t)n.type==="doc"?e++:n.type==="container"&&(e+=Iu(n.items));return e}function OT(t,e){for(const n of t){if(n.type==="doc"&&n.file===e)return[];if(n.type==="container"){const r=OT(n.items,e);if(r)return[n.id,...r]}}return null}function Ip(t){const e=new Set;return Ml(t,e),[...e]}function IT(t,e,n=0){for(const r of t)if(r.type==="container"){if(r.id===e)return n;const s=IT(r.items,e,n+1);if(s>=0)return s}return-1}function j8(t,e){if(!e)return 12;for(const n of t){if(!n.workspace)continue;const r=IT(n.workspace.root,e);if(r>=0)return 12+(r+1)*16}return 12}function A8({docs:t,workspaces:e,assignedFiles:n,pendingDocs:r,onSwitchDocument:s,onCreateDocument:i,actions:o,scrollRef:l,writingTitle:d,writingTarget:f,pendingWriteFilenames:h,searchQuery:m,searchResults:g,onSearchChange:v}){var Ie,je,qe;const b=F=>!!h&&h.has(F),[k,w]=x.useState(()=>{try{const F=localStorage.getItem("ow-files-collapsed");return F?new Set(JSON.parse(F)):new Set}catch{return new Set}}),{draggedItem:S,dropIndicator:N,handlePointerDown:T,dropClass:M,isDragging:_,isContainerDropTarget:A}=CT({docs:t,workspaces:e,assignedFiles:n,scrollRef:l,setCollapsedSections:w}),O=F=>!N||N.itemId!==F||N.position==="inside"?void 0:{"--drop-indent":`${j8(e,N.containerId)}px`},{variantsByMaster:B,variantFilenames:$}=x.useMemo(()=>{const F=new Map,ce=new Set;for(const Ne of t)if(Ne.masterDocId){const P=F.get(Ne.masterDocId)||[];P.push(Ne),F.set(Ne.masterDocId,P),ce.add(Ne.filename)}return{variantsByMaster:F,variantFilenames:ce}},[t]),[W,J]=x.useState(null),[z,G]=x.useState(null),[D,U]=x.useState(new Set),[q,se]=x.useState(null),[V,re]=x.useState([]),[K,j]=x.useState(!1),[L,ee]=x.useState(null),[he,ge]=x.useState(null),[oe,xe]=x.useState(null),[we,We]=x.useState(null),[He,Ze]=x.useState(null),[Oe,Ke]=x.useState(null),[mt,Ye]=x.useState(new Set);x.useEffect(()=>{Ye(new Set)},[r]);const pe=x.useCallback(()=>{fetch("/api/plugins").then(F=>F.json()).then(F=>{const ce=[];let Ne=!1;for(const P of F.plugins||[]){const Z=P.displayName||void 0;for(const I of P.sidebarMenuItems||[])ce.push({...I,pluginDisplayName:Z});P.name==="@openwriter/plugin-publish"&&P.enabled&&(Ne=!0)}re(ce),j(Ne)}).catch(()=>{})},[]);x.useEffect(()=>{pe()},[pe]),x.useEffect(()=>{const F=()=>pe();return window.addEventListener("ow-plugins-changed",F),()=>window.removeEventListener("ow-plugins-changed",F)},[pe]);const gt=x.useCallback((F,ce)=>{if(F.preventDefault(),F.stopPropagation(),D.has(ce.filename)&&D.size>1){G({x:F.clientX,y:F.clientY,filename:ce.filename,title:ce.title,bulkCount:D.size});return}D.size>0&&!D.has(ce.filename)&&U(new Set),G({x:F.clientX,y:F.clientY,filename:ce.filename,title:ce.title,docId:ce.docId,lastSent:ce.lastSent,postedUrl:ce.postedUrl,isNewsletter:ce.isNewsletter,contentType:ce.contentType,sortRequest:ce.sortRequest})},[D]),ft=x.useCallback(F=>{fetch("/api/documents/duplicate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).catch(()=>{})},[]),at=x.useCallback((F,ce,Ne,P,Z)=>{if(!_T(ce,t.find(I=>I.filename===Ne))){if(ce.promptForFocus&&Z===void 0){ee({action:F,label:ce.label,filename:Ne,title:P});return}fetch("/api/plugins/sidebar-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:F,filename:Ne,title:P,instructions:Z||"",label:ce.label})}).catch(()=>{})}},[t]),nt=x.useCallback((F,ce)=>{Ye(Ne=>{const P=new Set(Ne);for(const Z of F)P.add(Z);return P}),fetch("/api/documents/batch-resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:F,action:ce})}).catch(()=>{})},[]),ht=F=>{w(ce=>{const Ne=new Set(ce);return Ne.has(F)?Ne.delete(F):Ne.add(F),localStorage.setItem("ow-files-collapsed",JSON.stringify([...Ne])),Ne})},Fe=(F,ce,Ne,P)=>{J({type:F,key:ce,value:Ne,wsFilename:P})},ve=()=>{if(!W)return;const{type:F,key:ce,value:Ne,wsFilename:P}=W;F==="doc"?o.handleRename(ce,"",Ne):F==="workspace"?o.handleRenameWorkspace(ce,Ne):F==="container"&&P&&o.handleRenameContainer(P,ce,Ne),J(null)},X=t.find(F=>F.isActive),Be=x.useRef(e);Be.current=e,x.useEffect(()=>{var F;if(X)for(const ce of Be.current){const Ne=OT(((F=ce.workspace)==null?void 0:F.root)||[],X.filename);if(Ne){w(P=>{const Z=[ce.filename,...Ne.map(ne=>`container-${ne}`)];if(Z.every(ne=>!P.has(ne)))return P;const I=new Set(P);for(const ne of Z)I.delete(ne);return localStorage.setItem("ow-files-collapsed",JSON.stringify([...I])),I});break}}},[X==null?void 0:X.filename]);const te=x.useMemo(()=>t.filter(F=>!n.has(F.filename)&&!$.has(F.filename)&&!b(F.filename)),[t,n,$,h]),de=x.useMemo(()=>{var P;const F=[],ce=Z=>{F.push(Z.filename);const I=Z.docId?B.get(Z.docId):void 0,ne=Z.docId&&!k.has(`variants-${Z.docId}`);if(I&&ne)for(const ye of I)F.push(ye.filename)},Ne=Z=>{for(const I of Z)if(I.type==="doc"){const ne=t.find(ye=>ye.filename===I.file);ne&&!$.has(ne.filename)&&ce(ne)}else k.has(`container-${I.id}`)||Ne(I.items)};k.has("docs")||te.forEach(ce);for(const Z of e)k.has(Z.filename)||Ne(((P=Z.workspace)==null?void 0:P.root)||[]);return F},[t,e,te,$,B,k]),fe=x.useCallback(()=>{U(new Set)},[]),Je=x.useCallback((F,ce)=>{if(S)return;const Ne=F.shiftKey,P=F.ctrlKey||F.metaKey;if(Ne){const I=q||(X==null?void 0:X.filename)||ce,ne=de.indexOf(I),ye=de.indexOf(ce);if(ne<0||ye<0){U(new Set([ce])),se(ce);return}const[Me,Ee]=ne<ye?[ne,ye]:[ye,ne];U(new Set(de.slice(Me,Ee+1)));return}if(P){U(I=>{const ne=new Set(I);return ne.has(ce)?ne.delete(ce):ne.add(ce),ne}),se(ce);return}U(new Set),se(ce);const Z=t.find(I=>I.filename===ce);Z&&!Z.isActive&&s(ce)},[S,q,X==null?void 0:X.filename,de,s,t]);x.useEffect(()=>{if(D.size===0)return;const F=ce=>{ce.key==="Escape"&&fe()};return document.addEventListener("keydown",F),()=>document.removeEventListener("keydown",F)},[D.size,fe]);const Le=x.useCallback(()=>{for(const F of D)o.handleDelete(F);U(new Set),se(null)},[D,o]),et=x.useCallback(F=>{F.length!==0&&fetch("/api/documents/sort-request",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filenames:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]),ot=x.useCallback(F=>{fetch("/api/documents/sort-reject",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]),bt=x.useCallback(F=>{fetch("/api/documents/sort-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:F})}).then(()=>o.fetchDocs()).catch(()=>{})},[o]);if(g!==null)return c.jsx(Qd,{results:g,query:m,onSwitchDocument:s,actions:o});const Ge=F=>c.jsx("input",{className:"sidebar-rename-input",value:W.value,onChange:ce=>J(Ne=>Ne?{...Ne,value:ce.target.value}:null),onBlur:F,onKeyDown:ce=>{ce.key==="Enter"&&F(),ce.key==="Escape"&&J(null)},autoFocus:!0,onClick:ce=>ce.stopPropagation()}),it=(F,ce,Ne,P,Z,I=!1)=>c.jsxs("div",{className:`files-row${F.isActive?" active":""}${D.has(F.filename)?" selected":""} ${_(F.filename)?"dragging":""} ${M(F.filename)}${F.masterDocId?" is-variant":""}`,style:{paddingLeft:ce,...O(F.filename)},"data-drag-id":F.filename,"data-drag-type":"doc","data-drag-ws":Ne||"__docs__","data-drag-container":P||"",onPointerDown:ne=>T(ne,{type:"doc",file:F.filename,sourceWs:Ne||null},F.title),onClick:ne=>Je(ne,F.filename),onDoubleClick:()=>Fe("doc",F.filename,F.title),onContextMenu:ne=>gt(ne,F),children:[c.jsx("span",{className:"files-row-icon",children:c.jsx(M8,{type:F.contentType})}),(W==null?void 0:W.type)==="doc"&&W.key===F.filename?Ge(ve):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"files-row-label",children:F.title}),F.variantType&&c.jsx("span",{className:"files-badge-variant",children:F.variantType}),(F.autoAccept===!0||F.autoAccept!==!1&&I)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:F.autoAccept===!0?"Auto-accept on":"Auto-accept inherited"}),r.filenames.includes(F.filename)&&!mt.has(F.filename)&&c.jsx("span",{className:"files-badge-pending"}),F.sortRequest&&(F.sortRequest.proposal?c.jsx("span",{className:"files-badge-sort-proposal",title:"Sort proposal ready — right-click to review"}):c.jsx("span",{className:"files-badge-sort-pending",title:"Sort requested"})),o.getDocTags(F.filename).includes("✓")&&c.jsx("span",{className:"files-badge-approved",children:c.jsx(Ck,{})}),F.lastSent&&c.jsx("span",{className:"files-badge-sent",children:c.jsx(Ck,{})}),Z&&c.jsx("span",{className:`files-row-chevron${k.has(`variants-${F.docId}`)?" collapsed":""}`,onClick:ne=>{ne.stopPropagation(),ht(`variants-${F.docId}`)},children:c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})})]})]},F.filename),pt=(F,ce,Ne,P,Z=!1)=>{const I=F.docId?B.get(F.docId):void 0,ne=!!(I&&I.length>0),ye=d&&(f==null?void 0:f.parentDocId)&&f.parentDocId===F.docId,Me=ne||ye,Ee=!k.has(`variants-${F.docId}`);return Me?c.jsxs("div",{className:"files-variant-group",children:[it(F,ce,Ne,P,ne,Z),Ee&&(I==null?void 0:I.map(ke=>it(ke,ce+16,Ne,P,!1,Z))),ye&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:ce+16},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]})]},`vg-${F.filename}`):it(F,ce,Ne,P,!1,Z)},Nt=(F,ce,Ne,P,Z=!1)=>{const I=12+ce*16;if(F.type==="doc"){const Se=t.find(Ct=>Ct.filename===F.file);return!Se||$.has(Se.filename)?null:pt(Se,I,Ne,P,Z)}const ne=F,ye=`container-${ne.id}`,Me=k.has(ye),Ee=Iu(ne.items),ke=ne.autoAccept===!0,me=ke||Z;return c.jsxs("div",{className:`${M(ne.id)} ${A(ne.id)?"files-drop-inside":""}`,children:[c.jsxs("div",{className:`files-row is-container ${_(ne.id)?"dragging":""} ${M(ne.id)}`,style:{paddingLeft:I,...O(ne.id)},"data-drag-id":ne.id,"data-drag-type":"container-header","data-drag-ws":Ne,"data-drag-parent":P||"","data-section-key":ye,onPointerDown:Se=>T(Se,{type:"container",id:ne.id,sourceWs:Ne},ne.name),onClick:()=>!S&&ht(ye),onDoubleClick:Se=>{Se.stopPropagation(),Fe("container",ne.id,ne.name,Ne)},onContextMenu:Se=>{Se.preventDefault(),Se.stopPropagation(),Ke({x:Se.clientX,y:Se.clientY,type:"container",wsFilename:Ne,containerId:ne.id,title:ne.name,nodes:ne.items,autoAccept:ke})},children:[c.jsx("span",{className:"files-row-icon",children:c.jsx(x8,{})}),(W==null?void 0:W.type)==="container"&&W.key===ne.id?Ge(ve):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"files-row-label",children:ne.name}),me&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:ke?"Auto-accept on for this container":"Auto-accept inherited from workspace"}),c.jsx("span",{className:"files-row-count",children:Ee})]})]}),c.jsxs("div",{className:`files-children${Me?" collapsed":""}`,"data-drop-ws":Ne,"data-drop-container":ne.id,children:[d&&!(f!=null&&f.parentDocId)&&(f==null?void 0:f.wsFilename)===Ne&&f.containerId===ne.id&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:12+(ce+1)*16},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ne.items.filter(Se=>Se.type!=="doc"||!b(Se.file)).map(Se=>Nt(Se,ce+1,Ne,ne.id,me))]})]},ne.id)};return c.jsxs("div",{className:"files-scroll",ref:l,children:[c.jsxs("div",{className:"files-section",children:[c.jsxs("div",{className:"files-row is-section","data-section-key":"docs",onClick:()=>ht("docs"),children:[c.jsx("span",{className:`files-row-chevron leading${k.has("docs")?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),c.jsx("span",{className:"files-row-label",children:"Documents"}),c.jsx("button",{className:"files-section-btn",onClick:F=>{F.stopPropagation(),Ze({anchor:F.target.getBoundingClientRect()})},title:"New document",children:"+"})]}),c.jsxs("div",{className:`files-section-list files-children${k.has("docs")?" collapsed":""}`,"data-drop-ws":"__docs__",children:[d&&!(f!=null&&f.parentDocId)&&(!f||!e.some(F=>F.filename===(f==null?void 0:f.wsFilename)))&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:28},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),te.map(F=>pt(F,28))]})]}),e.map(F=>{var I,ne,ye;const ce=((I=F.workspace)==null?void 0:I.root)||[],Ne=k.has(F.filename),P=Iu(ce),Z=((ne=F.workspace)==null?void 0:ne.autoAccept)===!0||F.autoAccept===!0;return c.jsxs("div",{className:`files-section ${_(F.filename)?"dragging":""} ${(N==null?void 0:N.itemId)===F.filename?N.position==="before"?"files-ws-drop-before":"files-ws-drop-after":""}`,children:[c.jsx("div",{className:`files-row is-section${(N==null?void 0:N.itemId)==="__section__"&&N.wsFilename===F.filename&&N.position==="inside"?" files-ws-drop-target":""}`,"data-section-key":F.filename,"data-ws-drag":F.filename,onPointerDown:Me=>T(Me,{type:"workspace",filename:F.filename},F.title),onClick:()=>!S&&ht(F.filename),onDoubleClick:Me=>{Me.stopPropagation(),Fe("workspace",F.filename,F.title)},onContextMenu:Me=>{var Ee;Me.preventDefault(),Me.stopPropagation(),Ke({x:Me.clientX,y:Me.clientY,type:"workspace",wsFilename:F.filename,title:F.title,nodes:ce,autoAccept:((Ee=F.workspace)==null?void 0:Ee.autoAccept)===!0||F.autoAccept===!0})},children:(W==null?void 0:W.type)==="workspace"&&W.key===F.filename?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:`files-row-chevron leading${Ne?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),Ge(ve)]}):c.jsxs(c.Fragment,{children:[c.jsx("span",{className:`files-row-chevron leading${Ne?" collapsed":""}`,children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),c.jsx("span",{className:"files-row-label",children:F.title}),(((ye=F.workspace)==null?void 0:ye.autoAccept)===!0||F.autoAccept===!0)&&c.jsx("span",{className:"sidebar-auto-accept-dot",title:"Auto-accept on for this workspace"}),c.jsx("span",{className:"files-row-count",children:P}),c.jsxs("div",{className:"files-section-actions",children:[c.jsx("button",{className:"files-section-btn",onClick:Me=>{Me.stopPropagation(),Ze({anchor:Me.target.getBoundingClientRect(),wsFilename:F.filename,containerId:null})},title:"New document",children:"+"}),c.jsx("button",{className:"files-section-btn",onClick:Me=>{Me.stopPropagation(),o.handleCreateContainer(F.filename,null)},title:"New container",children:"☐"})]})]})}),c.jsxs("div",{className:`files-section-list files-children${Ne?" collapsed":""}`,"data-drop-ws":F.filename,children:[d&&!(f!=null&&f.parentDocId)&&(f==null?void 0:f.wsFilename)===F.filename&&f.containerId===null&&c.jsxs("div",{className:"sidebar-item sidebar-writing-placeholder",style:{paddingLeft:28},children:[c.jsxs("div",{className:"sidebar-item-title",children:[c.jsx("span",{className:"sidebar-writing-spinner"}),c.jsx("span",{className:"sidebar-item-title-text",children:d})]}),c.jsx("div",{className:"sidebar-item-meta",children:"Writing..."})]}),ce.filter(Me=>Me.type!=="doc"||!b(Me.file)).map(Me=>Nt(Me,1,F.filename,null,Z))]})]},F.filename)}),c.jsx("div",{className:"files-new-ws",children:c.jsx("button",{onClick:o.handleCreateWorkspace,children:"+ New Workspace"})}),Oe&&c.jsx(Rd,{x:Oe.x,y:Oe.y,filename:Oe.wsFilename,title:Oe.title,onClose:()=>Ke(null),onDuplicate:()=>{},onRename:()=>{Oe.type==="workspace"?Fe("workspace",Oe.wsFilename,Oe.title):Oe.containerId&&Fe("container",Oe.containerId,Oe.title,Oe.wsFilename),Ke(null)},onArchive:()=>{},onDelete:()=>{Oe.type==="workspace"?o.handleDeleteWorkspace(Oe.wsFilename):Oe.containerId&&o.handleDeleteContainer(Oe.wsFilename,Oe.containerId,!1)},folderDocCount:Oe.type==="container"?Iu(Oe.nodes):0,onDeleteWithDocs:Oe.type==="container"&&Oe.containerId?()=>{o.handleDeleteContainer(Oe.wsFilename,Oe.containerId,!0)}:void 0,onPluginAction:()=>{},pluginItems:[],folderMode:!0,onNewDoc:F=>{Ze({anchor:F.target.getBoundingClientRect(),wsFilename:Oe.wsFilename,containerId:Oe.type==="container"?Oe.containerId:null}),Ke(null)},onNewContainer:()=>{o.handleCreateContainer(Oe.wsFilename,Oe.type==="container"?Oe.containerId:null),Ke(null)},onAcceptAll:()=>{const F=Ip(Oe.nodes);F.length&&nt(F,"accept"),Ke(null)},onRejectAll:()=>{const F=Ip(Oe.nodes);F.length&&nt(F,"reject"),Ke(null)},folderAutoAccept:Oe.autoAccept,folderAutoAcceptLabel:Oe.type==="workspace"?"for workspace":"for container",onToggleFolderAutoAccept:()=>{fetch("/api/auto-accept/inherit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({wsFile:Oe.wsFilename,...Oe.type==="container"?{containerId:Oe.containerId}:{},enabled:!Oe.autoAccept})}).catch(()=>{})},onRequestSortAll:()=>{const F=Ip(Oe.nodes);F.length&&et(F)}}),z&&c.jsx(Rd,{x:z.x,y:z.y,filename:z.filename,title:z.title,bulkCount:z.bulkCount,onBulkDelete:Le,onBulkRequestSort:z.bulkCount?()=>et([...D]):void 0,onClose:()=>G(null),onDuplicate:()=>ft(z.filename),onCreateVariant:z.docId?F=>{fetch("/api/documents/variant",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:z.filename,masterDocId:z.docId,variantType:F})}).catch(()=>{})}:void 0,onRename:()=>{Fe("doc",z.filename,z.title),G(null)},onArchive:()=>o.handleArchive(z.filename),onDelete:()=>o.handleDelete(z.filename),onPluginAction:(F,ce)=>at(F,ce,z.filename,z.title),pluginItems:V,onSchedulePost:K?()=>{ge({filename:z.filename,title:z.title}),G(null)}:void 0,onPostNow:z.contentType==="blog"?()=>{const F=(X==null?void 0:X.filename)===z.filename;xe({filename:z.filename,title:z.title,isActive:F}),G(null)}:void 0,isAlreadyPublished:z.contentType==="blog"&&!!z.postedUrl,onViewAnalytics:z.docId&&z.lastSent&&(z.postedUrl||z.isNewsletter)?()=>{z.isNewsletter?We({docId:z.docId,title:z.title}):z.postedUrl&&window.open(z.postedUrl,"_blank"),G(null)}:void 0,viewAnalyticsLabel:z.isNewsletter?"View Analytics":z.contentType==="blog"&&z.postedUrl?"View Post":z.postedUrl?"View on X":"View Analytics",isApproved:o.getDocTags(z.filename).includes("✓"),onToggleApprove:()=>{o.getDocTags(z.filename).includes("✓")?o.handleRemoveTag(z.filename,"✓"):(o.handleAddTag(z.filename,"✓"),setTimeout(()=>window.dispatchEvent(new CustomEvent("ow-accept-all")),50))},isAutoAccept:(()=>{var ce;const F=(ce=t.find(Ne=>Ne.filename===z.filename))==null?void 0:ce.autoAccept;return F===!0?!0:F===!1?!1:Ad(e,z.filename)})(),onToggleAutoAccept:()=>{var Ne;const F=(Ne=t.find(P=>P.filename===z.filename))==null?void 0:Ne.autoAccept,ce=F===!0?!0:F===!1?!1:Ad(e,z.filename);fetch("/api/auto-accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filename:z.filename,enabled:!ce})}).then(()=>o.fetchDocs()).catch(()=>{})},isAlreadySent:!!z.lastSent,onMarkSent:()=>{const F=z.filename;o.getDocTags(F).includes("✓")&&o.handleRemoveTag(F,"✓"),s(F),setTimeout(()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({manualPost:{postedAt:new Date().toISOString()}})}).then(()=>o.fetchDocs()).catch(()=>{})},100),G(null)},sortState:z.bulkCount?void 0:(Ie=z.sortRequest)!=null&&Ie.proposal?"proposal":z.sortRequest?"pending":"none",sortProposalLabel:(()=>{var I;const F=(I=z.sortRequest)==null?void 0:I.proposal;if(!F)return;const ce=e.find(ne=>ne.filename===F.wsFilename),Ne=(ce==null?void 0:ce.title)||F.wsFilename;if(!F.containerId)return Ne;const P=ne=>{for(const ye of ne){if(ye.type==="container"&&ye.id===F.containerId)return ye.name;if(ye.type==="container"){const Me=P(ye.items);if(Me)return Me}}return null},Z=ce!=null&&ce.workspace?P(ce.workspace.root):null;return Z?`${Ne} / ${Z}`:Ne})(),sortProposalReasoning:(qe=(je=z.sortRequest)==null?void 0:je.proposal)==null?void 0:qe.reasoning,onRequestSort:z.bulkCount?void 0:()=>et([z.filename]),onCancelSort:()=>ot(z.filename),onAcceptSortProposal:()=>bt(z.filename),onRejectSortProposal:()=>ot(z.filename)}),L&&c.jsx(TT,{actionLabel:L.label,docTitle:L.title,onClose:()=>ee(null),onConfirm:F=>{const ce=V.find(Ne=>Ne.action===L.action);ce&&at(L.action,ce,L.filename,L.title,F),ee(null)}}),we&&c.jsx(MT,{docId:we.docId,title:we.title,onClose:()=>We(null)}),he&&c.jsx(Pl,{filename:he.filename,title:he.title,onClose:()=>ge(null)}),oe&&c.jsx(RT,{filename:oe.filename,title:oe.title,isActive:oe.isActive,onSwitchDocument:s,onClose:()=>xe(null)}),He&&c.jsx(jT,{anchorRect:He.anchor,onClose:()=>Ze(null),onSelect:F=>{Ze(null),He.wsFilename?o.handleCreateInWorkspace(He.wsFilename,He.containerId??null,F):F?fetch("/api/documents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({metadata:F})}).catch(()=>{}):i()}})]})}const R8=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],O8=[{value:"any",label:"Any"},{value:"content_type",label:"Content Type"},{value:"connection",label:"Connection"}],LT=["America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Anchorage","Pacific/Honolulu","America/Phoenix","America/Toronto","America/Vancouver","America/Sao_Paulo","America/Mexico_City","Europe/London","Europe/Paris","Europe/Berlin","Europe/Amsterdam","Europe/Rome","Europe/Madrid","Europe/Moscow","Asia/Tokyo","Asia/Shanghai","Asia/Kolkata","Asia/Dubai","Asia/Singapore","Asia/Seoul","Australia/Sydney","Australia/Melbourne","Pacific/Auckland"];function _k(t){var e;try{const n=new Date,i=((e=new Intl.DateTimeFormat("en-US",{timeZone:t,timeZoneName:"short"}).formatToParts(n).find(l=>l.type==="timeZoneName"))==null?void 0:e.value)||"";return`${t.split("/").pop().replace(/_/g," ")} (${i})`}catch{return t}}function I8(t){if(t.length>0)return t[0].timezone;try{const e=Intl.DateTimeFormat().resolvedOptions().timeZone;if(LT.includes(e))return e}catch{}return"America/New_York"}function L8({slots:t,onBack:e}){const[n,r]=x.useState(t),[s,i]=x.useState(()=>I8(t)),[o,l]=x.useState(!1),[d,f]=x.useState("09:00"),[h,m]=x.useState(["default"]),[g,v]=x.useState("any"),[b,k]=x.useState(!1),w=x.useRef(null);x.useEffect(()=>{if(!o)return;function _(A){w.current&&!w.current.contains(A.target)&&l(!1)}return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[o]);async function S(_){i(_);const A=[];for(const O of n){const B=await fetch(`/api/scheduler/slots/${O.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({timezone:_})});if(B.ok){const $=await B.json();A.push($.slot)}else A.push(O)}A.length>0&&r(A)}async function N(){const _=await fetch("/api/scheduler/slots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({time:d,days:h.includes("default")?["default"]:h,filter_type:g,timezone:s})});if(_.ok){const A=await _.json();r(O=>[...O,A.slot]),k(!1),f("09:00"),m(["default"]),v("any")}}async function T(_){(await fetch(`/api/scheduler/slots/${_}`,{method:"DELETE"})).ok&&r(O=>O.filter(B=>B.id!==_))}function M(_){m(A=>{if(_==="default")return["default"];const O=A.filter(B=>B!=="default");if(O.includes(_)){const B=O.filter($=>$!==_);return B.length===0?["default"]:B}return[...O,_]})}return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-btn",onClick:e,title:"Back",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Slot Settings"}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>k(!b),children:b?"Cancel":"+ Add"})]}),c.jsxs("div",{className:"slot-tz",ref:w,children:[c.jsx("label",{className:"slot-tz-label",children:"Timezone"}),c.jsxs("button",{className:"slot-tz-trigger",onClick:()=>l(!o),children:[c.jsx("span",{children:_k(s)}),c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`slot-tz-chevron ${o?"slot-tz-chevron--open":""}`,children:c.jsx("path",{d:"m6 9 6 6 6-6"})})]}),o&&c.jsx("div",{className:"slot-tz-dropdown",children:LT.map(_=>c.jsx("div",{className:`slot-tz-option ${_===s?"active":""}`,onClick:()=>{S(_),l(!1)},children:_k(_)},_))})]}),b&&c.jsxs("div",{className:"slot-add-form",children:[c.jsxs("div",{className:"slot-add-row",children:[c.jsx("input",{type:"time",className:"slot-input",value:d,onChange:_=>f(_.target.value)}),c.jsx("select",{className:"slot-input",value:g,onChange:_=>v(_.target.value),children:O8.map(_=>c.jsx("option",{value:_.value,children:_.label},_.value))})]}),c.jsxs("div",{className:"slot-add-days",children:[c.jsx("button",{className:`sidebar-schedule-btn slot-day-btn ${h.includes("default")?"sidebar-schedule-btn--active":""}`,onClick:()=>M("default"),children:"Every day"}),R8.map(_=>c.jsx("button",{className:`sidebar-schedule-btn slot-day-btn ${h.includes(_.toLowerCase())?"sidebar-schedule-btn--active":""}`,onClick:()=>M(_.toLowerCase()),children:_},_))]}),c.jsx("button",{className:"sidebar-schedule-btn sidebar-schedule-btn--active slot-create-btn",onClick:N,children:"Create Slot"})]}),c.jsx("div",{className:"slot-list",children:n.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No slots"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create time slots to define your posting schedule."})]}):n.map(_=>c.jsxs("div",{className:"schedule-item slot-item",children:[c.jsx("div",{className:"schedule-item-time slot-item-time",children:D8(_.time)}),c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:_.days.includes("default")?"Every day":_.days.join(", ")}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsxs("span",{children:["Filter: ",_.filter_type]}),_.filter_value&&c.jsxs("span",{children:["(",_.filter_value,")"]})]})]}),c.jsx("button",{className:"schedule-item-action schedule-item-action--danger slot-delete-btn",onClick:()=>T(_.id),title:"Delete slot",children:"×"})]},_.id))})]})}function D8(t){const[e,n]=t.split(":").map(Number),r=e>=12?"PM":"AM";return`${e%12||12}:${String(n).padStart(2,"0")} ${r}`}function P8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState([]),[i,o]=x.useState(null),[l,d]=x.useState(!1),[f,h]=x.useState(!0),m=x.useCallback(async()=>{try{const[S,N]=await Promise.all([fetch("/api/scheduler/autoplugs/goals"),fetch("/api/scheduler/autoplugs/tracking")]);if(S.ok){const T=await S.json();n(T.goals||[])}if(N.ok){const T=await N.json();s(T.tracking||[])}}catch{}h(!1)},[]);x.useEffect(()=>{m()},[m]);const g=async S=>{(await fetch(`/api/scheduler/autoplugs/goals/${S.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!S.enabled})})).ok&&n(T=>T.map(M=>M.id===S.id?{...M,enabled:!M.enabled}:M))},v=async S=>{(await fetch(`/api/scheduler/autoplugs/goals/${S}`,{method:"DELETE"})).ok&&(n(T=>T.filter(M=>M.id!==S)),o(null))},b=async S=>{(await fetch(`/api/scheduler/autoplugs/tracking/${S}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({skipped:!0})})).ok&&s(T=>T.map(M=>M.id===S?{...M,skipped:!0}:M))},k=e.reduce((S,N)=>N.rule&&N.enabled?Math.min(S,N.rule.threshold):S,1/0),w=k===1/0?50:k;return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-back",onClick:t,title:"Back",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Autoplugs"}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>d(!l),children:l?"Cancel":"+ Add"})]}),l&&c.jsx($8,{onCreated:S=>{n(N=>[...N,S]),d(!1)}}),f?null:c.jsxs(c.Fragment,{children:[e.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No goals"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create a goal to start autoplugging your tweets."})]}):e.map(S=>c.jsxs("div",{children:[c.jsxs("div",{className:"schedule-item",onClick:()=>o(i===S.id?null:S.id),children:[c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:S.name}),c.jsx("div",{className:"schedule-item-meta",children:B8(S).map((N,T)=>c.jsx("span",{children:N},T))})]}),c.jsx("button",{className:`autoplug-toggle ${S.enabled?"autoplug-toggle--on":"autoplug-toggle--off"}`,onClick:N=>{N.stopPropagation(),g(S)},title:S.enabled?"Disable":"Enable"})]}),i===S.id&&c.jsx(z8,{goal:S,onSaved:N=>{n(T=>T.map(M=>M.id===N.id?N:M))},onDeleted:()=>v(S.id),onRefresh:m})]},S.id)),c.jsx("div",{className:"schedule-day-header",children:"Tracking"}),r.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No tracked tweets"}),c.jsx("div",{className:"schedule-empty-desc",children:"Tweets will appear here after posting."})]}):r.map(S=>c.jsxs("div",{className:"schedule-item",children:[c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:S.original_text||`Tweet ${S.tweet_id}`}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsx("span",{children:F8(S.posted_at)}),c.jsxs("span",{children:[S.likes," likes"]}),c.jsxs("span",{children:[S.retweets," RTs"]}),S.views>0&&c.jsxs("span",{children:[U8(S.views)," views"]})]}),S.triggered?c.jsxs("div",{className:"autoplug-tracking-triggered",children:[c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Autoplugged ",S.goal_name?`→ ${S.goal_name}`:""]}):S.skipped?c.jsx("div",{className:"autoplug-tracking-skipped",children:"Skipped"}):c.jsx("div",{className:"autoplug-tracking-bar",children:c.jsx("div",{className:"autoplug-tracking-bar-fill",style:{width:`${Math.min(100,S.likes/w*100)}%`}})})]}),!S.triggered&&!S.skipped&&c.jsx("button",{className:"autoplug-tracking-skip",onClick:()=>b(S.id),title:"Skip autoplug for this tweet",children:"×"})]},S.id))]})]})}function B8(t){const e=[];return t.rule&&(e.push(`${t.rule.threshold}+ ${t.rule.metric}`),e.push(t.rule.mode.charAt(0).toUpperCase()+t.rule.mode.slice(1)),t.rule.delay_minutes>0&&e.push(`${t.rule.delay_minutes}m delay`)),e.push(`${t.pool_count} msg${t.pool_count!==1?"s":""}`),e}function $8({onCreated:t}){const[e,n]=x.useState(""),[r,s]=x.useState(""),[i,o]=x.useState(""),[l,d]=x.useState("likes"),[f,h]=x.useState(50),[m,g]=x.useState(30),[v,b]=x.useState("static"),[k,w]=x.useState(!1),S=async()=>{if(e.trim()){w(!0);try{const N=await fetch("/api/scheduler/autoplugs/goals",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e.trim(),link:r.trim()||null,description:i.trim()||null})});if(!N.ok){w(!1);return}const{goal:T}=await N.json();await fetch("/api/scheduler/autoplugs/rules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({goal_id:T.id,metric:l,threshold:f,delay_minutes:m,mode:v})});const M=await fetch("/api/scheduler/autoplugs/goals");if(M.ok){const A=((await M.json()).goals||[]).find(O=>O.id===T.id);if(A){t(A);return}}t({...T,rule_count:1,pool_count:0,rule:{metric:l,threshold:f,delay_minutes:m,mode:v,id:""}})}finally{w(!1)}}};return c.jsxs("div",{className:"autoplug-editor",children:[c.jsxs("label",{children:["Name",c.jsx("input",{value:e,onChange:N=>n(N.target.value),placeholder:"Newsletter, Course..."})]}),c.jsxs("label",{children:["Link",c.jsx("input",{value:r,onChange:N=>s(N.target.value),placeholder:"https://..."})]}),c.jsxs("label",{children:["Description (context for LLM)",c.jsx("textarea",{value:i,onChange:N=>o(N.target.value),placeholder:"Weekly engineering insights...",rows:2})]}),c.jsxs("div",{className:"autoplug-editor-row",children:[c.jsx("input",{type:"number",value:f,onChange:N=>h(Number(N.target.value)),min:1}),c.jsxs("select",{value:l,onChange:N=>d(N.target.value),children:[c.jsx("option",{value:"likes",children:"likes"}),c.jsx("option",{value:"retweets",children:"retweets"}),c.jsx("option",{value:"views",children:"views"})]}),c.jsx("span",{className:"autoplug-editor-row-label",children:"wait"}),c.jsx("input",{type:"number",value:m,onChange:N=>g(Number(N.target.value)),min:0,className:"autoplug-delay-input"}),c.jsx("span",{className:"autoplug-editor-row-label",children:"min"})]}),c.jsx("div",{className:"autoplug-mode-toggle",children:["static","llm","hybrid"].map(N=>c.jsx("button",{className:v===N?"active":"",onClick:()=>b(N),children:N==="llm"?"LLM":N.charAt(0).toUpperCase()+N.slice(1)},N))}),c.jsx("button",{className:"sidebar-schedule-btn sidebar-schedule-btn--active autoplug-create-btn",onClick:S,disabled:k||!e.trim(),children:k?"Creating...":"Create Goal"})]})}function z8({goal:t,onSaved:e,onDeleted:n,onRefresh:r}){var J,z,G,D;const[s,i]=x.useState(t.name),[o,l]=x.useState(t.link||""),[d,f]=x.useState(t.description||""),[h,m]=x.useState(((J=t.rule)==null?void 0:J.metric)||"likes"),[g,v]=x.useState(((z=t.rule)==null?void 0:z.threshold)||50),[b,k]=x.useState(((G=t.rule)==null?void 0:G.delay_minutes)||30),[w,S]=x.useState(((D=t.rule)==null?void 0:D.mode)||"static"),[N,T]=x.useState([]),[M,_]=x.useState(""),[A,O]=x.useState(!1);x.useEffect(()=>{fetch(`/api/scheduler/autoplugs/goals/${t.id}/pool`).then(U=>U.json()).then(U=>T(U.pool||[])).catch(()=>{})},[t.id]);const B=async()=>{var U;O(!0);try{await fetch(`/api/scheduler/autoplugs/goals/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s,link:o||null,description:d||null})}),(U=t.rule)!=null&&U.id?await fetch(`/api/scheduler/autoplugs/rules/${t.rule.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({metric:h,threshold:g,delay_minutes:b,mode:w})}):await fetch("/api/scheduler/autoplugs/rules",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({goal_id:t.id,metric:h,threshold:g,delay_minutes:b,mode:w})}),r()}finally{O(!1)}},$=async()=>{if(!M.trim())return;const U=await fetch(`/api/scheduler/autoplugs/goals/${t.id}/pool`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:M.trim()})});if(U.ok){const q=await U.json();T(se=>[...se,q.message]),_("")}},W=async U=>{(await fetch(`/api/scheduler/autoplugs/pool/${U}`,{method:"DELETE"})).ok&&T(se=>se.filter(V=>V.id!==U))};return c.jsxs("div",{className:"autoplug-editor",children:[c.jsxs("label",{children:["Name",c.jsx("input",{value:s,onChange:U=>i(U.target.value)})]}),c.jsxs("label",{children:["Link",c.jsx("input",{value:o,onChange:U=>l(U.target.value),placeholder:"https://..."})]}),c.jsxs("label",{children:["Description",c.jsx("textarea",{value:d,onChange:U=>f(U.target.value),rows:2})]}),c.jsx("div",{className:"autoplug-editor-section-label",children:"Trigger"}),c.jsxs("div",{className:"autoplug-editor-row",children:[c.jsx("input",{type:"number",value:g,onChange:U=>v(Number(U.target.value)),min:1}),c.jsxs("select",{value:h,onChange:U=>m(U.target.value),children:[c.jsx("option",{value:"likes",children:"likes"}),c.jsx("option",{value:"retweets",children:"retweets"}),c.jsx("option",{value:"views",children:"views"})]}),c.jsx("span",{className:"autoplug-editor-row-label",children:"wait"}),c.jsx("input",{type:"number",value:b,onChange:U=>k(Number(U.target.value)),min:0,className:"autoplug-delay-input"}),c.jsx("span",{className:"autoplug-editor-row-label",children:"min"})]}),c.jsx("div",{className:"autoplug-mode-toggle",children:["static","llm","hybrid"].map(U=>c.jsx("button",{className:w===U?"active":"",onClick:()=>S(U),children:U==="llm"?"LLM":U.charAt(0).toUpperCase()+U.slice(1)},U))}),c.jsxs("div",{className:"autoplug-pool-section",children:[c.jsx("div",{className:"autoplug-editor-section-label",children:"Static Pool"}),N.map(U=>c.jsxs("div",{className:"autoplug-pool-item",children:[c.jsx("span",{children:U.content}),c.jsx("button",{onClick:()=>W(U.id),title:"Remove",children:"×"})]},U.id)),c.jsxs("div",{className:"autoplug-pool-add",children:[c.jsx("input",{value:M,onChange:U=>_(U.target.value),placeholder:"Add message... (use {{link}} for link)",onKeyDown:U=>U.key==="Enter"&&$()}),c.jsx("button",{onClick:$,children:"+"})]})]}),(w==="llm"||w==="hybrid")&&c.jsx("div",{className:"autoplug-llm-hint",children:"LLM mode uses Author's Voice to generate contextual replies referencing the original tweet."}),c.jsxs("div",{className:"autoplug-editor-actions",children:[c.jsx("button",{className:"schedule-item-action",onClick:B,disabled:A,children:A?"Saving...":"Save"}),c.jsx("button",{className:"schedule-item-action schedule-item-action--danger",onClick:n,children:"Delete"})]})]})}function F8(t){const e=Date.now()-new Date(t).getTime(),n=Math.floor(e/6e4);if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function U8(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}function H8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState([]),[i,o]=x.useState(!1),[l,d]=x.useState(!1),[f,h]=x.useState(null),[m,g]=x.useState(!0),v=x.useCallback(async()=>{try{const[w,S]=await Promise.all([fetch("/api/scheduler/queue"),fetch("/api/scheduler/slots"),fetch("/api/scheduler/sync",{method:"POST"})]);if(w.ok){const N=await w.json();n(N.items||[])}if(S.ok){const N=await S.json();s(N.slots||[])}}catch{}g(!1)},[]);x.useEffect(()=>{v()},[v]);const b=async w=>{(await fetch(`/api/scheduler/queue/${w}`,{method:"DELETE"})).ok&&(n(N=>N.filter(T=>T.id!==w)),h(null))};if(l)return c.jsx(P8,{onBack:()=>{d(!1),v()}});if(i)return c.jsx(L8,{slots:r,onBack:()=>{o(!1),v()}});const k=W8(r,e);return c.jsxs("div",{className:"sidebar-schedule",children:[c.jsxs("div",{className:"sidebar-schedule-header",children:[c.jsx("button",{className:"sidebar-schedule-back",onClick:t,title:"Back to documents",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Schedule"}),c.jsxs("div",{className:"sidebar-schedule-actions",children:[c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>d(!0),title:"Autoplugs",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}),c.jsx("button",{className:"sidebar-schedule-btn",onClick:()=>o(!0),title:"Manage slots",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),m?null:r.length===0?c.jsxs("div",{className:"schedule-empty",children:[c.jsx("div",{className:"schedule-empty-title",children:"No time slots"}),c.jsx("div",{className:"schedule-empty-desc",children:"Create time slots to define your posting schedule."})]}):k.map(({label:w,entries:S})=>c.jsxs("div",{className:"schedule-day",children:[c.jsx("div",{className:"schedule-day-header",children:w}),S.map((N,T)=>{var M,_,A,O,B;return N.type==="empty"?c.jsxs("div",{className:"schedule-slot-empty",children:[c.jsx("div",{className:"schedule-item-time",children:Mk(N.time)}),c.jsx("div",{className:"schedule-slot-empty-label",children:((M=N.slot)==null?void 0:M.filter_type)==="any"?"Open slot":`${(_=N.slot)==null?void 0:_.filter_type}: ${((A=N.slot)==null?void 0:A.filter_value)||"any"}`})]},`empty-${T}`):c.jsxs("div",{children:[c.jsxs("div",{className:"schedule-item",onClick:()=>h(f===N.item.id?null:N.item.id),children:[c.jsx("div",{className:"schedule-item-time",children:Mk(N.time)}),c.jsxs("div",{className:"schedule-item-content",children:[c.jsx("div",{className:"schedule-item-text",children:((O=N.item.content)==null?void 0:O.text)||JSON.stringify(N.item.content)}),c.jsxs("div",{className:"schedule-item-meta",children:[c.jsx("span",{className:`schedule-item-status schedule-item-status--${N.item.status}`}),c.jsx("span",{children:N.item.status}),N.item.connection_name&&c.jsx("span",{children:N.item.connection_name}),N.item.provider&&c.jsx("span",{children:N.item.provider})]})]})]}),f===N.item.id&&c.jsxs("div",{className:"schedule-item-expanded",children:[c.jsx("div",{className:"schedule-item-full-text",children:((B=N.item.content)==null?void 0:B.text)||JSON.stringify(N.item.content,null,2)}),c.jsx("div",{className:"schedule-item-actions",children:c.jsx("button",{className:"schedule-item-action schedule-item-action--danger",onClick:()=>b(N.item.id),children:"Cancel"})})]})]},N.item.id)})]},w))]})}function W8(t,e){const n=new Date,r=[];for(let l=0;l<7;l++){const d=new Date(n);d.setDate(d.getDate()+l),d.setHours(0,0,0,0);let f;l===0?f="Today":l===1?f="Tomorrow":f=d.toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"}),r.push({label:f,date:d})}const s=new Map;for(const l of e){const d=new Date(l.scheduled_at),f=`${d.getFullYear()}-${d.getMonth()}-${d.getDate()}-${d.getHours()}-${d.getMinutes()}`;s.set(f,l)}const i=new Set,o=[];for(const{label:l,date:d}of r){const f=[],h=d.getDay(),g=["sun","mon","tue","wed","thu","fri","sat"][h];for(const v of t){if(!(v.days.includes("default")||v.days.includes(g)))continue;const[k,w]=v.time.split(":").map(Number),S=new Date(d);if(S.setHours(k,w,0,0),Tk(d,n)&&S<n)continue;const N=`${S.getFullYear()}-${S.getMonth()}-${S.getDate()}-${k}-${w}`,T=s.get(N);T?(f.push({type:"filled",time:S,item:T,slot:v}),i.add(T.id)):f.push({type:"empty",time:S,slot:v})}for(const v of e){if(i.has(v.id))continue;const b=new Date(v.scheduled_at);Tk(b,d)&&(f.push({type:"filled",time:b,item:v}),i.add(v.id))}f.sort((v,b)=>v.time.getTime()-b.time.getTime()),f.length>0&&o.push({label:l,entries:f})}return o}function Tk(t,e){return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()}function Mk(t){return t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}function q8({onBack:t}){const[e,n]=x.useState([]),[r,s]=x.useState(""),[i,o]=x.useState(null),[l,d]=x.useState(!1),f=x.useRef(null),h=x.useCallback(async()=>{try{const w=await fetch("/api/tasks");if(w.ok){const S=await w.json();n(S.tasks||[])}}catch{}},[]);x.useEffect(()=>{h()},[h]);const m=async()=>{const w=r.trim();if(w){s("");try{const S=await fetch("/api/tasks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:w})});if(S.ok){const N=await S.json();n(T=>[...T,N.task])}}catch{}}},g=w=>{o(w),fetch(`/api/tasks/${w}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({completed:!0})}).catch(()=>{}),setTimeout(()=>{n(S=>S.filter(N=>N.id!==w)),o(null)},400)},v=async w=>{try{(await fetch(`/api/tasks/${w}`,{method:"DELETE"})).ok&&n(N=>N.filter(T=>T.id!==w))}catch{}},b=()=>{d(!0),setTimeout(()=>{var w;return(w=f.current)==null?void 0:w.focus()},0)},k=e.filter(w=>!w.completed);return c.jsxs("div",{className:"sidebar-tasks",children:[c.jsxs("div",{className:"sidebar-tasks-header",children:[c.jsx("button",{className:"sidebar-tasks-back",onClick:t,title:"Back to documents",children:c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"m15 18-6-6 6-6"})})}),c.jsx("h3",{children:"Tasks"}),c.jsx("button",{className:"sidebar-tasks-add-btn",onClick:b,title:"Add task",children:"+"})]}),k.length===0&&!l?c.jsxs("div",{className:"sidebar-tasks-empty",children:[c.jsx("div",{className:"sidebar-tasks-empty-title",children:"No tasks"}),c.jsx("div",{className:"sidebar-tasks-empty-desc",children:"Add tasks to track your checklist."})]}):c.jsx("div",{className:"sidebar-tasks-list",children:k.map(w=>c.jsxs("div",{className:`sidebar-tasks-item${i===w.id?" completing":""}`,children:[c.jsx("input",{type:"checkbox",className:"sidebar-tasks-checkbox",checked:i===w.id,onChange:()=>g(w.id)}),c.jsx("span",{className:`sidebar-tasks-text${i===w.id?" completed":""}`,children:w.text}),c.jsx("button",{className:"sidebar-tasks-delete",onClick:()=>v(w.id),title:"Remove",children:"×"})]},w.id))}),l&&c.jsx("div",{className:"sidebar-tasks-add",children:c.jsx("input",{ref:f,type:"text",placeholder:"New task...",value:r,onChange:w=>s(w.target.value),onKeyDown:w=>{w.key==="Enter"&&m(),w.key==="Escape"&&(d(!1),s(""))},onBlur:()=>{r.trim()||d(!1)}})})]})}function V8({profiles:t,activeProfile:e,trashedProfiles:n,onSwitch:r,onCreate:s,onDelete:i,onRestore:o}){const[l,d]=x.useState(!1),[f,h]=x.useState(!1),[m,g]=x.useState(""),[v,b]=x.useState(null),k=x.useRef(null),w=x.useRef(null);x.useEffect(()=>{if(!l)return;const N=T=>{k.current&&!k.current.contains(T.target)&&(d(!1),h(!1),g(""),b(null))};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[l]),x.useEffect(()=>{f&&w.current&&w.current.focus()},[f]);const S=()=>{const N=m.trim();N&&(s(N),g(""),h(!1))};return c.jsxs("div",{className:"sidebar-profile-wrapper",ref:k,children:[c.jsx("button",{className:"sidebar-collapse-btn",onClick:()=>d(!l),title:`Profile: ${e}`,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"8",r:"4"}),c.jsx("path",{d:"M5.5 21a8.38 8.38 0 0 1 13 0"})]})}),l&&c.jsxs("div",{className:"sidebar-profile-dropdown",children:[t.map(N=>c.jsxs("div",{className:"sidebar-profile-row",children:[v===N?c.jsxs("div",{className:"sidebar-profile-confirm",children:[c.jsx("span",{children:"Delete?"}),c.jsxs("div",{className:"sidebar-inline-confirm",children:[c.jsx("button",{onClick:()=>{i(N),b(null)},children:"Yes"}),c.jsx("button",{onClick:()=>b(null),children:"No"})]})]}):c.jsx(c.Fragment,{children:c.jsxs("button",{className:`sidebar-profile-option ${N===e?"active":""}`,onClick:()=>{N!==e&&r(N),d(!1)},children:[c.jsx("span",{className:"sidebar-profile-check",children:N===e?"✓":""}),c.jsx("span",{children:N})]})}),N!=="Default"&&N!==e&&v!==N&&c.jsx("button",{className:"sidebar-profile-delete-btn",onClick:T=>{T.stopPropagation(),b(N)},title:"Delete profile",children:"×"})]},N)),n.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"sidebar-profile-divider"}),c.jsx("div",{className:"sidebar-profile-trash-label",children:"Trash"}),n.map(N=>c.jsxs("div",{className:"sidebar-profile-row sidebar-profile-trashed",children:[c.jsx("span",{className:"sidebar-profile-trash-name",children:N}),c.jsx("button",{className:"sidebar-profile-restore-btn",onClick:()=>o(N),children:"Restore"})]},N))]}),c.jsx("div",{className:"sidebar-profile-divider"}),f?c.jsx("div",{className:"sidebar-profile-add-input",children:c.jsx("input",{ref:w,type:"text",value:m,onChange:N=>g(N.target.value),onKeyDown:N=>{N.key==="Enter"&&S(),N.key==="Escape"&&(h(!1),g(""))},placeholder:"Profile name..."})}):c.jsxs("button",{className:"sidebar-profile-option sidebar-profile-add",onClick:()=>h(!0),children:[c.jsx("span",{className:"sidebar-profile-check",children:"+"}),c.jsx("span",{children:"New Profile"})]})]})]})}const jk=200,Ak=600,Lp=260;function Rk({open:t,onSwitchDocument:e,onCreateDocument:n,refreshKey:r,docTagsRefreshKey:s,workspacesRefreshKey:i,pendingDocs:o,writingTitle:l,writingTarget:d,pendingWriteFilenames:f,onClose:h}){const{docs:m,setDocs:g,workspaces:v,setWorkspaces:b,assignedFiles:k,fetchDocs:w,fetchWorkspaces:S,scrollRef:N,markPendingDelete:T}=a8(r,i),M=l8(w,S,g,b,m,T),_=Od(),[A,O]=x.useState(()=>{try{const nt=localStorage.getItem("ow-sidebar-width");if(nt){const ht=parseInt(nt,10);if(!isNaN(ht)&&ht>=jk&&ht<=Ak)return ht}}catch{}return Lp}),B=x.useRef(!1),$=x.useCallback(nt=>{nt.preventDefault(),B.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none";const ht=ve=>{if(!B.current)return;const X=Math.min(Ak,Math.max(jk,ve.clientX));O(X)},Fe=()=>{B.current=!1,document.body.style.cursor="",document.body.style.userSelect="",window.removeEventListener("pointermove",ht),window.removeEventListener("pointerup",Fe);try{localStorage.setItem("ow-sidebar-width",String(W.current))}catch{}};window.addEventListener("pointermove",ht),window.addEventListener("pointerup",Fe)},[]),W=x.useRef(A);W.current=A;const J=x.useCallback(nt=>{g(ht=>ht.map(Fe=>({...Fe,isActive:Fe.filename===nt}))),e(nt)},[g,e]),[z,G]=x.useState(!1),[D,U]=x.useState(!1),[q,se]=x.useState([]),[V,re]=x.useState("Default"),K=x.useCallback(async()=>{try{const nt=await fetch("/api/profiles");if(nt.ok){const ht=await nt.json();se(ht.profiles),re(ht.active)}}catch{}},[]);x.useEffect(()=>{K()},[K]);const j=x.useCallback(async nt=>{try{(await fetch("/api/profiles/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&(re(nt),K())}catch{}},[K]),L=x.useCallback(async nt=>{try{(await fetch("/api/profiles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&K()}catch{}},[K]),[ee,he]=x.useState([]),ge=x.useCallback(async()=>{try{const nt=await fetch("/api/profiles/trash");if(nt.ok){const ht=await nt.json();he(ht.profiles)}}catch{}},[]);x.useEffect(()=>{ge()},[ge]);const oe=x.useCallback(async nt=>{try{(await fetch(`/api/profiles/${encodeURIComponent(nt)}`,{method:"DELETE"})).ok&&(K(),ge())}catch{}},[K,ge]),xe=x.useCallback(async nt=>{try{(await fetch("/api/profiles/restore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:nt})})).ok&&(K(),ge())}catch{}},[K,ge]),[we,We]=x.useState(""),[He,Ze]=x.useState(null),Oe=x.useRef(),Ke=x.useRef(null),mt=x.useCallback(nt=>{if(We(nt),Oe.current&&clearTimeout(Oe.current),!nt.trim()){Ze(null);return}Oe.current=setTimeout(async()=>{try{const ht=await fetch(`/api/documents/search?q=${encodeURIComponent(nt.trim())}&archived=true`);ht.ok&&Ze(await ht.json())}catch{}},250)},[]);x.useEffect(()=>()=>{Oe.current&&clearTimeout(Oe.current)},[]);const Ye={docs:m,archivedDocs:[],workspaces:v,assignedFiles:k,pendingDocs:o,writingTitle:l,writingTarget:d,pendingWriteFilenames:f,onSwitchDocument:J,onCreateDocument:n,actions:M,scrollRef:N,searchQuery:we,searchResults:He,onSearchChange:mt},pe=()=>{switch(_){case"files":return c.jsx(A8,{...Ye});case"timeline":return c.jsx(v8,{...Ye});case"board":return c.jsx(y8,{...Ye});case"shelf":return c.jsx(b8,{...Ye});default:return c.jsx(g8,{...Ye})}},gt=c.jsxs("div",{className:"sidebar-search",children:[c.jsxs("svg",{className:"sidebar-search-icon",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"10.5",cy:"10.5",r:"7"}),c.jsx("path",{d:"m20 20-4.5-4.5"})]}),c.jsx("input",{ref:Ke,className:"sidebar-search-input",type:"text",placeholder:"Search...",value:we,onChange:nt=>mt(nt.target.value)}),we&&c.jsx("button",{className:"sidebar-search-clear",onClick:()=>mt(""),title:"Clear search",children:"×"})]}),ft=t?{width:`${A}px`,minWidth:`${A}px`}:void 0,at=t?c.jsx("div",{className:"sidebar-resize-handle",onPointerDown:$,onDoubleClick:()=>{O(Lp);try{localStorage.setItem("ow-sidebar-width",String(Lp))}catch{}},title:"Drag to resize · double-click to reset"}):null;return _==="board"?c.jsxs("div",{className:`sidebar sidebar-board-mode ${t?"open":""}`,style:ft,children:[pe(),at]}):c.jsxs("div",{className:`sidebar ${t?"open":""}`,style:ft,children:[c.jsxs("div",{className:"sidebar-topbar",children:[c.jsxs("div",{className:"sidebar-logo",children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M17 3a2.83 2.83 0 0 1 4 4L7.5 20.5 2 22l1.5-5.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M15 5l4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),c.jsx("span",{className:"sidebar-logo-text",children:"OpenWriter"})]}),c.jsxs("div",{className:"sidebar-topbar-actions",children:[c.jsx(V8,{profiles:q,activeProfile:V,trashedProfiles:ee,onSwitch:j,onCreate:L,onDelete:oe,onRestore:xe}),c.jsx("button",{className:`sidebar-collapse-btn${z?" sidebar-collapse-btn--active":""}`,onClick:()=>{G(!z),U(!1)},title:"Schedule",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),c.jsx("line",{x1:"16",x2:"16",y1:"1",y2:"5"}),c.jsx("line",{x1:"8",x2:"8",y1:"1",y2:"5"}),c.jsx("line",{x1:"3",x2:"21",y1:"9",y2:"9"})]})}),c.jsx("button",{className:`sidebar-collapse-btn${D?" sidebar-collapse-btn--active":""}`,onClick:()=>{U(!D),G(!1)},title:"Tasks",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),c.jsx("path",{d:"m9 12 2 2 4-4"})]})}),h&&c.jsx("button",{className:"sidebar-collapse-btn",onClick:h,title:"Close sidebar",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M9 3v18",stroke:"currentColor",strokeWidth:"2"}),c.jsx("path",{d:"M15 10l-2 2 2 2",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})})]})]}),D?c.jsx(q8,{onBack:()=>U(!1)}):z?c.jsx(H8,{onBack:()=>G(!1)}):c.jsxs(c.Fragment,{children:[gt,pe()]}),at]})}function ay(t,e,n){let r=t.resolve(e);for(;r.depth>0;){const s=r.node(r.depth),i=r.before(r.depth),o=i+s.nodeSize;if(s.childCount===1)e=i,n=o,r=t.resolve(e);else break}return{from:e,to:n}}function K8(t,e){const n=Pn(t,e);if(!n)return!1;const{node:r,pos:s}=n;return t.chain().command(({tr:i})=>(i.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null}),!0)).run(),!0}function G8(t,e){const n=Pn(t,e);if(!n)return!1;const{node:r,pos:s}=n;return t.chain().command(({tr:i})=>(i.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null,pendingOriginalContent:null,pendingSelectionFrom:null,pendingSelectionTo:null,pendingOriginalFrom:null,pendingOriginalTo:null}),!0)).run(),!0}function J8(t,e){var o;const n=Pn(t,e);if(!n)return!1;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="delete")return!0;const i=ay(t.state.doc,s,s+r.nodeSize);return t.chain().deleteRange(i).run(),!0}function Y8(t,e){var o;const n=Pn(t,e);if(!n)return!0;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="insert")return!0;const i=ay(t.state.doc,s,s+r.nodeSize);return t.chain().deleteRange(i).run(),!0}function X8(t,e){var o,l;const n=Pn(t,e);if(!n)return!1;const{node:r,pos:s}=n;if(((o=r.attrs)==null?void 0:o.pendingStatus)!=="rewrite")return!0;const i=(l=r.attrs)==null?void 0:l.pendingOriginalContent;if(i)t.chain().deleteRange({from:s,to:s+r.nodeSize}).insertContentAt(s,i).run();else{const d=ay(t.state.doc,s,s+r.nodeSize);t.chain().deleteRange(d).run()}return!0}function Q8(t,e){var i;const n=Pn(t,e);if(!n)return!1;const{node:r,pos:s}=n;return((i=r.attrs)==null?void 0:i.pendingStatus)!=="delete"||t.chain().command(({tr:o})=>(o.setNodeMarkup(s,void 0,{...r.attrs,pendingStatus:null}),!0)).run(),!0}function Z8(t,e){const n=Xd(t,e);if(n.length===0)return!1;for(const r of[...n].reverse()){const s=Pn(t,r.nodeId);s&&t.chain().command(({tr:i})=>(i.setNodeMarkup(s.pos,void 0,{...s.node.attrs,pendingStatus:null,pendingOriginalContent:null,pendingGroupId:null,pendingSelectionFrom:null,pendingSelectionTo:null,pendingOriginalFrom:null,pendingOriginalTo:null}),!0)).run()}return!0}function e$(t,e){var l;const n=Xd(t,e);if(n.length===0)return!1;const r=(l=n[0].node.attrs)==null?void 0:l.pendingOriginalContent,s=n[0].pos,i=n[n.length-1],o=i.pos+i.node.nodeSize;try{return r&&Array.isArray(r)&&r.length>0?t.chain().deleteRange({from:s,to:o}).insertContentAt(s,r).run():t.chain().deleteRange({from:s,to:o}).run(),!0}catch{return!1}}function DT(t,e){var i,o;const n=Pn(t,e);if(!n)return!1;const r=(i=n.node.attrs)==null?void 0:i.pendingGroupId;if(r)return Z8(t,r);switch((o=n.node.attrs)==null?void 0:o.pendingStatus){case"insert":return K8(t,e);case"rewrite":return G8(t,e);case"delete":return J8(t,e);default:return!1}}function PT(t,e){var i,o;const n=Pn(t,e);if(!n)return!1;const r=(i=n.node.attrs)==null?void 0:i.pendingGroupId;if(r)return e$(t,r);switch((o=n.node.attrs)==null?void 0:o.pendingStatus){case"insert":return Y8(t,e);case"rewrite":return X8(t,e);case"delete":return Q8(t,e);default:return!1}}function t$(t){const e=BT(t).reverse();for(const n of e)DT(t,n);t.view&&sy(t.view)}function n$(t){const e=BT(t).reverse();for(const n of e)PT(t,n);t.view&&sy(t.view)}function ly(t){const e=[],n=new Set;return t.state.doc.descendants((r,s)=>{var o,l,d;const i=(o=r.attrs)==null?void 0:o.pendingStatus;if(i&&((l=r.attrs)!=null&&l.id)){const f=(d=r.attrs)==null?void 0:d.pendingGroupId;if(f){if(n.has(f))return!0;n.add(f)}e.push({nodeId:r.attrs.id,pos:s,pendingStatus:i,groupId:f,editor:t})}return!0}),e}function Dp(t){const e=[];for(const n of t)n&&!n.isDestroyed&&e.push(...ly(n));return e}function BT(t){return ly(t).map(e=>e.nodeId)}function r$(t){let e=0,n=0,r=0;for(const s of t)s.pendingStatus==="insert"?e++:s.pendingStatus==="rewrite"?n++:s.pendingStatus==="delete"&&r++;return{insert:e,rewrite:n,delete:r,total:t.length}}function Qa(t,e){if(t.isDestroyed)return;let n=-1;if(t.state.doc.descendants((i,o)=>{var l;return((l=i.attrs)==null?void 0:l.id)===e?(n=o,!1):!0}),n===-1)return;const r=t.view.nodeDOM(n),s=r instanceof HTMLElement?r:r==null?void 0:r.parentElement;if(s){s.scrollIntoView({behavior:"smooth",block:"center"});return}try{const i=t.view.coordsAtPos(n),o=t.view.dom.closest(".editor-container");if(o){const l=o.getBoundingClientRect(),d=i.top-l.top+o.scrollTop-o.clientHeight/2;o.scrollTo({top:d,behavior:"smooth"})}}catch{}}function s$(t){const[e,n]=x.useState([]),[r,s]=x.useState(0),i=x.useRef(),o=x.useRef(new Set),l=x.useCallback(()=>{const S=t.filter(A=>A&&!A.isDestroyed);if(S.length===0){n([]),o.current=new Set;return}const N=Dp(S);n(N);const T=o.current,M=new Set(N.map(A=>A.nodeId));let _=-1;if(T.size>0){for(let A=0;A<N.length;A++)if(!T.has(N[A].nodeId)){_=A;break}}o.current=M,_>=0?(s(_),Qa(N[_].editor,N[_].nodeId)):N.length===0?s(0):s(A=>Math.min(A,N.length-1))},[t]);x.useEffect(()=>{const S=t.filter(M=>M&&!M.isDestroyed);if(S.length===0)return;const N=()=>{clearTimeout(i.current),i.current=setTimeout(l,50)};for(const M of S)M.on("transaction",N);l();const T=setTimeout(()=>{const M=Dp(S.filter(_=>!_.isDestroyed));M.length>0&&Qa(M[0].editor,M[0].nodeId)},150);return()=>{for(const M of S)M.isDestroyed||M.off("transaction",N);clearTimeout(i.current),clearTimeout(T)}},[t,l]),x.useEffect(()=>{const S=e[r]??null;return sk((S==null?void 0:S.nodeId)??null,(S==null?void 0:S.groupId)??null),S!=null&&S.editor&&!S.editor.isDestroyed&&S.editor.view&&sy(S.editor.view),()=>{sk(null)}},[r,e]);const d=r$(e),f=e[r]??null,h=x.useCallback(()=>{if(e.length===0)return;const S=(r+1)%e.length;s(S),e[S]&&Qa(e[S].editor,e[S].nodeId)},[e,r]),m=x.useCallback(()=>{if(e.length===0)return;const S=(r-1+e.length)%e.length;s(S),e[S]&&Qa(e[S].editor,e[S].nodeId)},[e,r]),g=x.useCallback(()=>{const S=t.filter(M=>M&&!M.isDestroyed),N=Dp(S);if(N.length===0)return;const T=Math.min(r,N.length-1);Qa(N[T].editor,N[T].nodeId)},[t,r]),v=x.useCallback(()=>{f&&(DT(f.editor,f.nodeId),l(),g())},[f,l,g]),b=x.useCallback(()=>{f&&(PT(f.editor,f.nodeId),l(),g())},[f,l,g]),k=x.useCallback(()=>{const S=t.filter(N=>N&&!N.isDestroyed);for(const N of S)t$(N);l()},[t,l]),w=x.useCallback(()=>{const S=t.filter(N=>N&&!N.isDestroyed);for(const N of S)n$(N);l()},[t,l]);return{pendingNodes:e,counts:d,currentNode:f,currentIndex:r,hasPending:d.total>0,goToNext:h,goToPrevious:m,acceptCurrent:v,rejectCurrent:b,acceptAll:k,rejectAll:w,refresh:l}}const $T="ow-review-scope";function i$(){try{return localStorage.getItem($T)==="workspace"?"workspace":"all"}catch{return"all"}}function o$(t){try{localStorage.setItem($T,t)}catch{}}function zT(t){if(!t)return[];const e=[];for(const n of t)n.type==="doc"&&n.file&&e.push(n.file),n.type==="container"&&n.items&&e.push(...zT(n.items));return e}function FT(t,e){if(!t)return!1;for(const n of t)if(n.type==="doc"&&n.file===e||n.type==="container"&&n.items&&FT(n.items,e))return!0;return!1}const fa={strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"},a$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M10 3L5 8l5 5",stroke:"currentColor",...fa})}),l$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M6 3l5 5-5 5",stroke:"currentColor",...fa})}),c$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 10l5-5 5 5",stroke:"currentColor",...fa})}),u$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 6l5 5 5-5",stroke:"currentColor",...fa})}),Ok=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 8.5l3.5 3.5L13 5",stroke:"currentColor",...fa})}),Ik=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M4 4l8 8M12 4l-8 8",stroke:"currentColor",...fa})});function UT(t,e,n){const r=Pn(t,e);if(!r)return!1;const{pos:s,node:i}=r,o={type:n.type||i.type.name,attrs:{...n.attrs||{},id:i.attrs.id,pendingStatus:i.attrs.pendingStatus,pendingOriginalContent:i.attrs.pendingOriginalContent,pendingSelectionFrom:i.attrs.pendingSelectionFrom,pendingSelectionTo:i.attrs.pendingSelectionTo,pendingOriginalFrom:i.attrs.pendingOriginalFrom,pendingOriginalTo:i.attrs.pendingOriginalTo},content:n.content};try{return t.chain().command(({tr:l})=>(l.setMeta("addToHistory",!1),!0)).deleteRange({from:s,to:s+i.nodeSize}).insertContentAt(s,o).run(),!0}catch{return!1}}function HT(t,e,n){const r=Xd(t,e);if(r.length===0)return!1;const s=r[0].pos,i=r[r.length-1].pos+r[r.length-1].node.nodeSize;try{return t.chain().command(({tr:o})=>(o.setMeta("addToHistory",!1),!0)).deleteRange({from:s,to:i}).insertContentAt(s,n).run(),!0}catch{return!1}}function yu(t,e){if(!ry()||!e)return!1;const n=f5();return d5()&&n&&Array.isArray(n)?HT(t,e,n):n&&UT(t,e,n),sl(!1),!0}function d$(t,e){return t.indexOf(e)}function f$({editors:t,pendingDocs:e,currentFilename:n,docId:r,pendingTitle:s,onSwitchDocument:i,sendMessage:o,getDocument:l,docVersionRef:d}){const{counts:f,currentNode:h,currentIndex:m,hasPending:g,goToNext:v,goToPrevious:b,acceptCurrent:k,rejectCurrent:w,acceptAll:S,rejectAll:N}=s$(t),[T,M]=x.useState(s?"title":"body");x.useEffect(()=>{s&&T!=="title"&&f.total===0?M("title"):!s&&T==="title"&&M("body")},[s,f.total,T]);const _=!!s,A=f.total+(_?1:0),O=T==="title"?0:(_?1:0)+m,[B,$]=x.useState(!1);x.useEffect(()=>{T!=="title"&&$(!1)},[T]),x.useEffect(()=>{const Fe=!!s&&T==="title",ve={docId:r,titleFocused:Fe,titleShowOriginal:Fe&&B};return window.dispatchEvent(new CustomEvent("ow-pending-review-cursor",{detail:ve})),()=>{window.dispatchEvent(new CustomEvent("ow-pending-review-cursor",{detail:{docId:r,titleFocused:!1,titleShowOriginal:!1}}))}},[r,s,T,B]);const W=x.useCallback(()=>{r&&o({type:"accept-pending-title",docId:r})},[r,o]),J=x.useCallback(()=>{r&&o({type:"reject-pending-title",docId:r})},[r,o]),z=x.useRef(null),G=x.useRef(null),[D,U]=x.useState(()=>i$()),[q,se]=x.useState([]);x.useEffect(()=>{let Fe=!1;async function ve(){try{const te=await(await fetch("/api/workspaces")).json();if(!Array.isArray(te))return;const de=await Promise.all(te.map(async fe=>{try{const Le=await(await fetch(`/api/workspaces/${encodeURIComponent(fe.filename)}`)).json();return{...fe,workspace:Le}}catch{return fe}}));Fe||se(de)}catch{}}ve();const X=()=>ve();return window.addEventListener("ow-workspaces-changed",X),()=>{Fe=!0,window.removeEventListener("ow-workspaces-changed",X)}},[]);const V=x.useMemo(()=>{var ve;if(q.length===0||!n)return null;const Fe=q.find(X=>{var Be;return FT((Be=X.workspace)==null?void 0:Be.root,n)});return Fe?new Set(zT((ve=Fe.workspace)==null?void 0:ve.root)):null},[q,n]),re=x.useMemo(()=>D==="all"||!V?e.filenames:e.filenames.filter(Fe=>V.has(Fe)),[D,e.filenames,V]),K=x.useCallback(Fe=>{U(Fe),o$(Fe)},[]),j=re.length,L=d$(re,n),ee=(h==null?void 0:h.pendingStatus)==="rewrite",he=!!(h!=null&&h.groupId),ge=ee,oe=x.useCallback(()=>{var ve,X;const Fe=h==null?void 0:h.editor;if(!(!Fe||!h||h.pendingStatus!=="rewrite"))if(B)G.current&&yu(G.current,z.current),z.current=null,G.current=null,$(!1);else if(he&&h.groupId){const Be=Xd(Fe,h.groupId);if(Be.length===0)return;const te=(ve=Be[0].node.attrs)==null?void 0:ve.pendingOriginalContent;if(!te||!Array.isArray(te))return;const de=Be.map(Le=>Le.node.toJSON()),fe=te.map((Le,et)=>({...Le,attrs:{...Le.attrs||{},pendingStatus:"rewrite",pendingGroupId:h.groupId,...et===0?{pendingOriginalContent:te}:{}}}));if(sl(!0,h.nodeId,de,h.groupId),!HT(Fe,h.groupId,fe)){sl(!1);return}z.current=h.nodeId,G.current=Fe,$(!0)}else{const Be=Pn(Fe,h.nodeId);if(!Be)return;const{node:te}=Be,de=(X=te.attrs)==null?void 0:X.pendingOriginalContent;if(!de)return;const fe=te.toJSON();if(sl(!0,h.nodeId,fe),!UT(Fe,h.nodeId,de)){sl(!1);return}z.current=h.nodeId,G.current=Fe,$(!0)}},[h,B,he]);x.useEffect(()=>{if(!B)return;const Fe=z.current,ve=G.current;Fe&&ve&&(h==null?void 0:h.nodeId)!==Fe&&(yu(ve,Fe),z.current=null,G.current=null,$(!1))},[h==null?void 0:h.nodeId,B]),x.useEffect(()=>{if(t.length!==0)return()=>{ry()&&z.current&&G.current&&(yu(G.current,z.current),z.current=null,G.current=null)}},[t]);const xe=x.useCallback(Fe=>{if(!n)return;if(!t.some(X=>!X||X.isDestroyed?!1:ly(X).length>0)){const X=l==null?void 0:l();X&&o({type:"doc-update",document:X,filename:n,version:(d==null?void 0:d.current)??0}),o({type:"pending-resolved",filename:n,action:Fe})}},[t,n,o,l,d]),we=x.useCallback(()=>{G.current&&B&&z.current&&(yu(G.current,z.current),z.current=null,G.current=null,$(!1))},[B]),We=x.useCallback(()=>{if(T==="title"&&s){W(),f.total>0&&M("body");return}we(),k(),xe("accept")},[T,s,W,f.total,we,k,xe]),He=x.useCallback(()=>{if(T==="title"&&s){J(),f.total>0&&M("body");return}we(),w(),xe("reject")},[T,s,J,f.total,we,w,xe]),Ze=x.useCallback(()=>{we(),s&&W(),S(),xe("accept")},[we,s,W,S,xe]);x.useEffect(()=>{const Fe=()=>Ze();return window.addEventListener("ow-accept-all",Fe),()=>window.removeEventListener("ow-accept-all",Fe)},[Ze]);const Oe=x.useCallback(()=>{we(),s&&J(),N(),xe("reject")},[we,s,J,N,xe]),Ke=x.useCallback(()=>{if(!(A<=1)){if(T==="title"){M("body");return}if(_&&m>=f.total-1){v(),M("title");return}v()}},[A,T,_,m,f.total,v]),mt=x.useCallback(()=>{if(!(A<=1)){if(T==="title"){b(),M("body");return}if(_&&m===0){M("title");return}b()}},[A,T,_,m,b]),Ye=x.useCallback(()=>{if(j===0||j===1&&L===0)return;const Fe=L<=0?j-1:L-1;i(re[Fe])},[j,L,re,i]),pe=x.useCallback(()=>{if(j===0||j===1&&L===0)return;const Fe=L>=j-1?0:L+1;i(re[Fe])},[j,L,re,i]);x.useEffect(()=>{if(!g&&!s)return;const Fe=ve=>{if(!(ve.target instanceof HTMLInputElement||ve.target instanceof HTMLTextAreaElement)&&!(ve.target instanceof HTMLElement&&ve.target.closest("[contenteditable]")))switch(ve.key){case"j":case"ArrowDown":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Ke());break;case"k":case"ArrowUp":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),mt());break;case"h":case"ArrowLeft":!ve.metaKey&&!ve.ctrlKey&&!ve.altKey&&(ve.preventDefault(),Ye());break;case"l":case"ArrowRight":!ve.metaKey&&!ve.ctrlKey&&!ve.altKey&&(ve.preventDefault(),pe());break;case"a":!ve.metaKey&&!ve.ctrlKey&&!ve.shiftKey&&(ve.preventDefault(),We());break;case"r":!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),He());break;case"A":ve.shiftKey&&!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Ze());break;case"R":ve.shiftKey&&!ve.metaKey&&!ve.ctrlKey&&(ve.preventDefault(),Oe());break;case"o":!ve.metaKey&&!ve.ctrlKey&&!ve.shiftKey&&(ve.preventDefault(),T==="title"?$(X=>!X):oe());break}};return window.addEventListener("keydown",Fe),()=>window.removeEventListener("keydown",Fe)},[g,s,Ke,mt,Ye,pe,We,He,Ze,Oe,oe]);const gt=L>=0?`${L+1} / ${j}`:`— / ${j}`,ft=e.filenames.length,at=!V,ht=ft>0?c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:"Scope"}),c.jsxs("div",{className:"review-tab__toggle",children:[c.jsx("button",{type:"button",className:`review-panel__toggle-btn${D==="all"?" review-panel__toggle-btn--active":""}`,onClick:()=>K("all"),title:"Cycle every pending doc in the profile",children:"All"}),c.jsx("button",{type:"button",className:`review-panel__toggle-btn${D==="workspace"?" review-panel__toggle-btn--active":""}`,onClick:()=>!at&&K("workspace"),disabled:at,title:at?"Current doc is not in a workspace":"Only cycle pending docs in this workspace",children:"Workspace"})]})]}):null;return!g&&!s?c.jsxs("div",{className:"review-tab__empty",children:[c.jsx("div",{className:"review-tab__empty-title",children:"All caught up"}),c.jsx("div",{className:"review-tab__empty-note",children:"No pending agent changes. New writes from agents will land here for review."})]}):c.jsxs("div",{className:"review-tab",children:[ht,j>1&&c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:"Document"}),c.jsxs("div",{className:"review-tab__row",children:[c.jsx("button",{className:"review-panel__btn",onClick:Ye,title:"Previous doc (h)",children:c.jsx(a$,{})}),c.jsx("span",{className:"review-panel__counter",children:gt}),c.jsx("button",{className:"review-panel__btn",onClick:pe,title:"Next doc (l)",children:c.jsx(l$,{})})]})]}),c.jsxs("div",{className:"review-tab__section",children:[c.jsx("div",{className:"review-tab__section-label",children:T==="title"?"Title":"Change"}),c.jsxs("div",{className:"review-tab__row",children:[c.jsx("button",{className:"review-panel__btn",onClick:mt,disabled:A<=1,title:"Previous (k)",children:c.jsx(c$,{})}),c.jsxs("span",{className:"review-panel__counter",children:[O+1," / ",A]}),c.jsx("button",{className:"review-panel__btn",onClick:Ke,disabled:A<=1,title:"Next (j)",children:c.jsx(u$,{})})]})]}),c.jsx("div",{className:"review-tab__section",children:c.jsxs("div",{className:"review-tab__toggle",children:[c.jsx("button",{className:`review-panel__toggle-btn${(ge||T==="title")&&!B?" review-panel__toggle-btn--active":""}`,onClick:()=>{T==="title"?B&&$(!1):ge&&B&&oe()},disabled:!ge&&T!=="title",title:"Show modified (o)",children:"Modified"}),c.jsx("button",{className:`review-panel__toggle-btn${(ge||T==="title")&&B?" review-panel__toggle-btn--active":""}`,onClick:()=>{T==="title"?B||$(!0):ge&&!B&&oe()},disabled:!ge&&T!=="title",title:"Show original (o)",children:"Original"})]})}),c.jsxs("div",{className:"review-tab__section review-tab__section--actions",children:[c.jsxs("div",{className:"review-tab__row",children:[c.jsxs("button",{className:"review-panel__accept review-tab__action-btn",onClick:We,title:"Accept (a)",children:[c.jsx(Ok,{}),c.jsx("span",{children:"Accept"})]}),c.jsxs("button",{className:"review-panel__reject review-tab__action-btn",onClick:He,title:"Reject (r)",children:[c.jsx(Ik,{}),c.jsx("span",{children:"Reject"})]})]}),c.jsxs("div",{className:"review-tab__row",children:[c.jsxs("button",{className:"review-panel__accept-all review-tab__action-btn",onClick:Ze,title:"Accept all (Shift+A)",children:[c.jsx(Ok,{}),c.jsx("span",{children:"Accept All"})]}),c.jsxs("button",{className:"review-panel__reject-all review-tab__action-btn",onClick:Oe,title:"Reject all (Shift+R)",children:[c.jsx(Ik,{}),c.jsx("span",{children:"Reject All"})]})]})]})]})}function h$(t){const e=Date.now()-t,n=Math.floor(e/1e3);if(n<60)return"Just now";const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const s=Math.floor(r/60);if(s<24)return`${s}h ago`;const i=Math.floor(s/24);return i<7?`${i}d ago`:new Date(t).toLocaleDateString()}function p$(t){return t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`}function m$({currentFilename:t}){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(!1),l=x.useCallback(()=>{fetch("/api/versions").then(f=>f.json()).then(f=>{n(Array.isArray(f)?f:[]),s(null)}).catch(()=>n([]))},[]);x.useEffect(()=>{l()},[t,l]);const d=x.useCallback(async f=>{if(r!==null){o(!0);try{(await fetch(`/api/versions/${r}/restore`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:f})})).ok&&l()}catch{}o(!1)}},[r,l]);return c.jsxs("div",{className:"versions-tab",children:[c.jsx("div",{className:"versions-tab__list",children:e.length===0?c.jsx("div",{className:"versions-tab__empty",children:"No versions yet. Versions are created automatically when you save."}):e.map(f=>c.jsxs("div",{className:`versions-tab__item${r===f.timestamp?" versions-tab__item--selected":""}`,onClick:()=>s(f.timestamp===r?null:f.timestamp),children:[c.jsx("span",{className:"versions-tab__item-time",children:h$(f.timestamp)}),c.jsxs("span",{className:"versions-tab__item-meta",children:[f.wordCount.toLocaleString()," words · ",p$(f.size)]})]},f.timestamp))}),e.length>0&&c.jsxs("div",{className:"versions-tab__footer",children:[c.jsx("button",{className:"versions-tab__review-btn",disabled:r===null||i,onClick:()=>d("review"),children:"Review"}),c.jsx("button",{className:"versions-tab__restore-btn",disabled:r===null||i,onClick:()=>d("full"),children:"Restore"})]})]})}function g$({docId:t,currentFilename:e,onSwitchDocument:n}){const[r,s]=x.useState(new Map),[i,o]=x.useState([]),[l,d]=x.useState([]),[f,h]=x.useState(!0),[m,g]=x.useState(!1);x.useEffect(()=>{let w=!1;const S=async()=>{try{const M=await(await fetch("/api/documents")).json();if(w)return;const _=new Map;if(Array.isArray(M))for(const A of M)A!=null&&A.docId&&_.set(A.docId,{docId:A.docId,filename:A.filename,title:A.title||A.filename});s(_)}catch{}finally{w||h(!1)}};S();const N=()=>S();return window.addEventListener("ow-documents-changed",N),()=>{w=!0,window.removeEventListener("ow-documents-changed",N)}},[]),x.useEffect(()=>{if(!t){o([]);return}let w=!1;const S=()=>{g(!0),fetch(`/api/backlinks/${t}`).then(T=>T.ok?T.json():[]).then(T=>{w||o(Array.isArray(T)?T:[])}).catch(()=>{w||o([])}).finally(()=>{w||g(!1)})};S();const N=()=>S();return window.addEventListener("ow-metadata-changed",N),()=>{w=!0,window.removeEventListener("ow-metadata-changed",N)}},[t]),x.useEffect(()=>{let w=!1;const S=()=>{fetch("/api/document").then(T=>T.json()).then(T=>{var _;if(w)return;const M=(_=T==null?void 0:T.metadata)==null?void 0:_.references;d(Array.isArray(M)?M:[])}).catch(()=>{w||d([])})};S();const N=()=>S();return window.addEventListener("ow-metadata-changed",N),()=>{w=!0,window.removeEventListener("ow-metadata-changed",N)}},[e,t]);const v=x.useMemo(()=>i.map(w=>{const S=r.get(w.from_doc);return S?{docId:w.from_doc,title:S.title,filename:S.filename,snippet:w.text}:null}).filter(w=>w!==null),[i,r]),b=x.useMemo(()=>l.map(w=>{const S=r.get(w);return S?{docId:w,title:S.title,filename:S.filename}:null}).filter(w=>w!==null),[l,r]);if(!t)return c.jsxs("div",{className:"backlinks-tab__empty",children:[c.jsx("div",{className:"backlinks-tab__empty-title",children:"No document open"}),c.jsx("div",{className:"backlinks-tab__empty-note",children:"Open a doc to see what links to it and what it links out to."})]});const k=f||m;return c.jsxs("div",{className:"backlinks-tab",children:[c.jsxs("div",{className:"backlinks-tab__group",children:[c.jsxs("div",{className:"backlinks-tab__group-label",children:["Inbound ",c.jsx("span",{className:"backlinks-tab__count",children:v.length})]}),k&&v.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"Loading…"}):v.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"No docs link to this one yet."}):v.map(w=>c.jsxs("button",{type:"button",className:"backlinks-tab__entry",onClick:()=>n(w.filename),children:[c.jsx("div",{className:"backlinks-tab__entry-title",children:w.title}),w.snippet&&c.jsx("div",{className:"backlinks-tab__entry-snippet",children:w.snippet})]},w.docId))]}),c.jsxs("div",{className:"backlinks-tab__group",children:[c.jsxs("div",{className:"backlinks-tab__group-label",children:["Outbound ",c.jsx("span",{className:"backlinks-tab__count",children:b.length})]}),b.length===0?c.jsx("div",{className:"backlinks-tab__empty-note backlinks-tab__inline-note",children:"This doc doesn’t reference others yet."}):b.map(w=>c.jsx("button",{type:"button",className:"backlinks-tab__entry",onClick:()=>n(w.filename),children:c.jsx("div",{className:"backlinks-tab__entry-title",children:w.title})},w.docId))]})]})}const v$=[{key:"md",label:"Markdown",desc:"Plain .md file",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("path",{d:"M14 2v6h6"})]})},{key:"html",label:"HTML",desc:"Styled web page",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"16 18 22 12 16 6"}),c.jsx("polyline",{points:"8 6 2 12 8 18"})]})},{key:"docx",label:"Word",desc:"Microsoft Word .docx",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("path",{d:"M14 2v6h6"}),c.jsx("path",{d:"M16 13H8"}),c.jsx("path",{d:"M16 17H8"}),c.jsx("path",{d:"M10 9H8"})]})},{key:"txt",label:"Plain Text",desc:"Unformatted .txt file",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 6.1H3"}),c.jsx("path",{d:"M21 12.1H3"}),c.jsx("path",{d:"M15.1 18H3"})]})},{key:"pdf",label:"PDF",desc:"Print preview for save as PDF",icon:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"6 9 6 2 18 2 18 9"}),c.jsx("path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),c.jsx("rect",{x:"6",y:"14",width:"12",height:"8"})]})}];function y$(t){const e=n=>{if(n==="pdf"){window.open("/api/export?format=pdf","_blank");return}const r=document.createElement("a");r.href=`/api/export?format=${n}`,r.download="",document.body.appendChild(r),r.click(),document.body.removeChild(r)};return c.jsx("div",{className:"exports-tab",children:c.jsx("div",{className:"exports-tab__list",children:v$.map(n=>c.jsxs("button",{type:"button",className:"exports-tab__item",onClick:()=>e(n.key),children:[c.jsx("span",{className:"exports-tab__item-icon",children:n.icon}),c.jsxs("span",{className:"exports-tab__item-text",children:[c.jsx("span",{className:"exports-tab__item-label",children:n.label}),c.jsx("span",{className:"exports-tab__item-desc",children:n.desc})]})]},n.key))})})}const b$=3e4,x$=500;let mi={entries:[],freshKeys:new Set};const Zg=new Set;function WT(t){return`${t.ts}:${t.kind}:${t.headline}`}function w$(){for(const t of Zg)t(mi)}function ev(t){mi=t,w$()}function k$(t){return Zg.add(t),()=>{Zg.delete(t)}}function S$(){return mi}function E$(t){const e=t.detail;e!=null&&e.entries&&ev({entries:e.entries,freshKeys:new Set})}function N$(t){const e=t.detail;if(!(e!=null&&e.event))return;const n=e.event,r=WT(n),s={entries:[n,...mi.entries].slice(0,x$),freshKeys:new Set([...mi.freshKeys,r])};ev(s),window.setTimeout(()=>{if(mi.freshKeys.has(r)){const i=new Set(mi.freshKeys);i.delete(r),ev({...mi,freshKeys:i})}},b$)}typeof window<"u"&&(window.addEventListener("ow-activity-seed",E$),window.addEventListener("ow-activity-event",N$));function C$(){const[t,e]=x.useState(S$);return x.useEffect(()=>k$(e),[]),t}function _$(){const[t,e]=x.useState(()=>({byDocId:new Map,filenameSet:new Set}));return x.useEffect(()=>{let n=!1;const r=()=>{fetch("/api/documents").then(s=>s.json()).then(s=>{if(n||!Array.isArray(s))return;const i=new Map,o=new Set;for(const l of s)l.filename&&o.add(l.filename),l.docId&&l.filename&&i.set(l.docId,l.filename);e({byDocId:i,filenameSet:o})}).catch(()=>{})};return r(),window.addEventListener("ow-documents-changed",r),()=>{n=!0,window.removeEventListener("ow-documents-changed",r)}},[]),t}function T$(t,e){return t.docId?e.byDocId.get(t.docId)??null:t.filename&&e.filenameSet.has(t.filename)?t.filename:null}function M$(t,e){const n=Math.max(0,e-t),r=Math.floor(n/1e3);if(r<45)return"just now";const s=Math.floor(r/60);if(s<60)return`${s}m ago`;const i=Math.floor(s/60);if(i<24)return`${i}h ago`;const o=Math.floor(i/24);return o<7?`${o}d ago`:new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function j$({onSwitchDocument:t}){const{entries:e,freshKeys:n}=C$(),r=_$(),[s,i]=x.useState(()=>Date.now());x.useEffect(()=>{const l=setInterval(()=>i(Date.now()),3e4);return()=>clearInterval(l)},[]);const o=x.useMemo(()=>A$(e,s),[e,s]);return e.length===0?c.jsxs("div",{className:"activity-tab__empty",children:[c.jsx("div",{className:"activity-tab__empty-title",children:"No activity yet"}),c.jsx("div",{className:"activity-tab__empty-note",children:"Agent actions — writes, enrichment, backlink propagation — will appear here as they happen."})]}):c.jsx("div",{className:"activity-tab",children:o.map(l=>c.jsxs("div",{className:"activity-tab__group",children:[c.jsx("div",{className:"activity-tab__group-label",children:l.label}),l.entries.map(d=>{const f=WT(d),h=n.has(f),m=d.kind==="doc-deleted"?null:T$(d,r),g=m!==null,v=!g,b=v&&d.kind!=="doc-deleted"?"Doc no longer available":void 0,k=()=>{m&&t(m)};return c.jsxs("div",{className:`activity-tab__entry${h?" activity-tab__entry--fresh":""}${g?" activity-tab__entry--clickable":""}${v?" activity-tab__entry--muted":""}`,role:g?"button":void 0,tabIndex:g?0:void 0,title:b,onClick:k,onKeyDown:w=>{g&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),k())},children:[c.jsx("span",{className:`activity-tab__kind-dot activity-tab__kind-dot--${d.kind}`,"aria-hidden":"true"}),c.jsxs("div",{className:"activity-tab__entry-body",children:[c.jsx("div",{className:"activity-tab__headline",children:d.headline}),d.detail&&c.jsx("div",{className:"activity-tab__detail",children:d.detail})]}),c.jsx("div",{className:"activity-tab__ts",title:new Date(d.ts).toLocaleString(),children:M$(d.ts,s)})]},f)})]},l.label))})}function A$(t,e){if(t.length===0)return[];const n=Lk(e),r=n-1440*60*1e3,s=[];let i=null;for(const o of t){const l=Lk(o.ts);let d;l===n?d="Today":l===r?d="Yesterday":d=new Date(o.ts).toLocaleDateString(void 0,{weekday:"long",month:"short",day:"numeric"}),(!i||i.label!==d)&&(i={label:d,entries:[]},s.push(i)),i.entries.push(o)}return s}function Lk(t){const e=new Date(t);return e.setHours(0,0,0,0),e.getTime()}async function bu(t,e={}){var s,i;const r=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:t,arguments:e})})).json();if((i=(s=r==null?void 0:r.content)==null?void 0:s[0])!=null&&i.text)try{return JSON.parse(r.content[0].text)}catch{return r.content[0].text}return r}function R$(){const[t,e]=x.useState([]),[n,r]=x.useState(!0),[s,i]=x.useState("closed"),[o,l]=x.useState(""),[d,f]=x.useState(!1),[h,m]=x.useState(null),[g,v]=x.useState(null),[b,k]=x.useState(null),w=x.useCallback(async()=>{r(!0);try{const _=await bu("list_blog_sites");e((_==null?void 0:_.sites)||[])}finally{r(!1)}},[]);x.useEffect(()=>{w()},[w]);const S=()=>{i("closed"),l(""),m(null),v(null),k(null)},N=async()=>{if(o.trim()){f(!0),m(null);try{const _=await bu("inspect_blog_repo",{repo_url:o.trim()});if(_.error){m(_.error);return}v({..._,label:_.repo,branch:"main",site_url:_.site_url||"",blog_url_pattern:_.blog_url_pattern||"/blog/{slug}/"}),i("review")}catch(_){m((_==null?void 0:_.message)||"Inspection failed")}finally{f(!1)}}},T=async()=>{if(g){i("saving"),k(null);try{const _=await bu("add_blog_site",{label:g.label,owner:g.owner,repo:g.repo,branch:g.branch||"main",content_dir:g.content_dir,image_dir:g.image_dir,image_public_prefix:g.image_public_prefix,framework:g.framework,frontmatter_defaults:g.frontmatter_defaults||{},frontmatter_field_map:g.frontmatter_field_map||{},frontmatter_schema:g.frontmatter_schema||[],site_url:g.site_url||"",blog_url_pattern:g.blog_url_pattern||"/blog/{slug}/"});if(_!=null&&_.error){k(_.error),i("review");return}S(),await w()}catch(_){k((_==null?void 0:_.message)||"Save failed"),i("review")}}},M=async _=>{if(!window.confirm(`Remove "${_.label}" (${_.owner}/${_.repo})?
|
|
208
208
|
|
|
209
|
-
This only removes the OpenWriter registration. Your GitHub repo is untouched.`))return;const O=await bu("remove_blog_site",{id:_.id});if(O!=null&&O.error){alert(`Remove failed: ${O.error}`);return}await w()};return c.jsxs("div",{className:"github-plugin-settings",children:[c.jsxs("div",{className:"github-plugin-settings__header",children:[c.jsx("span",{className:"github-plugin-settings__title",children:"Blog repos"}),s==="closed"&&c.jsx("button",{className:"github-plugin-settings__add-btn",onClick:()=>i("url"),children:"+ Add"})]}),n?c.jsx("div",{className:"github-plugin-settings__loading",children:"Loading…"}):t.length===0&&s==="closed"?c.jsxs("div",{className:"github-plugin-settings__empty",children:["Connect a GitHub repo to publish blog posts via local git — no PATs, no Workers. Uses your existing ",c.jsx("code",{children:"gh auth login"}),"."]}):c.jsx("div",{className:"github-plugin-settings__list",children:t.map(_=>c.jsxs("div",{className:"github-plugin-settings__site",children:[c.jsxs("div",{className:"github-plugin-settings__site-info",children:[c.jsxs("div",{className:"github-plugin-settings__site-row1",children:[c.jsx("span",{className:"github-plugin-settings__site-label",children:_.label}),c.jsx("span",{className:`github-plugin-settings__site-framework github-plugin-settings__site-framework--${_.framework}`,children:_.framework})]}),c.jsxs("div",{className:"github-plugin-settings__site-repo",children:[_.owner,"/",_.repo,"@",_.branch]}),c.jsxs("div",{className:"github-plugin-settings__site-dirs",children:[c.jsx("span",{title:"content_dir",children:_.content_dir}),c.jsx("span",{className:"github-plugin-settings__site-sep",children:"·"}),c.jsx("span",{title:"image_public_prefix",children:_.image_public_prefix})]})]}),c.jsx("button",{className:"github-plugin-settings__remove-btn",onClick:()=>M(_),title:"Remove",children:"×"})]},_.id))}),s==="url"&&c.jsxs("div",{className:"github-plugin-settings__form",children:[c.jsx("label",{className:"github-plugin-settings__label",children:"GitHub repo"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"owner/repo or https://github.com/owner/repo",value:o,onChange:_=>l(_.target.value),onKeyDown:_=>{_.key==="Enter"&&!d&&N()},autoFocus:!0}),h&&c.jsx("div",{className:"github-plugin-settings__error",children:h}),c.jsxs("div",{className:"github-plugin-settings__form-buttons",children:[c.jsx("button",{className:"github-plugin-settings__btn github-plugin-settings__btn--primary",onClick:N,disabled:d||!o.trim(),children:d?"Inspecting…":"Inspect"}),c.jsx("button",{className:"github-plugin-settings__btn",onClick:S,disabled:d,children:"Cancel"})]})]}),(s==="review"||s==="saving")&&g&&c.jsxs("div",{className:"github-plugin-settings__form",children:[c.jsxs("div",{className:"github-plugin-settings__form-meta",children:[c.jsxs("span",{children:["Detected: ",g.framework]}),c.jsx("span",{children:"·"}),c.jsxs("span",{children:[g.markdown_files_found," posts"]}),c.jsx("span",{children:"·"}),c.jsxs("span",{className:`github-plugin-settings__confidence github-plugin-settings__confidence--${g.confidence}`,children:[g.confidence," confidence"]})]}),c.jsx("label",{className:"github-plugin-settings__label",children:"Label"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.label,onChange:_=>v({...g,label:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Branch"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.branch,onChange:_=>v({...g,branch:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Content directory"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.content_dir,onChange:_=>v({...g,content_dir:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Image directory"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.image_dir,onChange:_=>v({...g,image_dir:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Image public prefix"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.image_public_prefix,onChange:_=>v({...g,image_public_prefix:_.target.value})}),c.jsxs("label",{className:"github-plugin-settings__label",children:["Site URL ",c.jsx("span",{className:"github-plugin-settings__hint",children:"— optional, used for the live link after publish"})]}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"https://example.com",value:g.site_url||"",onChange:_=>v({...g,site_url:_.target.value})}),c.jsxs("label",{className:"github-plugin-settings__label",children:["Blog URL pattern ",c.jsxs("span",{className:"github-plugin-settings__hint",children:["— uses ","{slug}"," placeholder"]})]}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"/blog/{slug}/",value:g.blog_url_pattern||"",onChange:_=>v({...g,blog_url_pattern:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Framework"}),c.jsxs("select",{className:"github-plugin-settings__input",value:g.framework,onChange:_=>v({...g,framework:_.target.value}),children:[c.jsx("option",{value:"astro",children:"Astro"}),c.jsx("option",{value:"next",children:"Next"}),c.jsx("option",{value:"jekyll",children:"Jekyll"}),c.jsx("option",{value:"hugo",children:"Hugo"}),c.jsx("option",{value:"unknown",children:"Unknown"})]}),g.frontmatter_schema.length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsxs("span",{className:"github-plugin-settings__label",children:["Frontmatter keys detected (",g.samples_analyzed," ",g.samples_analyzed===1?"sample":"samples",")"]}),c.jsx("code",{children:g.frontmatter_schema.join(", ")})]}),Object.keys(g.frontmatter_defaults||{}).length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsx("span",{className:"github-plugin-settings__label",children:"Frontmatter defaults (constants applied to every post)"}),c.jsx("code",{children:Object.entries(g.frontmatter_defaults).map(([_,A])=>c.jsxs("div",{children:[_,": ",typeof A=="string"?A:JSON.stringify(A)]},_))})]}),Object.keys(g.frontmatter_field_map||{}).length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsx("span",{className:"github-plugin-settings__label",children:"Field name mapping (openwriter → site)"}),c.jsx("code",{children:Object.entries(g.frontmatter_field_map).map(([_,A])=>c.jsxs("div",{children:[_," → ",A]},_))})]}),b&&c.jsx("div",{className:"github-plugin-settings__error",children:b}),c.jsxs("div",{className:"github-plugin-settings__form-buttons",children:[c.jsx("button",{className:"github-plugin-settings__btn github-plugin-settings__btn--primary",onClick:T,disabled:s==="saving"||!g.label.trim(),children:s==="saving"?"Saving…":"Add site"}),c.jsx("button",{className:"github-plugin-settings__btn",onClick:S,disabled:s==="saving",children:"Cancel"})]})]})]})}const O$={none:"No Plan",free:"No Plan",creator:"Creator — $19/mo",growth:"Growth — $49/mo",publisher:"Publisher — $79/mo"},I$=[{plan:"creator",label:"Creator $19/mo"},{plan:"growth",label:"Growth $49/mo"}];function L$(){var d,f;const[t,e]=x.useState(null),[n,r]=x.useState(!0);x.useEffect(()=>{fetch("/api/billing").then(h=>h.json()).then(h=>e(h)).catch(()=>{}).finally(()=>r(!1))},[]);const s=x.useCallback(async h=>{const m=await fetch("/api/billing/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plan:h})});if(m.ok){const g=await m.json();g.url&&window.open(g.url,"_blank")}},[]),i=x.useCallback(async()=>{const h=await fetch("/api/billing/portal",{method:"POST",headers:{"Content-Type":"application/json"}});if(h.ok){const m=await h.json();m.url&&window.open(m.url,"_blank")}},[]);if(n)return c.jsx("div",{className:"billing-section",children:c.jsx("div",{className:"billing-loading",children:"Loading..."})});if(!(t!=null&&t.authenticated))return null;const o=t.plan||"free",l=I$.filter(h=>{const m=["free","creator","growth","publisher"];return m.indexOf(h.plan)>m.indexOf(o)});return c.jsxs("div",{className:"billing-section",children:[c.jsxs("div",{className:"billing-plan",children:[c.jsx("span",{className:"billing-plan-label",children:"Plan"}),c.jsx("span",{className:`billing-plan-badge billing-plan-badge--${o}`,children:O$[o]||o})]}),((d=t.billing)==null?void 0:d.paymentFailed)&&c.jsx("div",{className:"billing-warning",children:"Payment failed — update card to keep your plan."}),l.length>0&&c.jsx("div",{className:"billing-upgrades",children:l.map(h=>c.jsxs("button",{className:"billing-upgrade-btn",onClick:()=>s(h.plan),children:["Upgrade to ",h.label]},h.plan))}),((f=t.billing)==null?void 0:f.hasPaymentMethod)&&c.jsx("button",{className:"billing-manage-btn",onClick:i,children:"Manage Billing"})]})}function Dk(t){return t.replace(/^@openwriter\/plugin-/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function D$({status:t}){return t==="saving"?c.jsx("span",{className:"plugin-config-status plugin-config-status--saving",children:"Saving…"}):t==="saved"?c.jsxs("span",{className:"plugin-config-status plugin-config-status--saved",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#22c55e",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Saved"]}):t==="error"?c.jsxs("span",{className:"plugin-config-status plugin-config-status--error",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#ef4444",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),"Failed"]}):null}function P$(t){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(new Set),[l,d]=x.useState({}),f=x.useCallback(()=>{fetch("/api/available-plugins").then(g=>g.json()).then(g=>n(g.plugins||[])).catch(()=>{})},[]);x.useEffect(()=>{f()},[f]),x.useEffect(()=>{const g=()=>f();return window.addEventListener("ow-plugins-changed",g),()=>window.removeEventListener("ow-plugins-changed",g)},[f]);const h=x.useCallback(async(g,v)=>{s(g);try{(await fetch(v?"/api/plugins/disable":"/api/plugins/enable",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:g})})).ok&&f()}catch{}finally{s(null)}},[f]),m=x.useCallback(async(g,v,b)=>{const k=`${g}:${v}`;d(w=>({...w,[k]:"saving"}));try{const w=await fetch("/api/plugins/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:g,config:{[v]:b}})});if(!w.ok)throw new Error(`save failed (${w.status})`);d(S=>({...S,[k]:"saved"})),setTimeout(()=>{d(S=>S[k]==="saved"?{...S,[k]:"idle"}:S)},2e3)}catch{d(w=>({...w,[k]:"error"}))}},[]);return c.jsx("div",{className:"plugins-tab",children:e.length===0?c.jsx("div",{className:"plugin-empty",children:"No plugins found"}):e.map(g=>c.jsxs("div",{className:"plugin-item",children:[c.jsxs("div",{className:"plugin-item-header",children:[c.jsxs("div",{className:"plugin-item-info",children:[c.jsxs("div",{className:"plugin-item-name",children:[Dk(g.name),c.jsxs("span",{className:"plugin-item-version",children:["v",g.version]})]}),g.description&&c.jsx("div",{className:"plugin-item-desc",children:g.description})]}),c.jsxs("label",{className:`plugin-toggle${r===g.name?" loading":""}`,children:[c.jsx("input",{type:"checkbox",checked:g.enabled,disabled:r===g.name,onChange:()=>h(g.name,g.enabled)}),c.jsx("span",{className:"plugin-toggle-track"}),c.jsx("span",{className:"plugin-toggle-thumb"})]})]}),g.enabled&&g.name==="@openwriter/plugin-publish"&&c.jsx(L$,{}),g.enabled&&g.name==="@openwriter/plugin-github"&&c.jsx(R$,{}),g.enabled&&Object.keys(g.configSchema).length>0&&(()=>{const v=Object.entries(g.configSchema),b=v.filter(([,N])=>N.type==="select"),k=v.filter(([,N])=>N.type!=="select"),w=v.some(([N,T])=>T.required&&!g.config[N]),S=(N,T)=>{const M=l[`${g.name}:${N}`]||"idle";return c.jsxs("div",{className:"plugin-config-field",children:[c.jsxs("label",{className:"plugin-config-label",children:[T.description||N,c.jsx(D$,{status:M})]}),T.options?c.jsxs("select",{className:"plugin-config-input",defaultValue:g.config[N]||"",onChange:_=>m(g.name,N,_.target.value),children:[!T.required&&!T.options.some(_=>_.value==="")&&c.jsx("option",{value:"",children:"—"}),T.options.map(_=>c.jsx("option",{value:_.value,children:_.label},_.value))]}):c.jsx("input",{className:"plugin-config-input",type:N.toLowerCase().includes("key")||N.toLowerCase().includes("secret")||N.toLowerCase().includes("token")?"password":"text",defaultValue:g.config[N]||"",placeholder:T.env?`$${T.env}`:"",onBlur:_=>m(g.name,N,_.target.value)})]},N)};return c.jsxs("div",{className:"plugin-config-section",children:[w&&c.jsxs("div",{className:"plugin-setup-hint",children:["Ask your agent: “set up ",Dk(g.name),"”"]}),b.length>0&&c.jsx("div",{className:"plugin-config",children:b.map(([N,T])=>S(N,T))}),k.length>0&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{className:"plugin-config-toggle",onClick:()=>o(N=>{const T=new Set(N);return T.has(g.name)?T.delete(g.name):T.add(g.name),T}),children:[c.jsx("svg",{className:`plugin-config-chevron${i.has(g.name)?" plugin-config-chevron--open":""}`,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Settings"]}),i.has(g.name)&&c.jsx("div",{className:"plugin-config",children:k.map(([N,T])=>S(N,T))})]})]})})()]},g.name))})}function B$({existingConnection:t,onClose:e,onSaved:n}){const[r,s]=x.useState("form"),[i,o]=x.useState(null),[l,d]=x.useState((t==null?void 0:t.domain)||""),[f,h]=x.useState(""),[m,g]=x.useState((t==null?void 0:t.from_name)||""),[v,b]=x.useState(""),[k,w]=x.useState((t==null?void 0:t.id)||""),[S,N]=x.useState({dns_verified:!1,sender_verified:!1}),T=x.useRef(null),M=x.useRef(null);x.useEffect(()=>{const J=z=>{r!=="submitting"&&r!=="verifying"&&M.current&&!M.current.contains(z.target)&&e()};return document.addEventListener("mousedown",J),()=>document.removeEventListener("mousedown",J)},[e,r]),x.useEffect(()=>{const J=z=>{z.key==="Escape"&&r!=="submitting"&&r!=="verifying"&&e()};return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[e,r]),x.useEffect(()=>()=>{T.current&&clearInterval(T.current)},[]);async function _(){var J,z;s("submitting"),o(null);try{const D=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"setup_custom_domain",arguments:{domain:l,from_email:f,from_name:m||void 0,physical_address:v}})})).json(),U=(z=(J=D.content)==null?void 0:J[0])!=null&&z.text?JSON.parse(D.content[0].text):D;if(U.error){o(U.error),s("error");return}const q=U.connectionId||U.connection_id||k;q&&w(q),O(q)}catch(G){o(G.message),s("error")}}async function A(){var J,z;s("submitting"),o(null);try{const D=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"setup_custom_domain",arguments:{domain:l,from_email:f||void 0,from_name:m||void 0,physical_address:v||void 0}})})).json(),U=(z=(J=D.content)==null?void 0:J[0])!=null&&z.text?JSON.parse(D.content[0].text):D;if(U.error){o(U.error),s("error");return}s("done")}catch(G){o(G.message),s("error")}}function O(J){s("verifying"),T.current=setInterval(async()=>{var z,G;try{const U=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"check_domain_status",arguments:{connectionId:J}})})).json(),q=(G=(z=U.content)==null?void 0:z[0])!=null&&G.text?JSON.parse(U.content[0].text):U,se=!!q.dns_verified,V=!!q.sender_verified;N({dns_verified:se,sender_verified:V}),se&&V&&(T.current&&clearInterval(T.current),T.current=null,s("done"))}catch{}},5e3)}function B(){k&&fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"resend_domain_verification",arguments:{connectionId:k}})}).catch(()=>{})}const $=!!t,W=l.trim()&&f.trim()&&v.trim();return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"newsletter-modal newsletter-modal--setup",ref:M,children:[c.jsxs("div",{className:"newsletter-modal__header",children:[c.jsx("h3",{children:$?"Newsletter Settings":"Set Up Newsletter"}),c.jsx("button",{className:"newsletter-modal__close",onClick:e,children:"×"})]}),c.jsxs("div",{className:"newsletter-modal__body",children:[r==="form"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsx("label",{className:"newsletter-modal__label",children:"Domain"}),c.jsx("input",{className:"newsletter-modal__input",type:"text",placeholder:"yourdomain.com",value:l,onChange:J=>d(J.target.value),disabled:$,autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsx("label",{className:"newsletter-modal__label",children:"From Email"}),c.jsx("input",{className:"newsletter-modal__input",type:"email",placeholder:"newsletter@yourdomain.com",value:f,onChange:J=>h(J.target.value),autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsxs("label",{className:"newsletter-modal__label",children:["From Name ",c.jsx("span",{className:"newsletter-modal__optional",children:"(optional)"})]}),c.jsx("input",{className:"newsletter-modal__input",type:"text",placeholder:"Your Name or Brand",value:m,onChange:J=>g(J.target.value),autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsxs("label",{className:"newsletter-modal__label",children:["Physical Address ",c.jsx("span",{className:"newsletter-modal__required",children:"*"})]}),c.jsx("textarea",{className:"newsletter-modal__input newsletter-modal__textarea",rows:2,placeholder:"123 Main St, City, State 12345",value:v,onChange:J=>b(J.target.value)}),c.jsx("span",{className:"newsletter-modal__hint",children:"Required by CAN-SPAM. Included in email footer."})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:e,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:$?A:_,disabled:!W,children:$?"Save":"Set Up Domain"})]})]}),r==="submitting"&&c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:$?"Saving...":"Setting up domain..."})]}),r==="verifying"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__verify",children:[c.jsx("p",{className:"newsletter-modal__verify-title",children:"Verifying domain setup..."}),c.jsxs("div",{className:"newsletter-modal__verify-checks",children:[c.jsxs("div",{className:`newsletter-modal__verify-item${S.dns_verified?" newsletter-modal__verify-item--done":""}`,children:[S.dns_verified?"✓":c.jsx("span",{className:"newsletter-modal__spinner newsletter-modal__spinner--sm"}),c.jsx("span",{children:"DNS records"})]}),c.jsxs("div",{className:`newsletter-modal__verify-item${S.sender_verified?" newsletter-modal__verify-item--done":""}`,children:[S.sender_verified?"✓":c.jsx("span",{className:"newsletter-modal__spinner newsletter-modal__spinner--sm"}),c.jsx("span",{children:"Sender verification"})]})]}),c.jsx("p",{className:"newsletter-modal__hint",children:"This may take a few minutes. You can close and check back later."})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:B,children:"Resend Verification"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>{n(),e()},children:"Close"})]})]}),r==="done"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__status newsletter-modal__status--success",children:$?"Settings saved!":"Newsletter domain configured!"}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>{n(),e()},children:"Done"})})]}),r==="error"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__error",children:i}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:e,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>s("form"),children:"Try Again"})]})]})]})]})})}const $$={x:[],linkedin:[]};function z$({connectionId:t,provider:e,displayName:n,onClose:r,onSaved:s}){const[i,o]=x.useState("loading"),[l,d]=x.useState({}),[f,h]=x.useState(null),m=x.useRef(null),g=$$[e]||[];x.useEffect(()=>{fetch(`/api/connections/${t}/config`).then(k=>k.json()).then(k=>{d(k.config||{}),o("form")}).catch(k=>{h(k.message),o("error")})},[t]),x.useEffect(()=>{const k=w=>{i!=="saving"&&m.current&&!m.current.contains(w.target)&&r()};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[r,i]),x.useEffect(()=>{const k=w=>{w.key==="Escape"&&i!=="saving"&&r()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[r,i]);async function v(){o("saving"),h(null);try{const k=await fetch(`/api/connections/${t}/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),w=await k.json();if(!k.ok)throw new Error(w.error||"Failed to save");o("saved"),s(),setTimeout(r,800)}catch(k){h(k.message),o("error")}}function b(k){switch(k){case"x":return"X (Twitter)";case"linkedin":return"LinkedIn";default:return k}}return c.jsx("div",{className:"conn-config-overlay",children:c.jsxs("div",{className:"conn-config-modal",ref:m,children:[c.jsxs("div",{className:"conn-config-modal__header",children:[c.jsxs("div",{className:"conn-config-modal__title",children:[b(e)," Settings"]}),c.jsx("div",{className:"conn-config-modal__subtitle",children:n})]}),i==="loading"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("div",{className:"conn-config-spinner"}),c.jsx("span",{children:"Loading configuration..."})]}),(i==="form"||i==="error")&&g.length>0&&c.jsxs("div",{className:"conn-config-modal__body",children:[g.map(k=>c.jsxs("div",{className:"conn-config-field",children:[c.jsxs("label",{className:"conn-config-field__label",children:[k.label,k.readonly&&c.jsx("span",{className:"conn-config-field__badge",children:"read-only"})]}),c.jsx("input",{className:"conn-config-field__input",value:l[k.key]||"",placeholder:k.placeholder,readOnly:k.readonly,onChange:w=>d(S=>({...S,[k.key]:w.target.value}))})]},k.key)),f&&c.jsx("div",{className:"conn-config-modal__error",children:f})]}),(i==="form"||i==="error")&&g.length===0&&c.jsx("div",{className:"conn-config-modal__body conn-config-modal__center",children:c.jsxs("span",{className:"conn-config-modal__empty",children:["No configuration needed for ",b(e),"."]})}),i==="saving"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("div",{className:"conn-config-spinner"}),c.jsx("span",{children:"Saving..."})]}),i==="saved"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"#22c55e",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),c.jsx("span",{children:"Saved"})]}),c.jsxs("div",{className:"conn-config-modal__footer",children:[c.jsx("button",{className:"conn-config-btn conn-config-btn--secondary",onClick:r,children:i==="saved"?"Close":"Cancel"}),g.length>0&&(i==="form"||i==="error")&&c.jsx("button",{className:"conn-config-btn conn-config-btn--primary",onClick:v,children:"Save"})]})]})})}const F$=[{id:"x",label:"X (Twitter)",oauth:!0},{id:"linkedin",label:"LinkedIn",oauth:!0},{id:"newsletter",label:"Newsletter",oauth:!1}];function Pp(t){switch(t){case"x":return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})});case"linkedin":return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"})});case"newsletter":return c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),c.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]});default:return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("circle",{cx:"12",cy:"12",r:"10"})})}}function U$(t){return t==="active"?"connections-status--active":t==="expired"?"connections-status--expired":t==="revoked"?"connections-status--revoked":"connections-status--pending"}function H$(t){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(null),[l,d]=x.useState(null),[f,h]=x.useState(null),[m,g]=x.useState(null),v=x.useRef(null);async function b(){try{const A=await(await fetch("/api/connections")).json();s(A.authenticated!==!1);const O=(A.connections||[]).filter(B=>B&&B.id&&B.provider);return n(O),O}catch{return[]}}x.useEffect(()=>{b()},[]),x.useEffect(()=>()=>{v.current&&clearInterval(v.current)},[]);async function k(_){d(_);try{const A=await fetch(`/api/connections/oauth/${_}/start`,{method:"POST"}),O=await A.json();if(!A.ok||!O.url){d(null);return}window.open(O.url,"_blank","width=600,height=700"),v.current=setInterval(async()=>{try{const $=await(await fetch(`/api/connections/oauth/${_}/status/${O.state}`)).json();if($.status==="completed"){v.current&&clearInterval(v.current),v.current=null,d(null);const W=await b();if(_==="x"){const J=W.find(z=>z.provider==="x"&&z.status==="active");if(J!=null&&J.display_name){const z=J.display_name.replace("@","");localStorage.setItem("ow-x-handle",z),window.dispatchEvent(new StorageEvent("storage",{key:"ow-x-handle",newValue:z}))}}}else $.status==="failed"&&(v.current&&clearInterval(v.current),v.current=null,d(null))}catch{}},2e3)}catch{d(null)}}async function w(_){try{const A=await fetch(`/api/connections/${_}`,{method:"DELETE"});if(!A.ok){const O=await A.json().catch(()=>({error:"Delete failed"}));console.error("[Connections] Delete failed:",O.error)}}catch(A){console.error("[Connections] Delete error:",A)}o(null),await b()}const S=new Map,N=new Map;for(const _ of e){S.has(_.provider)||S.set(_.provider,_);const A=N.get(_.provider)||[];A.push(_),N.set(_.provider,A)}const T=new Set,M=r===!1;return c.jsxs("div",{className:"connections-tab",children:[m&&c.jsx(z$,{connectionId:m.id,provider:m.provider,displayName:m.display_name,onClose:()=>g(null),onSaved:()=>b()}),f&&c.jsx(B$,{existingConnection:f==="edit"?S.get("newsletter"):null,onClose:()=>h(null),onSaved:()=>b()}),M?c.jsxs("div",{className:"connections-dropdown__upsell",children:[c.jsx("p",{children:"Connect your X, LinkedIn, and other accounts to publish directly from OpenWriter."}),c.jsxs("p",{children:["Set up the ",c.jsx("strong",{children:"Publish"})," plugin to get started."]})]}):c.jsx("div",{className:"connections-dropdown__list",children:F$.flatMap(_=>{const A=T.has(_.id),O=N.get(_.id)||[],B=W=>i===W.id?c.jsxs("div",{className:"connections-dropdown__confirm",children:[c.jsxs("span",{children:["Disconnect ",W.display_name||_.label,"?"]}),c.jsxs("div",{className:"connections-dropdown__confirm-btns",children:[c.jsx("button",{onClick:()=>w(W.id),children:"Yes"}),c.jsx("button",{onClick:()=>o(null),children:"No"})]})]},W.id):c.jsxs("div",{className:"connections-dropdown__item",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Pp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:W.display_name||W.domain||_.label}),c.jsxs("div",{className:"connections-dropdown__type",children:[c.jsx("span",{className:`connections-status ${U$(W.status)}`}),"Connected"]})]}),c.jsxs("div",{className:"connections-dropdown__actions",children:[c.jsx("button",{className:"connections-dropdown__action-btn",onClick:()=>{_.id==="newsletter"?h("edit"):g({id:W.id,provider:_.id,display_name:W.display_name||_.label})},title:"Settings",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),c.jsx("button",{className:"connections-dropdown__action-btn connections-dropdown__action-btn--delete",onClick:()=>o(W.id),title:"Disconnect",children:"×"})]})]},W.id),$=O.map(B);return A?($.push(c.jsx("div",{className:"connections-dropdown__add-row",children:c.jsx("button",{className:"connections-dropdown__add-btn",onClick:()=>k(_.id),disabled:l!==null,children:l===_.id?"Connecting…":`+ Add ${_.label} repo`})},`${_.id}__add`)),$):O.length>0?$:_.oauth?[c.jsxs("div",{className:"connections-dropdown__item connections-dropdown__item--disconnected",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Pp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:_.label}),c.jsx("div",{className:"connections-dropdown__type",children:"Not connected"})]}),c.jsx("button",{className:"connections-dropdown__connect-inline-btn",onClick:()=>k(_.id),disabled:l!==null,children:l===_.id?"Connecting…":"Connect"})]},_.id)]:[c.jsxs("div",{className:"connections-dropdown__item connections-dropdown__item--disconnected",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Pp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:_.label}),c.jsx("div",{className:"connections-dropdown__type",children:"Built-in · Not configured"})]}),c.jsx("button",{className:"connections-dropdown__connect-inline-btn",onClick:()=>h("new"),children:"Configure"})]},_.id)]})})]})}const W$={tree:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M3 3h7v7H3zM14 3h7v4h-7zM14 10h7v4h-7zM3 13h7v8H3z"})}),files:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("polyline",{points:"14 2 14 8 20 8"})]}),timeline:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"22"}),c.jsx("circle",{cx:"12",cy:"6",r:"2"}),c.jsx("circle",{cx:"12",cy:"12",r:"2"}),c.jsx("circle",{cx:"12",cy:"18",r:"2"}),c.jsx("line",{x1:"14",y1:"6",x2:"20",y2:"6"}),c.jsx("line",{x1:"14",y1:"12",x2:"20",y2:"12"}),c.jsx("line",{x1:"14",y1:"18",x2:"20",y2:"18"})]}),board:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"5",height:"18",rx:"1"}),c.jsx("rect",{x:"10",y:"3",width:"5",height:"12",rx:"1"}),c.jsx("rect",{x:"17",y:"3",width:"5",height:"15",rx:"1"})]}),shelf:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 19V5"}),c.jsx("path",{d:"M8 19V7"}),c.jsx("path",{d:"M12 19V4"}),c.jsx("path",{d:"M16 19V8"}),c.jsx("path",{d:"M20 19V6"}),c.jsx("line",{x1:"2",y1:"20",x2:"22",y2:"20"})]})};function q$(t){const[e,n]=x.useState(NE),[r,s]=x.useState(CE),[i,o]=x.useState(Od),l=_E(),[d,f]=x.useState(ME),[h,m]=x.useState(jE),g=(N=e,T=r,M=i,_=l,A=d,O=h)=>{AE(N,T,M,_,A,O)},v=N=>{n(N),g(N)},b=()=>{const N=r==="light"?"dark":"light";s(N),g(void 0,N)},k=N=>{o(N),g(void 0,void 0,N),window.dispatchEvent(new CustomEvent("ow-sidebar-mode-change",{detail:N}))},w=N=>{f(N),g(void 0,void 0,void 0,void 0,N)},S=N=>{m(N),g(void 0,void 0,void 0,void 0,void 0,N)};return c.jsxs("div",{className:"appearance-tab",children:[c.jsx("div",{className:"appearance-section",children:c.jsxs("div",{className:"appearance-section-header",children:[c.jsx("span",{className:"appearance-section-title",children:"Mode"}),c.jsxs("button",{className:"appearance-mode-btn",onClick:b,title:r==="light"?"Switch to dark":"Switch to light",children:[r==="light"?c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"5"}),c.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),c.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),c.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),c.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),c.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),c.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),c.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),c.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):c.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}),c.jsx("span",{children:r==="light"?"Light":"Dark"})]})]})}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Typography"})}),c.jsx("div",{className:"appearance-typeface-grid",children:wE.map(N=>c.jsx("button",{className:`appearance-style-option ${e===N.id?"active":""}`,onClick:()=>v(N.id),title:N.description,children:N.label},N.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Spacing"})}),c.jsx("div",{className:"appearance-typography-grid",children:EE.map(N=>c.jsx("button",{className:`appearance-style-option ${d===N.id?"active":""}`,onClick:()=>w(N.id),children:N.label},N.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Canvas"})}),c.jsx("div",{className:"appearance-style-grid",children:SE.map(N=>c.jsx("button",{className:`appearance-style-option ${h===N.id?"active":""}`,onClick:()=>S(N.id),children:N.label},N.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Layout"})}),c.jsx("div",{className:"appearance-mode-grid",children:kE.map(N=>c.jsxs("button",{className:`appearance-mode-option ${i===N.id?"active":""}`,onClick:()=>k(N.id),children:[W$[N.icon],c.jsx("span",{children:N.label})]},N.id))})]})]})}const qT=[{id:"review",label:"Review",scope:"doc",icon:c.jsx(I5,{}),Component:f$},{id:"activity",label:"Activity",scope:"workspace",icon:c.jsx(B5,{}),Component:j$},{id:"backlinks",label:"Backlinks",scope:"doc",icon:c.jsx(D5,{}),Component:g$},{id:"exports",label:"Export",scope:"doc",icon:c.jsx(P5,{}),Component:y$},{id:"versions",label:"Versions",scope:"doc",icon:c.jsx(L5,{}),Component:m$},{id:"plugins",label:"Plugins",scope:"settings",icon:c.jsx($5,{}),Component:P$},{id:"connections",label:"Connections",scope:"settings",icon:c.jsx(z5,{}),Component:H$},{id:"appearance",label:"Appearance",scope:"settings",icon:c.jsx(F5,{}),Component:q$}];function V$(t){return t?qT.find(e=>e.id===t)??null:null}function Pk({pendingDocs:t}){const{open:e,activeTab:n,openTab:r}=Yd(),[s,i]=x.useState(!1),[o,l]=x.useState(!1),d=x.useRef(0);return x.useEffect(()=>{const f=t.filenames.length,h=d.current;d.current=f,h===0&&f>0&&r("review")},[t.filenames.length,r]),x.useEffect(()=>{const f=()=>r("review");return window.addEventListener("ow-pending-write-applied",f),()=>window.removeEventListener("ow-pending-write-applied",f)},[r]),x.useEffect(()=>{const f=()=>{if(!(e&&n==="activity")){i(!0),window.setTimeout(()=>i(!1),500);try{localStorage.getItem("ow-bell-hint-seen")||(l(!0),localStorage.setItem("ow-bell-hint-seen","1"),window.setTimeout(()=>l(!1),6e3))}catch{}}};return window.addEventListener("ow-activity-event",f),()=>window.removeEventListener("ow-activity-event",f)},[e,n]),c.jsx("div",{className:"rail-icon-strip",role:"tablist","aria-label":"Right rail tabs",children:qT.map(f=>{const h=e&&n===f.id,m=f.id==="activity";return c.jsxs("button",{type:"button",role:"tab","aria-selected":h,className:["rail-icon-btn",h?"rail-icon-btn--active":"",`rail-icon-btn--scope-${f.scope}`,m&&s?"rail-icon-btn--pulsing":""].filter(Boolean).join(" "),onClick:()=>r(f.id),title:f.label,"aria-label":f.label,children:[f.icon,m&&o&&c.jsxs("div",{className:"rail-icon-hint",role:"tooltip",children:[c.jsx("span",{children:"Agent activity lives here."}),c.jsx("button",{type:"button",className:"rail-icon-hint-close",onClick:g=>{g.stopPropagation(),l(!1)},"aria-label":"Dismiss",children:"×"})]})]},f.id)})})}function K$(t){const{activeTab:e}=Yd(),n=V$(e);return c.jsx("div",{className:"rail-body",role:"tabpanel",children:n?c.jsx(n.Component,{...t}):null})}const G$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),J$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M9 14l2 2 4-4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),Y$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M12 16v-5M9.5 13.5L12 11l2.5 2.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),X$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M14 14l-4 4M10 14l4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});function Q$({syncStatus:t,onSync:e}){const[n,r]=x.useState(!1),[s,i]=x.useState([]),[o,l]=x.useState(!1),d=x.useRef(null),f=x.useCallback(()=>{if(n){r(!1);return}r(!0),l(!0),fetch("/api/sync/pending").then(h=>h.json()).then(h=>i(h)).catch(()=>i([])).finally(()=>l(!1))},[n]);return x.useEffect(()=>{t.state!=="pending"&&r(!1)},[t.state]),x.useEffect(()=>{if(!n)return;const h=m=>{d.current&&!d.current.contains(m.target)&&r(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[n]),c.jsxs("div",{className:"sync-btn-group",ref:d,children:[c.jsxs("button",{className:`titlebar-btn sync-btn-state sync-${t.state}`,onClick:e,disabled:t.state==="syncing",title:t.lastSyncTime?`Last synced: ${new Date(t.lastSyncTime).toLocaleString()}`:"Sync to GitHub",children:[t.state==="unconfigured"&&c.jsxs(c.Fragment,{children:[c.jsx(G$,{})," Sync"]}),t.state==="synced"&&c.jsxs(c.Fragment,{children:[c.jsx(J$,{})," Synced"]}),t.state==="pending"&&c.jsxs(c.Fragment,{children:[c.jsx(Y$,{})," Sync",t.pendingFiles?` (${t.pendingFiles})`:""]}),t.state==="syncing"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"sync-btn-spinner"})," Syncing..."]}),t.state==="error"&&c.jsxs(c.Fragment,{children:[c.jsx(X$,{})," Retry"]})]}),t.state==="pending"&&t.pendingFiles&&t.pendingFiles>0&&c.jsx("button",{className:"sync-details-btn",onClick:f,title:"View pending changes",children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:c.jsx("path",{d:n?"M3 7.5L6 4.5L9 7.5":"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n&&c.jsxs("div",{className:"sync-pending-dropdown",children:[c.jsx("div",{className:"sync-pending-header",children:"Changes to push"}),o?c.jsx("div",{className:"sync-pending-loading",children:"Loading..."}):s.length===0?c.jsx("div",{className:"sync-pending-loading",children:"No changes"}):c.jsx("div",{className:"sync-pending-list",children:s.map((h,m)=>c.jsxs("div",{className:`sync-pending-item sync-file-${h.status}`,children:[c.jsx("span",{className:"sync-file-badge",children:h.status[0].toUpperCase()}),c.jsx("span",{className:"sync-file-name",children:h.file})]},m))})]})]})}function Z$(t){const{syncStatus:e,onSync:n,onToggleToolbar:r,toolbarOpen:s,focusMode:i,onToggleFocusMode:o,...l}=t,{open:d,activeTab:f,width:h,setWidth:m,closeRail:g,openTab:v}=Yd(),b=x.useRef(null),k=x.useRef(null),w=x.useRef(i);x.useEffect(()=>{if(i!==w.current)if(w.current=i,i)k.current={open:d,activeTab:f},d&&g();else{const N=k.current;k.current=null,N!=null&&N.open&&N.activeTab&&v(N.activeTab)}},[i]);const S=x.useCallback(N=>{N.preventDefault();const T=N.clientX,M=h,_=O=>{const B=T-O.clientX;m(M+B)},A=()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",A)},[h,m]);return x.useEffect(()=>{if(!d)return;const N=T=>{T.key==="Escape"&&b.current&&b.current.contains(document.activeElement)&&(T.preventDefault(),g())};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[d,g]),d?c.jsxs("aside",{ref:b,className:"right-rail-column",style:{width:h,minWidth:h},"aria-label":"Right rail",children:[c.jsx("div",{className:"right-rail-resize-handle",onPointerDown:S,"aria-hidden":"true"}),c.jsxs("div",{className:"right-rail-topbar",children:[c.jsxs("div",{className:"right-rail-topbar-actions right-rail-topbar-actions--start",children:[c.jsx("button",{type:"button",className:"right-rail-topbar-btn",onClick:g,title:"Hide rail","aria-label":"Hide rail",children:c.jsx(U5,{})}),c.jsx("button",{type:"button",className:`right-rail-topbar-btn${i?" right-rail-topbar-btn--active":""}`,onClick:o,title:"Focus mode","aria-label":"Focus mode","aria-pressed":i,children:c.jsx(xT,{})}),c.jsx("button",{type:"button",className:`right-rail-topbar-btn${s?" right-rail-topbar-btn--active":""}`,onClick:r,title:"Toggle format toolbar","aria-label":"Toggle format toolbar","aria-pressed":s,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 20h16"}),c.jsx("path",{d:"m6 16 6-12 6 12"}),c.jsx("path",{d:"M8 12h8"})]})})]}),c.jsx("div",{className:"right-rail-topbar-actions right-rail-topbar-actions--end",children:c.jsx(Q$,{syncStatus:e,onSync:n})})]}),c.jsx(Pk,{pendingDocs:l.pendingDocs}),c.jsx(K$,{...l})]}):c.jsx("div",{className:"right-rail-mount-keepalive",style:{display:"none"},children:c.jsx(Pk,{pendingDocs:l.pendingDocs})})}function ez({onClose:t,onSetupComplete:e}){const[n,r]=x.useState("detecting"),[s,i]=x.useState(null),[o,l]=x.useState("gh"),[d,f]=x.useState("openwriter-docs"),[h,m]=x.useState(!0),[g,v]=x.useState(""),[b,k]=x.useState(""),[w,S]=x.useState(""),[N,T]=x.useState("");x.useEffect(()=>{fetch("/api/sync/capabilities").then(_=>_.json()).then(_=>{i(_),_.ghAuthenticated?l("gh"):(_.gitInstalled,l("pat")),r("setup")}).catch(()=>{S("Failed to detect git capabilities"),r("error")})},[]);const M=x.useCallback(async()=>{r("progress"),T(o==="connect"?"Connecting to repository...":"Creating repository and syncing...");try{const _={method:o,repoName:d,isPrivate:h};o==="pat"&&(_.pat=g),o==="connect"&&(_.remoteUrl=b,_.pat=g||void 0);const A=await fetch("/api/sync/setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)});if(!A.ok){const O=await A.json().catch(()=>({}));throw new Error(O.error||`Setup failed (${A.status})`)}r("done"),e()}catch(_){S(_.message),r("error")}},[o,d,h,g,b,e]);return c.jsx("div",{className:"sync-modal-overlay",onClick:t,children:c.jsxs("div",{className:"sync-modal",onClick:_=>_.stopPropagation(),children:[c.jsxs("div",{className:"sync-modal-header",children:[c.jsx("h2",{children:"Sync to GitHub"}),c.jsx("button",{className:"sync-modal-close",onClick:t,children:"×"})]}),n==="detecting"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-spinner"}),c.jsx("p",{children:"Detecting git configuration..."})]}),n==="setup"&&s&&c.jsxs("div",{className:"sync-modal-body",children:[!s.gitInstalled&&c.jsxs("div",{className:"sync-warning",children:["Git is not installed. Please ",c.jsx("a",{href:"https://git-scm.com/downloads",target:"_blank",rel:"noreferrer",children:"install git"})," first."]}),s.gitInstalled&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"sync-tabs",children:[s.ghAuthenticated&&c.jsx("button",{className:`sync-tab${o==="gh"?" active":""}`,onClick:()=>l("gh"),children:"GitHub CLI"}),c.jsx("button",{className:`sync-tab${o==="pat"?" active":""}`,onClick:()=>l("pat"),children:"Personal Access Token"}),c.jsx("button",{className:`sync-tab${o==="connect"?" active":""}`,onClick:()=>l("connect"),children:"Connect Existing"})]}),o==="gh"&&c.jsxs("div",{className:"sync-form",children:[c.jsxs("label",{children:["Repository name",c.jsx("input",{type:"text",value:d,onChange:_=>f(_.target.value),placeholder:"openwriter-docs"})]}),c.jsxs("label",{className:"sync-checkbox",children:[c.jsx("input",{type:"checkbox",checked:h,onChange:_=>m(_.target.checked)}),"Private repository"]})]}),o==="pat"&&c.jsxs("div",{className:"sync-form",children:[!s.ghAuthenticated&&!s.ghInstalled&&c.jsxs("p",{className:"sync-hint",children:["Create a ",c.jsx("a",{href:"https://github.com/settings/tokens/new?scopes=repo&description=OpenWriter",target:"_blank",rel:"noreferrer",children:"Personal Access Token"})," with ",c.jsx("code",{children:"repo"})," scope."]}),c.jsxs("label",{children:["Personal Access Token",c.jsx("input",{type:"password",value:g,onChange:_=>v(_.target.value),placeholder:"ghp_..."})]}),c.jsxs("label",{children:["Repository name",c.jsx("input",{type:"text",value:d,onChange:_=>f(_.target.value),placeholder:"openwriter-docs"})]}),c.jsxs("label",{className:"sync-checkbox",children:[c.jsx("input",{type:"checkbox",checked:h,onChange:_=>m(_.target.checked)}),"Private repository"]})]}),o==="connect"&&c.jsxs("div",{className:"sync-form",children:[c.jsxs("label",{children:["Remote URL",c.jsx("input",{type:"text",value:b,onChange:_=>k(_.target.value),placeholder:"https://github.com/user/repo.git"})]}),c.jsxs("label",{children:["PAT (optional, for private repos)",c.jsx("input",{type:"password",value:g,onChange:_=>v(_.target.value),placeholder:"ghp_..."})]})]}),c.jsxs("div",{className:"sync-modal-actions",children:[c.jsx("button",{className:"sync-btn secondary",onClick:t,children:"Cancel"}),c.jsx("button",{className:"sync-btn primary",onClick:M,disabled:o==="pat"&&!g||o==="connect"&&!b||o!=="connect"&&!d,children:o==="connect"?"Connect & Sync":"Create & Sync"})]})]})]}),n==="progress"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-spinner"}),c.jsx("p",{children:N})]}),n==="done"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-success-icon",children:"✓"}),c.jsx("p",{children:"Successfully synced to GitHub!"}),c.jsx("div",{className:"sync-modal-actions",children:c.jsx("button",{className:"sync-btn primary",onClick:t,children:"Done"})})]}),n==="error"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-error-msg",children:w}),c.jsxs("div",{className:"sync-modal-actions",children:[c.jsx("button",{className:"sync-btn secondary",onClick:()=>r("setup"),children:"Back"}),c.jsx("button",{className:"sync-btn secondary",onClick:t,children:"Close"})]})]})]})})}function tz({onNodeChanges:t,onAgentStatus:e,onDocumentSwitched:n,onDocumentReloaded:r,onDocumentsChanged:s,onWorkspacesChanged:i,onTitleChanged:o,onPendingDocsChanged:l,onMetadataChanged:d,onSyncStatus:f,onWritingStarted:h,onWritingFinished:m,onIdRewrites:g,onPendingFilenamesChanged:v,getEditorState:b}){const k=x.useRef(null),[w,S]=x.useState(!1),N=x.useRef(0),T=x.useRef(new Set),M=()=>{var j;return(j=se.current)==null?void 0:j.call(se,new Set(T.current))},_=x.useRef(t),A=x.useRef(e),O=x.useRef(n),B=x.useRef(s),$=x.useRef(i),W=x.useRef(o),J=x.useRef(l),z=x.useRef(f),G=x.useRef(d),D=x.useRef(h),U=x.useRef(m),q=x.useRef(g),se=x.useRef(v),V=x.useRef(r),re=x.useRef(b);_.current=t,A.current=e,O.current=n,B.current=s,$.current=i,W.current=o,J.current=l,G.current=d,z.current=f,D.current=h,U.current=m,q.current=g,se.current=v,V.current=r,re.current=b,x.useEffect(()=>{const L=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;let ee,he=!1,ge=1e3;function oe(){const we=new WebSocket(L);k.current=we,we.onopen=()=>{S(!0),ge=1e3,he&&we.send(JSON.stringify({type:"request-document"})),he=!0},we.onmessage=We=>{var He,Ze,Oe,Ke,mt,Ye,pe,gt,ft,at,nt,ht,Fe,ve;try{const X=JSON.parse(We.data);if(X.type==="node-changes"&&X.changes&&((He=_.current)==null||He.call(_,X.changes),typeof X.version=="number"&&(N.current=X.version)),X.type==="id-rewrites"&&Array.isArray(X.rewrites)&&((Ze=q.current)==null||Ze.call(q,X.rewrites)),X.type==="agent-status"&&((Oe=A.current)==null||Oe.call(A,!!X.agentConnected)),X.type==="document-switched"&&(N.current=0,(Ke=O.current)==null||Ke.call(O,{document:X.document,title:X.title,filename:X.filename,docId:X.docId,metadata:X.metadata,pendingMetadata:X.pendingMetadata??null}),window.dispatchEvent(new CustomEvent("ow-pending-metadata-changed",{detail:{docId:X.docId,pendingMetadata:X.pendingMetadata??null}}))),X.type==="pending-metadata-changed"&&window.dispatchEvent(new CustomEvent("ow-pending-metadata-changed",{detail:{docId:X.docId,pendingMetadata:X.pendingMetadata??null}})),X.type==="document-reloaded"&&(typeof X.version=="number"&&(N.current=X.version),(mt=V.current)==null||mt.call(V,{document:X.document,title:X.title,filename:X.filename,docId:X.docId,metadata:X.metadata,orphanCount:typeof X.orphanCount=="number"?X.orphanCount:0,staleBaselineCount:typeof X.staleBaselineCount=="number"?X.staleBaselineCount:0})),X.type==="metadata-changed"&&X.metadata&&((Ye=G.current)==null||Ye.call(G,X.metadata)),X.type==="documents-changed"&&((pe=B.current)==null||pe.call(B)),X.type==="workspaces-changed"&&((gt=$.current)==null||gt.call($)),X.type==="title-changed"&&X.title&&((ft=W.current)==null||ft.call(W,X.title)),X.type==="pending-docs-changed"&&X.pendingDocs&&((at=J.current)==null||at.call(J,X.pendingDocs)),X.type==="sync-status"&&((nt=z.current)==null||nt.call(z,{state:X.state,lastSyncTime:X.lastSyncTime,pendingFiles:X.pendingFiles,error:X.error})),X.type==="writing-started"&&X.title&&(typeof X.key=="string"&&(T.current.add(X.key),M()),(ht=D.current)==null||ht.call(D,X.title,X.target||null)),X.type==="writing-finished"&&(typeof X.key=="string"&&X.key?T.current.delete(X.key):T.current.clear(),M(),(Fe=U.current)==null||Fe.call(U)),X.type==="pending-writes-sync"&&Array.isArray(X.writes)&&(T.current=new Set(X.writes.map(Be=>Be.key).filter(Boolean)),M(),X.writes.length>0)){const Be=X.writes.reduce((te,de)=>te.startedAt>de.startedAt?te:de);Be!=null&&Be.title&&((ve=D.current)==null||ve.call(D,Be.title,Be.target||null))}X.type==="plugins-changed"&&window.dispatchEvent(new CustomEvent("ow-plugins-changed")),X.type==="comments-changed"&&X.filename&&window.dispatchEvent(new CustomEvent("ow-comments-changed",{detail:{filename:X.filename}})),X.type==="documents-changed"&&window.dispatchEvent(new CustomEvent("ow-documents-changed")),X.type==="metadata-changed"&&window.dispatchEvent(new CustomEvent("ow-metadata-changed",{detail:{metadata:X.metadata}})),X.type==="activity-log"&&Array.isArray(X.entries)&&window.dispatchEvent(new CustomEvent("ow-activity-seed",{detail:{entries:X.entries}})),X.type==="activity-event"&&X.event&&window.dispatchEvent(new CustomEvent("ow-activity-event",{detail:{event:X.event}}))}catch{}},we.onclose=()=>{S(!1),ee=setTimeout(oe,ge),ge=Math.min(ge*1.5,8e3)},we.onerror=()=>{we.close()}}oe();function xe(){var we;document.visibilityState==="visible"&&((we=k.current)==null?void 0:we.readyState)!==WebSocket.OPEN&&(clearTimeout(ee),ge=1e3,oe())}return document.addEventListener("visibilitychange",xe),()=>{clearTimeout(ee),document.removeEventListener("visibilitychange",xe),k.current&&(k.current.onclose=null,k.current.close())}},[]);const K=x.useCallback(j=>{var L;((L=k.current)==null?void 0:L.readyState)===WebSocket.OPEN&&k.current.send(JSON.stringify(j))},[]);return{connected:w,sendMessage:K,docVersionRef:N}}function nz(t){const[e,n]=x.useState(null),[r,s]=x.useState(!1),[i,o]=x.useState(null),l=x.useRef(void 0);return x.useEffect(()=>{if(!t){n(null),s(!1),o(null),l.current=void 0;return}t!==l.current&&(l.current=t,s(!0),o(null),fetch(`/api/tweet-embed?url=${encodeURIComponent(t)}`).then(d=>d.ok?d.json():d.json().then(f=>Promise.reject(new Error(f.error||`HTTP ${d.status}`)))).then(d=>{n(d),s(!1)}).catch(d=>{o(d.message),s(!1)}))},[t]),{tweet:e,loading:r,error:i}}function rz(t){var r;const e=t.view.dom,n=[];for(const s of e.children){const i=(r=s.innerText)==null?void 0:r.trim();i&&n.push(i)}return n.join(`
|
|
209
|
+
This only removes the OpenWriter registration. Your GitHub repo is untouched.`))return;const O=await bu("remove_blog_site",{id:_.id});if(O!=null&&O.error){alert(`Remove failed: ${O.error}`);return}await w()};return c.jsxs("div",{className:"github-plugin-settings",children:[c.jsxs("div",{className:"github-plugin-settings__header",children:[c.jsx("span",{className:"github-plugin-settings__title",children:"Blog repos"}),s==="closed"&&c.jsx("button",{className:"github-plugin-settings__add-btn",onClick:()=>i("url"),children:"+ Add"})]}),n?c.jsx("div",{className:"github-plugin-settings__loading",children:"Loading…"}):t.length===0&&s==="closed"?c.jsxs("div",{className:"github-plugin-settings__empty",children:["Connect a GitHub repo to publish blog posts via local git — no PATs, no Workers. Uses your existing ",c.jsx("code",{children:"gh auth login"}),"."]}):c.jsx("div",{className:"github-plugin-settings__list",children:t.map(_=>c.jsxs("div",{className:"github-plugin-settings__site",children:[c.jsxs("div",{className:"github-plugin-settings__site-info",children:[c.jsxs("div",{className:"github-plugin-settings__site-row1",children:[c.jsx("span",{className:"github-plugin-settings__site-label",children:_.label}),c.jsx("span",{className:`github-plugin-settings__site-framework github-plugin-settings__site-framework--${_.framework}`,children:_.framework})]}),c.jsxs("div",{className:"github-plugin-settings__site-repo",children:[_.owner,"/",_.repo,"@",_.branch]}),c.jsxs("div",{className:"github-plugin-settings__site-dirs",children:[c.jsx("span",{title:"content_dir",children:_.content_dir}),c.jsx("span",{className:"github-plugin-settings__site-sep",children:"·"}),c.jsx("span",{title:"image_public_prefix",children:_.image_public_prefix})]})]}),c.jsx("button",{className:"github-plugin-settings__remove-btn",onClick:()=>M(_),title:"Remove",children:"×"})]},_.id))}),s==="url"&&c.jsxs("div",{className:"github-plugin-settings__form",children:[c.jsx("label",{className:"github-plugin-settings__label",children:"GitHub repo"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"owner/repo or https://github.com/owner/repo",value:o,onChange:_=>l(_.target.value),onKeyDown:_=>{_.key==="Enter"&&!d&&N()},autoFocus:!0}),h&&c.jsx("div",{className:"github-plugin-settings__error",children:h}),c.jsxs("div",{className:"github-plugin-settings__form-buttons",children:[c.jsx("button",{className:"github-plugin-settings__btn github-plugin-settings__btn--primary",onClick:N,disabled:d||!o.trim(),children:d?"Inspecting…":"Inspect"}),c.jsx("button",{className:"github-plugin-settings__btn",onClick:S,disabled:d,children:"Cancel"})]})]}),(s==="review"||s==="saving")&&g&&c.jsxs("div",{className:"github-plugin-settings__form",children:[c.jsxs("div",{className:"github-plugin-settings__form-meta",children:[c.jsxs("span",{children:["Detected: ",g.framework]}),c.jsx("span",{children:"·"}),c.jsxs("span",{children:[g.markdown_files_found," posts"]}),c.jsx("span",{children:"·"}),c.jsxs("span",{className:`github-plugin-settings__confidence github-plugin-settings__confidence--${g.confidence}`,children:[g.confidence," confidence"]})]}),c.jsx("label",{className:"github-plugin-settings__label",children:"Label"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.label,onChange:_=>v({...g,label:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Branch"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.branch,onChange:_=>v({...g,branch:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Content directory"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.content_dir,onChange:_=>v({...g,content_dir:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Image directory"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.image_dir,onChange:_=>v({...g,image_dir:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Image public prefix"}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",value:g.image_public_prefix,onChange:_=>v({...g,image_public_prefix:_.target.value})}),c.jsxs("label",{className:"github-plugin-settings__label",children:["Site URL ",c.jsx("span",{className:"github-plugin-settings__hint",children:"— optional, used for the live link after publish"})]}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"https://example.com",value:g.site_url||"",onChange:_=>v({...g,site_url:_.target.value})}),c.jsxs("label",{className:"github-plugin-settings__label",children:["Blog URL pattern ",c.jsxs("span",{className:"github-plugin-settings__hint",children:["— uses ","{slug}"," placeholder"]})]}),c.jsx("input",{className:"github-plugin-settings__input",type:"text",placeholder:"/blog/{slug}/",value:g.blog_url_pattern||"",onChange:_=>v({...g,blog_url_pattern:_.target.value})}),c.jsx("label",{className:"github-plugin-settings__label",children:"Framework"}),c.jsxs("select",{className:"github-plugin-settings__input",value:g.framework,onChange:_=>v({...g,framework:_.target.value}),children:[c.jsx("option",{value:"astro",children:"Astro"}),c.jsx("option",{value:"next",children:"Next"}),c.jsx("option",{value:"jekyll",children:"Jekyll"}),c.jsx("option",{value:"hugo",children:"Hugo"}),c.jsx("option",{value:"unknown",children:"Unknown"})]}),g.frontmatter_schema.length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsxs("span",{className:"github-plugin-settings__label",children:["Frontmatter keys detected (",g.samples_analyzed," ",g.samples_analyzed===1?"sample":"samples",")"]}),c.jsx("code",{children:g.frontmatter_schema.join(", ")})]}),Object.keys(g.frontmatter_defaults||{}).length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsx("span",{className:"github-plugin-settings__label",children:"Frontmatter defaults (constants applied to every post)"}),c.jsx("code",{children:Object.entries(g.frontmatter_defaults).map(([_,A])=>c.jsxs("div",{children:[_,": ",typeof A=="string"?A:JSON.stringify(A)]},_))})]}),Object.keys(g.frontmatter_field_map||{}).length>0&&c.jsxs("div",{className:"github-plugin-settings__schema",children:[c.jsx("span",{className:"github-plugin-settings__label",children:"Field name mapping (openwriter → site)"}),c.jsx("code",{children:Object.entries(g.frontmatter_field_map).map(([_,A])=>c.jsxs("div",{children:[_," → ",A]},_))})]}),b&&c.jsx("div",{className:"github-plugin-settings__error",children:b}),c.jsxs("div",{className:"github-plugin-settings__form-buttons",children:[c.jsx("button",{className:"github-plugin-settings__btn github-plugin-settings__btn--primary",onClick:T,disabled:s==="saving"||!g.label.trim(),children:s==="saving"?"Saving…":"Add site"}),c.jsx("button",{className:"github-plugin-settings__btn",onClick:S,disabled:s==="saving",children:"Cancel"})]})]})]})}const O$={none:"No Plan",free:"No Plan",creator:"Publish — $19/mo",growth:"Publish+Email — $49/mo"},I$=[{plan:"creator",label:"Publish $19/mo"},{plan:"growth",label:"Publish+Email $49/mo"}];function L$(){var d,f;const[t,e]=x.useState(null),[n,r]=x.useState(!0);x.useEffect(()=>{fetch("/api/billing").then(h=>h.json()).then(h=>e(h)).catch(()=>{}).finally(()=>r(!1))},[]);const s=x.useCallback(async h=>{const m=await fetch("/api/billing/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plan:h})});if(m.ok){const g=await m.json();g.url&&window.open(g.url,"_blank")}},[]),i=x.useCallback(async()=>{const h=await fetch("/api/billing/portal",{method:"POST",headers:{"Content-Type":"application/json"}});if(h.ok){const m=await h.json();m.url&&window.open(m.url,"_blank")}},[]);if(n)return c.jsx("div",{className:"billing-section",children:c.jsx("div",{className:"billing-loading",children:"Loading..."})});if(!(t!=null&&t.authenticated))return null;const o=t.plan||"free",l=I$.filter(h=>{const m=["free","creator","growth"];return m.indexOf(h.plan)>m.indexOf(o)});return c.jsxs("div",{className:"billing-section",children:[c.jsxs("div",{className:"billing-plan",children:[c.jsx("span",{className:"billing-plan-label",children:"Plan"}),c.jsx("span",{className:`billing-plan-badge billing-plan-badge--${o}`,children:O$[o]||o})]}),((d=t.billing)==null?void 0:d.paymentFailed)&&c.jsx("div",{className:"billing-warning",children:"Payment failed — update card to keep your plan."}),l.length>0&&c.jsx("div",{className:"billing-upgrades",children:l.map(h=>c.jsxs("button",{className:"billing-upgrade-btn",onClick:()=>s(h.plan),children:["Upgrade to ",h.label]},h.plan))}),((f=t.billing)==null?void 0:f.hasPaymentMethod)&&c.jsx("button",{className:"billing-manage-btn",onClick:i,children:"Manage Billing"})]})}function Dk(t){return t.replace(/^@openwriter\/plugin-/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function D$({status:t}){return t==="saving"?c.jsx("span",{className:"plugin-config-status plugin-config-status--saving",children:"Saving…"}):t==="saved"?c.jsxs("span",{className:"plugin-config-status plugin-config-status--saved",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#22c55e",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Saved"]}):t==="error"?c.jsxs("span",{className:"plugin-config-status plugin-config-status--error",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#ef4444",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),"Failed"]}):null}function P$(t){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(new Set),[l,d]=x.useState({}),f=x.useCallback(()=>{fetch("/api/available-plugins").then(g=>g.json()).then(g=>n(g.plugins||[])).catch(()=>{})},[]);x.useEffect(()=>{f()},[f]),x.useEffect(()=>{const g=()=>f();return window.addEventListener("ow-plugins-changed",g),()=>window.removeEventListener("ow-plugins-changed",g)},[f]);const h=x.useCallback(async(g,v)=>{s(g);try{(await fetch(v?"/api/plugins/disable":"/api/plugins/enable",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:g})})).ok&&f()}catch{}finally{s(null)}},[f]),m=x.useCallback(async(g,v,b)=>{const k=`${g}:${v}`;d(w=>({...w,[k]:"saving"}));try{const w=await fetch("/api/plugins/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:g,config:{[v]:b}})});if(!w.ok)throw new Error(`save failed (${w.status})`);d(S=>({...S,[k]:"saved"})),setTimeout(()=>{d(S=>S[k]==="saved"?{...S,[k]:"idle"}:S)},2e3)}catch{d(w=>({...w,[k]:"error"}))}},[]);return c.jsx("div",{className:"plugins-tab",children:e.length===0?c.jsx("div",{className:"plugin-empty",children:"No plugins found"}):e.map(g=>c.jsxs("div",{className:"plugin-item",children:[c.jsxs("div",{className:"plugin-item-header",children:[c.jsxs("div",{className:"plugin-item-info",children:[c.jsxs("div",{className:"plugin-item-name",children:[Dk(g.name),c.jsxs("span",{className:"plugin-item-version",children:["v",g.version]})]}),g.description&&c.jsx("div",{className:"plugin-item-desc",children:g.description})]}),c.jsxs("label",{className:`plugin-toggle${r===g.name?" loading":""}`,children:[c.jsx("input",{type:"checkbox",checked:g.enabled,disabled:r===g.name,onChange:()=>h(g.name,g.enabled)}),c.jsx("span",{className:"plugin-toggle-track"}),c.jsx("span",{className:"plugin-toggle-thumb"})]})]}),g.enabled&&g.name==="@openwriter/plugin-publish"&&c.jsx(L$,{}),g.enabled&&g.name==="@openwriter/plugin-github"&&c.jsx(R$,{}),g.enabled&&Object.keys(g.configSchema).length>0&&(()=>{const v=Object.entries(g.configSchema),b=v.filter(([,N])=>N.type==="select"),k=v.filter(([,N])=>N.type!=="select"),w=v.some(([N,T])=>T.required&&!g.config[N]),S=(N,T)=>{const M=l[`${g.name}:${N}`]||"idle";return c.jsxs("div",{className:"plugin-config-field",children:[c.jsxs("label",{className:"plugin-config-label",children:[T.description||N,c.jsx(D$,{status:M})]}),T.options?c.jsxs("select",{className:"plugin-config-input",defaultValue:g.config[N]||"",onChange:_=>m(g.name,N,_.target.value),children:[!T.required&&!T.options.some(_=>_.value==="")&&c.jsx("option",{value:"",children:"—"}),T.options.map(_=>c.jsx("option",{value:_.value,children:_.label},_.value))]}):c.jsx("input",{className:"plugin-config-input",type:N.toLowerCase().includes("key")||N.toLowerCase().includes("secret")||N.toLowerCase().includes("token")?"password":"text",defaultValue:g.config[N]||"",placeholder:T.env?`$${T.env}`:"",onBlur:_=>m(g.name,N,_.target.value)})]},N)};return c.jsxs("div",{className:"plugin-config-section",children:[w&&c.jsxs("div",{className:"plugin-setup-hint",children:["Ask your agent: “set up ",Dk(g.name),"”"]}),b.length>0&&c.jsx("div",{className:"plugin-config",children:b.map(([N,T])=>S(N,T))}),k.length>0&&c.jsxs(c.Fragment,{children:[c.jsxs("button",{className:"plugin-config-toggle",onClick:()=>o(N=>{const T=new Set(N);return T.has(g.name)?T.delete(g.name):T.add(g.name),T}),children:[c.jsx("svg",{className:`plugin-config-chevron${i.has(g.name)?" plugin-config-chevron--open":""}`,width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Settings"]}),i.has(g.name)&&c.jsx("div",{className:"plugin-config",children:k.map(([N,T])=>S(N,T))})]})]})})()]},g.name))})}function B$({existingConnection:t,onClose:e,onSaved:n}){const[r,s]=x.useState("form"),[i,o]=x.useState(null),[l,d]=x.useState((t==null?void 0:t.domain)||""),[f,h]=x.useState(""),[m,g]=x.useState((t==null?void 0:t.from_name)||""),[v,b]=x.useState(""),[k,w]=x.useState((t==null?void 0:t.id)||""),[S,N]=x.useState({dns_verified:!1,sender_verified:!1}),T=x.useRef(null),M=x.useRef(null);x.useEffect(()=>{const J=z=>{r!=="submitting"&&r!=="verifying"&&M.current&&!M.current.contains(z.target)&&e()};return document.addEventListener("mousedown",J),()=>document.removeEventListener("mousedown",J)},[e,r]),x.useEffect(()=>{const J=z=>{z.key==="Escape"&&r!=="submitting"&&r!=="verifying"&&e()};return document.addEventListener("keydown",J),()=>document.removeEventListener("keydown",J)},[e,r]),x.useEffect(()=>()=>{T.current&&clearInterval(T.current)},[]);async function _(){var J,z;s("submitting"),o(null);try{const D=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"setup_custom_domain",arguments:{domain:l,from_email:f,from_name:m||void 0,physical_address:v}})})).json(),U=(z=(J=D.content)==null?void 0:J[0])!=null&&z.text?JSON.parse(D.content[0].text):D;if(U.error){o(U.error),s("error");return}const q=U.connectionId||U.connection_id||k;q&&w(q),O(q)}catch(G){o(G.message),s("error")}}async function A(){var J,z;s("submitting"),o(null);try{const D=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"setup_custom_domain",arguments:{domain:l,from_email:f||void 0,from_name:m||void 0,physical_address:v||void 0}})})).json(),U=(z=(J=D.content)==null?void 0:J[0])!=null&&z.text?JSON.parse(D.content[0].text):D;if(U.error){o(U.error),s("error");return}s("done")}catch(G){o(G.message),s("error")}}function O(J){s("verifying"),T.current=setInterval(async()=>{var z,G;try{const U=await(await fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"check_domain_status",arguments:{connectionId:J}})})).json(),q=(G=(z=U.content)==null?void 0:z[0])!=null&&G.text?JSON.parse(U.content[0].text):U,se=!!q.dns_verified,V=!!q.sender_verified;N({dns_verified:se,sender_verified:V}),se&&V&&(T.current&&clearInterval(T.current),T.current=null,s("done"))}catch{}},5e3)}function B(){k&&fetch("/api/mcp-call",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tool:"resend_domain_verification",arguments:{connectionId:k}})}).catch(()=>{})}const $=!!t,W=l.trim()&&f.trim()&&v.trim();return c.jsx("div",{className:"newsletter-modal-overlay",children:c.jsxs("div",{className:"newsletter-modal newsletter-modal--setup",ref:M,children:[c.jsxs("div",{className:"newsletter-modal__header",children:[c.jsx("h3",{children:$?"Newsletter Settings":"Set Up Newsletter"}),c.jsx("button",{className:"newsletter-modal__close",onClick:e,children:"×"})]}),c.jsxs("div",{className:"newsletter-modal__body",children:[r==="form"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsx("label",{className:"newsletter-modal__label",children:"Domain"}),c.jsx("input",{className:"newsletter-modal__input",type:"text",placeholder:"yourdomain.com",value:l,onChange:J=>d(J.target.value),disabled:$,autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsx("label",{className:"newsletter-modal__label",children:"From Email"}),c.jsx("input",{className:"newsletter-modal__input",type:"email",placeholder:"newsletter@yourdomain.com",value:f,onChange:J=>h(J.target.value),autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsxs("label",{className:"newsletter-modal__label",children:["From Name ",c.jsx("span",{className:"newsletter-modal__optional",children:"(optional)"})]}),c.jsx("input",{className:"newsletter-modal__input",type:"text",placeholder:"Your Name or Brand",value:m,onChange:J=>g(J.target.value),autoComplete:"off"})]}),c.jsxs("div",{className:"newsletter-modal__field",children:[c.jsxs("label",{className:"newsletter-modal__label",children:["Physical Address ",c.jsx("span",{className:"newsletter-modal__required",children:"*"})]}),c.jsx("textarea",{className:"newsletter-modal__input newsletter-modal__textarea",rows:2,placeholder:"123 Main St, City, State 12345",value:v,onChange:J=>b(J.target.value)}),c.jsx("span",{className:"newsletter-modal__hint",children:"Required by CAN-SPAM. Included in email footer."})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:e,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:$?A:_,disabled:!W,children:$?"Save":"Set Up Domain"})]})]}),r==="submitting"&&c.jsxs("div",{className:"newsletter-modal__status",children:[c.jsx("div",{className:"newsletter-modal__spinner"}),c.jsx("span",{children:$?"Saving...":"Setting up domain..."})]}),r==="verifying"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"newsletter-modal__verify",children:[c.jsx("p",{className:"newsletter-modal__verify-title",children:"Verifying domain setup..."}),c.jsxs("div",{className:"newsletter-modal__verify-checks",children:[c.jsxs("div",{className:`newsletter-modal__verify-item${S.dns_verified?" newsletter-modal__verify-item--done":""}`,children:[S.dns_verified?"✓":c.jsx("span",{className:"newsletter-modal__spinner newsletter-modal__spinner--sm"}),c.jsx("span",{children:"DNS records"})]}),c.jsxs("div",{className:`newsletter-modal__verify-item${S.sender_verified?" newsletter-modal__verify-item--done":""}`,children:[S.sender_verified?"✓":c.jsx("span",{className:"newsletter-modal__spinner newsletter-modal__spinner--sm"}),c.jsx("span",{children:"Sender verification"})]})]}),c.jsx("p",{className:"newsletter-modal__hint",children:"This may take a few minutes. You can close and check back later."})]}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:B,children:"Resend Verification"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>{n(),e()},children:"Close"})]})]}),r==="done"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__status newsletter-modal__status--success",children:$?"Settings saved!":"Newsletter domain configured!"}),c.jsx("div",{className:"newsletter-modal__actions",children:c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>{n(),e()},children:"Done"})})]}),r==="error"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"newsletter-modal__error",children:i}),c.jsxs("div",{className:"newsletter-modal__actions",children:[c.jsx("button",{className:"newsletter-modal__btn",onClick:e,children:"Cancel"}),c.jsx("button",{className:"newsletter-modal__btn newsletter-modal__btn--primary",onClick:()=>s("form"),children:"Try Again"})]})]})]})]})})}const $$={x:[],linkedin:[]};function z$({connectionId:t,provider:e,displayName:n,onClose:r,onSaved:s}){const[i,o]=x.useState("loading"),[l,d]=x.useState({}),[f,h]=x.useState(null),m=x.useRef(null),g=$$[e]||[];x.useEffect(()=>{fetch(`/api/connections/${t}/config`).then(k=>k.json()).then(k=>{d(k.config||{}),o("form")}).catch(k=>{h(k.message),o("error")})},[t]),x.useEffect(()=>{const k=w=>{i!=="saving"&&m.current&&!m.current.contains(w.target)&&r()};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[r,i]),x.useEffect(()=>{const k=w=>{w.key==="Escape"&&i!=="saving"&&r()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[r,i]);async function v(){o("saving"),h(null);try{const k=await fetch(`/api/connections/${t}/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),w=await k.json();if(!k.ok)throw new Error(w.error||"Failed to save");o("saved"),s(),setTimeout(r,800)}catch(k){h(k.message),o("error")}}function b(k){switch(k){case"x":return"X (Twitter)";case"linkedin":return"LinkedIn";default:return k}}return c.jsx("div",{className:"conn-config-overlay",children:c.jsxs("div",{className:"conn-config-modal",ref:m,children:[c.jsxs("div",{className:"conn-config-modal__header",children:[c.jsxs("div",{className:"conn-config-modal__title",children:[b(e)," Settings"]}),c.jsx("div",{className:"conn-config-modal__subtitle",children:n})]}),i==="loading"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("div",{className:"conn-config-spinner"}),c.jsx("span",{children:"Loading configuration..."})]}),(i==="form"||i==="error")&&g.length>0&&c.jsxs("div",{className:"conn-config-modal__body",children:[g.map(k=>c.jsxs("div",{className:"conn-config-field",children:[c.jsxs("label",{className:"conn-config-field__label",children:[k.label,k.readonly&&c.jsx("span",{className:"conn-config-field__badge",children:"read-only"})]}),c.jsx("input",{className:"conn-config-field__input",value:l[k.key]||"",placeholder:k.placeholder,readOnly:k.readonly,onChange:w=>d(S=>({...S,[k.key]:w.target.value}))})]},k.key)),f&&c.jsx("div",{className:"conn-config-modal__error",children:f})]}),(i==="form"||i==="error")&&g.length===0&&c.jsx("div",{className:"conn-config-modal__body conn-config-modal__center",children:c.jsxs("span",{className:"conn-config-modal__empty",children:["No configuration needed for ",b(e),"."]})}),i==="saving"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("div",{className:"conn-config-spinner"}),c.jsx("span",{children:"Saving..."})]}),i==="saved"&&c.jsxs("div",{className:"conn-config-modal__body conn-config-modal__center",children:[c.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"#22c55e",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),c.jsx("span",{children:"Saved"})]}),c.jsxs("div",{className:"conn-config-modal__footer",children:[c.jsx("button",{className:"conn-config-btn conn-config-btn--secondary",onClick:r,children:i==="saved"?"Close":"Cancel"}),g.length>0&&(i==="form"||i==="error")&&c.jsx("button",{className:"conn-config-btn conn-config-btn--primary",onClick:v,children:"Save"})]})]})})}const F$=[{id:"x",label:"X (Twitter)",oauth:!0},{id:"linkedin",label:"LinkedIn",oauth:!0},{id:"newsletter",label:"Newsletter",oauth:!1}];function Pp(t){switch(t){case"x":return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})});case"linkedin":return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"})});case"newsletter":return c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2"}),c.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]});default:return c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("circle",{cx:"12",cy:"12",r:"10"})})}}function U$(t){return t==="active"?"connections-status--active":t==="expired"?"connections-status--expired":t==="revoked"?"connections-status--revoked":"connections-status--pending"}function H$(t){const[e,n]=x.useState([]),[r,s]=x.useState(null),[i,o]=x.useState(null),[l,d]=x.useState(null),[f,h]=x.useState(null),[m,g]=x.useState(null),v=x.useRef(null);async function b(){try{const A=await(await fetch("/api/connections")).json();s(A.authenticated!==!1);const O=(A.connections||[]).filter(B=>B&&B.id&&B.provider);return n(O),O}catch{return[]}}x.useEffect(()=>{b()},[]),x.useEffect(()=>()=>{v.current&&clearInterval(v.current)},[]);async function k(_){d(_);try{const A=await fetch(`/api/connections/oauth/${_}/start`,{method:"POST"}),O=await A.json();if(!A.ok||!O.url){d(null);return}window.open(O.url,"_blank","width=600,height=700"),v.current=setInterval(async()=>{try{const $=await(await fetch(`/api/connections/oauth/${_}/status/${O.state}`)).json();if($.status==="completed"){v.current&&clearInterval(v.current),v.current=null,d(null);const W=await b();if(_==="x"){const J=W.find(z=>z.provider==="x"&&z.status==="active");if(J!=null&&J.display_name){const z=J.display_name.replace("@","");localStorage.setItem("ow-x-handle",z),window.dispatchEvent(new StorageEvent("storage",{key:"ow-x-handle",newValue:z}))}}}else $.status==="failed"&&(v.current&&clearInterval(v.current),v.current=null,d(null))}catch{}},2e3)}catch{d(null)}}async function w(_){try{const A=await fetch(`/api/connections/${_}`,{method:"DELETE"});if(!A.ok){const O=await A.json().catch(()=>({error:"Delete failed"}));console.error("[Connections] Delete failed:",O.error)}}catch(A){console.error("[Connections] Delete error:",A)}o(null),await b()}const S=new Map,N=new Map;for(const _ of e){S.has(_.provider)||S.set(_.provider,_);const A=N.get(_.provider)||[];A.push(_),N.set(_.provider,A)}const T=new Set,M=r===!1;return c.jsxs("div",{className:"connections-tab",children:[m&&c.jsx(z$,{connectionId:m.id,provider:m.provider,displayName:m.display_name,onClose:()=>g(null),onSaved:()=>b()}),f&&c.jsx(B$,{existingConnection:f==="edit"?S.get("newsletter"):null,onClose:()=>h(null),onSaved:()=>b()}),M?c.jsxs("div",{className:"connections-dropdown__upsell",children:[c.jsx("p",{children:"Connect your X, LinkedIn, and other accounts to publish directly from OpenWriter."}),c.jsxs("p",{children:["Set up the ",c.jsx("strong",{children:"Publish"})," plugin to get started."]})]}):c.jsx("div",{className:"connections-dropdown__list",children:F$.flatMap(_=>{const A=T.has(_.id),O=N.get(_.id)||[],B=W=>i===W.id?c.jsxs("div",{className:"connections-dropdown__confirm",children:[c.jsxs("span",{children:["Disconnect ",W.display_name||_.label,"?"]}),c.jsxs("div",{className:"connections-dropdown__confirm-btns",children:[c.jsx("button",{onClick:()=>w(W.id),children:"Yes"}),c.jsx("button",{onClick:()=>o(null),children:"No"})]})]},W.id):c.jsxs("div",{className:"connections-dropdown__item",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Pp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:W.display_name||W.domain||_.label}),c.jsxs("div",{className:"connections-dropdown__type",children:[c.jsx("span",{className:`connections-status ${U$(W.status)}`}),"Connected"]})]}),c.jsxs("div",{className:"connections-dropdown__actions",children:[c.jsx("button",{className:"connections-dropdown__action-btn",onClick:()=>{_.id==="newsletter"?h("edit"):g({id:W.id,provider:_.id,display_name:W.display_name||_.label})},title:"Settings",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),c.jsx("button",{className:"connections-dropdown__action-btn connections-dropdown__action-btn--delete",onClick:()=>o(W.id),title:"Disconnect",children:"×"})]})]},W.id),$=O.map(B);return A?($.push(c.jsx("div",{className:"connections-dropdown__add-row",children:c.jsx("button",{className:"connections-dropdown__add-btn",onClick:()=>k(_.id),disabled:l!==null,children:l===_.id?"Connecting…":`+ Add ${_.label} repo`})},`${_.id}__add`)),$):O.length>0?$:_.oauth?[c.jsxs("div",{className:"connections-dropdown__item connections-dropdown__item--disconnected",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Pp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:_.label}),c.jsx("div",{className:"connections-dropdown__type",children:"Not connected"})]}),c.jsx("button",{className:"connections-dropdown__connect-inline-btn",onClick:()=>k(_.id),disabled:l!==null,children:l===_.id?"Connecting…":"Connect"})]},_.id)]:[c.jsxs("div",{className:"connections-dropdown__item connections-dropdown__item--disconnected",children:[c.jsx("div",{className:"connections-dropdown__icon",children:Pp(_.id)}),c.jsxs("div",{className:"connections-dropdown__info",children:[c.jsx("div",{className:"connections-dropdown__name",children:_.label}),c.jsx("div",{className:"connections-dropdown__type",children:"Built-in · Not configured"})]}),c.jsx("button",{className:"connections-dropdown__connect-inline-btn",onClick:()=>h("new"),children:"Configure"})]},_.id)]})})]})}const W$={tree:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M3 3h7v7H3zM14 3h7v4h-7zM14 10h7v4h-7zM3 13h7v8H3z"})}),files:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),c.jsx("polyline",{points:"14 2 14 8 20 8"})]}),timeline:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"2",x2:"12",y2:"22"}),c.jsx("circle",{cx:"12",cy:"6",r:"2"}),c.jsx("circle",{cx:"12",cy:"12",r:"2"}),c.jsx("circle",{cx:"12",cy:"18",r:"2"}),c.jsx("line",{x1:"14",y1:"6",x2:"20",y2:"6"}),c.jsx("line",{x1:"14",y1:"12",x2:"20",y2:"12"}),c.jsx("line",{x1:"14",y1:"18",x2:"20",y2:"18"})]}),board:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"5",height:"18",rx:"1"}),c.jsx("rect",{x:"10",y:"3",width:"5",height:"12",rx:"1"}),c.jsx("rect",{x:"17",y:"3",width:"5",height:"15",rx:"1"})]}),shelf:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 19V5"}),c.jsx("path",{d:"M8 19V7"}),c.jsx("path",{d:"M12 19V4"}),c.jsx("path",{d:"M16 19V8"}),c.jsx("path",{d:"M20 19V6"}),c.jsx("line",{x1:"2",y1:"20",x2:"22",y2:"20"})]})};function q$(t){const[e,n]=x.useState(NE),[r,s]=x.useState(CE),[i,o]=x.useState(Od),l=_E(),[d,f]=x.useState(ME),[h,m]=x.useState(jE),g=(N=e,T=r,M=i,_=l,A=d,O=h)=>{AE(N,T,M,_,A,O)},v=N=>{n(N),g(N)},b=()=>{const N=r==="light"?"dark":"light";s(N),g(void 0,N)},k=N=>{o(N),g(void 0,void 0,N),window.dispatchEvent(new CustomEvent("ow-sidebar-mode-change",{detail:N}))},w=N=>{f(N),g(void 0,void 0,void 0,void 0,N)},S=N=>{m(N),g(void 0,void 0,void 0,void 0,void 0,N)};return c.jsxs("div",{className:"appearance-tab",children:[c.jsx("div",{className:"appearance-section",children:c.jsxs("div",{className:"appearance-section-header",children:[c.jsx("span",{className:"appearance-section-title",children:"Mode"}),c.jsxs("button",{className:"appearance-mode-btn",onClick:b,title:r==="light"?"Switch to dark":"Switch to light",children:[r==="light"?c.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"5"}),c.jsx("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),c.jsx("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),c.jsx("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),c.jsx("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),c.jsx("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),c.jsx("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),c.jsx("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),c.jsx("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):c.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}),c.jsx("span",{children:r==="light"?"Light":"Dark"})]})]})}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Typography"})}),c.jsx("div",{className:"appearance-typeface-grid",children:wE.map(N=>c.jsx("button",{className:`appearance-style-option ${e===N.id?"active":""}`,onClick:()=>v(N.id),title:N.description,children:N.label},N.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Spacing"})}),c.jsx("div",{className:"appearance-typography-grid",children:EE.map(N=>c.jsx("button",{className:`appearance-style-option ${d===N.id?"active":""}`,onClick:()=>w(N.id),children:N.label},N.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Canvas"})}),c.jsx("div",{className:"appearance-style-grid",children:SE.map(N=>c.jsx("button",{className:`appearance-style-option ${h===N.id?"active":""}`,onClick:()=>S(N.id),children:N.label},N.id))})]}),c.jsxs("div",{className:"appearance-section",children:[c.jsx("div",{className:"appearance-section-header",children:c.jsx("span",{className:"appearance-section-title",children:"Layout"})}),c.jsx("div",{className:"appearance-mode-grid",children:kE.map(N=>c.jsxs("button",{className:`appearance-mode-option ${i===N.id?"active":""}`,onClick:()=>k(N.id),children:[W$[N.icon],c.jsx("span",{children:N.label})]},N.id))})]})]})}const qT=[{id:"review",label:"Review",scope:"doc",icon:c.jsx(I5,{}),Component:f$},{id:"activity",label:"Activity",scope:"workspace",icon:c.jsx(B5,{}),Component:j$},{id:"backlinks",label:"Backlinks",scope:"doc",icon:c.jsx(D5,{}),Component:g$},{id:"exports",label:"Export",scope:"doc",icon:c.jsx(P5,{}),Component:y$},{id:"versions",label:"Versions",scope:"doc",icon:c.jsx(L5,{}),Component:m$},{id:"plugins",label:"Plugins",scope:"settings",icon:c.jsx($5,{}),Component:P$},{id:"connections",label:"Connections",scope:"settings",icon:c.jsx(z5,{}),Component:H$},{id:"appearance",label:"Appearance",scope:"settings",icon:c.jsx(F5,{}),Component:q$}];function V$(t){return t?qT.find(e=>e.id===t)??null:null}function Pk({pendingDocs:t}){const{open:e,activeTab:n,openTab:r}=Yd(),[s,i]=x.useState(!1),[o,l]=x.useState(!1),d=x.useRef(0);return x.useEffect(()=>{const f=t.filenames.length,h=d.current;d.current=f,h===0&&f>0&&r("review")},[t.filenames.length,r]),x.useEffect(()=>{const f=()=>r("review");return window.addEventListener("ow-pending-write-applied",f),()=>window.removeEventListener("ow-pending-write-applied",f)},[r]),x.useEffect(()=>{const f=()=>{if(!(e&&n==="activity")){i(!0),window.setTimeout(()=>i(!1),500);try{localStorage.getItem("ow-bell-hint-seen")||(l(!0),localStorage.setItem("ow-bell-hint-seen","1"),window.setTimeout(()=>l(!1),6e3))}catch{}}};return window.addEventListener("ow-activity-event",f),()=>window.removeEventListener("ow-activity-event",f)},[e,n]),c.jsx("div",{className:"rail-icon-strip",role:"tablist","aria-label":"Right rail tabs",children:qT.map(f=>{const h=e&&n===f.id,m=f.id==="activity";return c.jsxs("button",{type:"button",role:"tab","aria-selected":h,className:["rail-icon-btn",h?"rail-icon-btn--active":"",`rail-icon-btn--scope-${f.scope}`,m&&s?"rail-icon-btn--pulsing":""].filter(Boolean).join(" "),onClick:()=>r(f.id),title:f.label,"aria-label":f.label,children:[f.icon,m&&o&&c.jsxs("div",{className:"rail-icon-hint",role:"tooltip",children:[c.jsx("span",{children:"Agent activity lives here."}),c.jsx("button",{type:"button",className:"rail-icon-hint-close",onClick:g=>{g.stopPropagation(),l(!1)},"aria-label":"Dismiss",children:"×"})]})]},f.id)})})}function K$(t){const{activeTab:e}=Yd(),n=V$(e);return c.jsx("div",{className:"rail-body",role:"tabpanel",children:n?c.jsx(n.Component,{...t}):null})}const G$=()=>c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),J$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M9 14l2 2 4-4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),Y$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M12 16v-5M9.5 13.5L12 11l2.5 2.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),X$=()=>c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("path",{d:"M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),c.jsx("path",{d:"M14 14l-4 4M10 14l4 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});function Q$({syncStatus:t,onSync:e}){const[n,r]=x.useState(!1),[s,i]=x.useState([]),[o,l]=x.useState(!1),d=x.useRef(null),f=x.useCallback(()=>{if(n){r(!1);return}r(!0),l(!0),fetch("/api/sync/pending").then(h=>h.json()).then(h=>i(h)).catch(()=>i([])).finally(()=>l(!1))},[n]);return x.useEffect(()=>{t.state!=="pending"&&r(!1)},[t.state]),x.useEffect(()=>{if(!n)return;const h=m=>{d.current&&!d.current.contains(m.target)&&r(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[n]),c.jsxs("div",{className:"sync-btn-group",ref:d,children:[c.jsxs("button",{className:`titlebar-btn sync-btn-state sync-${t.state}`,onClick:e,disabled:t.state==="syncing",title:t.lastSyncTime?`Last synced: ${new Date(t.lastSyncTime).toLocaleString()}`:"Sync to GitHub",children:[t.state==="unconfigured"&&c.jsxs(c.Fragment,{children:[c.jsx(G$,{})," Sync"]}),t.state==="synced"&&c.jsxs(c.Fragment,{children:[c.jsx(J$,{})," Synced"]}),t.state==="pending"&&c.jsxs(c.Fragment,{children:[c.jsx(Y$,{})," Sync",t.pendingFiles?` (${t.pendingFiles})`:""]}),t.state==="syncing"&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"sync-btn-spinner"})," Syncing..."]}),t.state==="error"&&c.jsxs(c.Fragment,{children:[c.jsx(X$,{})," Retry"]})]}),t.state==="pending"&&t.pendingFiles&&t.pendingFiles>0&&c.jsx("button",{className:"sync-details-btn",onClick:f,title:"View pending changes",children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:c.jsx("path",{d:n?"M3 7.5L6 4.5L9 7.5":"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n&&c.jsxs("div",{className:"sync-pending-dropdown",children:[c.jsx("div",{className:"sync-pending-header",children:"Changes to push"}),o?c.jsx("div",{className:"sync-pending-loading",children:"Loading..."}):s.length===0?c.jsx("div",{className:"sync-pending-loading",children:"No changes"}):c.jsx("div",{className:"sync-pending-list",children:s.map((h,m)=>c.jsxs("div",{className:`sync-pending-item sync-file-${h.status}`,children:[c.jsx("span",{className:"sync-file-badge",children:h.status[0].toUpperCase()}),c.jsx("span",{className:"sync-file-name",children:h.file})]},m))})]})]})}function Z$(t){const{syncStatus:e,onSync:n,onToggleToolbar:r,toolbarOpen:s,focusMode:i,onToggleFocusMode:o,...l}=t,{open:d,activeTab:f,width:h,setWidth:m,closeRail:g,openTab:v}=Yd(),b=x.useRef(null),k=x.useRef(null),w=x.useRef(i);x.useEffect(()=>{if(i!==w.current)if(w.current=i,i)k.current={open:d,activeTab:f},d&&g();else{const N=k.current;k.current=null,N!=null&&N.open&&N.activeTab&&v(N.activeTab)}},[i]);const S=x.useCallback(N=>{N.preventDefault();const T=N.clientX,M=h,_=O=>{const B=T-O.clientX;m(M+B)},A=()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",A)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",A)},[h,m]);return x.useEffect(()=>{if(!d)return;const N=T=>{T.key==="Escape"&&b.current&&b.current.contains(document.activeElement)&&(T.preventDefault(),g())};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[d,g]),d?c.jsxs("aside",{ref:b,className:"right-rail-column",style:{width:h,minWidth:h},"aria-label":"Right rail",children:[c.jsx("div",{className:"right-rail-resize-handle",onPointerDown:S,"aria-hidden":"true"}),c.jsxs("div",{className:"right-rail-topbar",children:[c.jsxs("div",{className:"right-rail-topbar-actions right-rail-topbar-actions--start",children:[c.jsx("button",{type:"button",className:"right-rail-topbar-btn",onClick:g,title:"Hide rail","aria-label":"Hide rail",children:c.jsx(U5,{})}),c.jsx("button",{type:"button",className:`right-rail-topbar-btn${i?" right-rail-topbar-btn--active":""}`,onClick:o,title:"Focus mode","aria-label":"Focus mode","aria-pressed":i,children:c.jsx(xT,{})}),c.jsx("button",{type:"button",className:`right-rail-topbar-btn${s?" right-rail-topbar-btn--active":""}`,onClick:r,title:"Toggle format toolbar","aria-label":"Toggle format toolbar","aria-pressed":s,children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 20h16"}),c.jsx("path",{d:"m6 16 6-12 6 12"}),c.jsx("path",{d:"M8 12h8"})]})})]}),c.jsx("div",{className:"right-rail-topbar-actions right-rail-topbar-actions--end",children:c.jsx(Q$,{syncStatus:e,onSync:n})})]}),c.jsx(Pk,{pendingDocs:l.pendingDocs}),c.jsx(K$,{...l})]}):c.jsx("div",{className:"right-rail-mount-keepalive",style:{display:"none"},children:c.jsx(Pk,{pendingDocs:l.pendingDocs})})}function ez({onClose:t,onSetupComplete:e}){const[n,r]=x.useState("detecting"),[s,i]=x.useState(null),[o,l]=x.useState("gh"),[d,f]=x.useState("openwriter-docs"),[h,m]=x.useState(!0),[g,v]=x.useState(""),[b,k]=x.useState(""),[w,S]=x.useState(""),[N,T]=x.useState("");x.useEffect(()=>{fetch("/api/sync/capabilities").then(_=>_.json()).then(_=>{i(_),_.ghAuthenticated?l("gh"):(_.gitInstalled,l("pat")),r("setup")}).catch(()=>{S("Failed to detect git capabilities"),r("error")})},[]);const M=x.useCallback(async()=>{r("progress"),T(o==="connect"?"Connecting to repository...":"Creating repository and syncing...");try{const _={method:o,repoName:d,isPrivate:h};o==="pat"&&(_.pat=g),o==="connect"&&(_.remoteUrl=b,_.pat=g||void 0);const A=await fetch("/api/sync/setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)});if(!A.ok){const O=await A.json().catch(()=>({}));throw new Error(O.error||`Setup failed (${A.status})`)}r("done"),e()}catch(_){S(_.message),r("error")}},[o,d,h,g,b,e]);return c.jsx("div",{className:"sync-modal-overlay",onClick:t,children:c.jsxs("div",{className:"sync-modal",onClick:_=>_.stopPropagation(),children:[c.jsxs("div",{className:"sync-modal-header",children:[c.jsx("h2",{children:"Sync to GitHub"}),c.jsx("button",{className:"sync-modal-close",onClick:t,children:"×"})]}),n==="detecting"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-spinner"}),c.jsx("p",{children:"Detecting git configuration..."})]}),n==="setup"&&s&&c.jsxs("div",{className:"sync-modal-body",children:[!s.gitInstalled&&c.jsxs("div",{className:"sync-warning",children:["Git is not installed. Please ",c.jsx("a",{href:"https://git-scm.com/downloads",target:"_blank",rel:"noreferrer",children:"install git"})," first."]}),s.gitInstalled&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"sync-tabs",children:[s.ghAuthenticated&&c.jsx("button",{className:`sync-tab${o==="gh"?" active":""}`,onClick:()=>l("gh"),children:"GitHub CLI"}),c.jsx("button",{className:`sync-tab${o==="pat"?" active":""}`,onClick:()=>l("pat"),children:"Personal Access Token"}),c.jsx("button",{className:`sync-tab${o==="connect"?" active":""}`,onClick:()=>l("connect"),children:"Connect Existing"})]}),o==="gh"&&c.jsxs("div",{className:"sync-form",children:[c.jsxs("label",{children:["Repository name",c.jsx("input",{type:"text",value:d,onChange:_=>f(_.target.value),placeholder:"openwriter-docs"})]}),c.jsxs("label",{className:"sync-checkbox",children:[c.jsx("input",{type:"checkbox",checked:h,onChange:_=>m(_.target.checked)}),"Private repository"]})]}),o==="pat"&&c.jsxs("div",{className:"sync-form",children:[!s.ghAuthenticated&&!s.ghInstalled&&c.jsxs("p",{className:"sync-hint",children:["Create a ",c.jsx("a",{href:"https://github.com/settings/tokens/new?scopes=repo&description=OpenWriter",target:"_blank",rel:"noreferrer",children:"Personal Access Token"})," with ",c.jsx("code",{children:"repo"})," scope."]}),c.jsxs("label",{children:["Personal Access Token",c.jsx("input",{type:"password",value:g,onChange:_=>v(_.target.value),placeholder:"ghp_..."})]}),c.jsxs("label",{children:["Repository name",c.jsx("input",{type:"text",value:d,onChange:_=>f(_.target.value),placeholder:"openwriter-docs"})]}),c.jsxs("label",{className:"sync-checkbox",children:[c.jsx("input",{type:"checkbox",checked:h,onChange:_=>m(_.target.checked)}),"Private repository"]})]}),o==="connect"&&c.jsxs("div",{className:"sync-form",children:[c.jsxs("label",{children:["Remote URL",c.jsx("input",{type:"text",value:b,onChange:_=>k(_.target.value),placeholder:"https://github.com/user/repo.git"})]}),c.jsxs("label",{children:["PAT (optional, for private repos)",c.jsx("input",{type:"password",value:g,onChange:_=>v(_.target.value),placeholder:"ghp_..."})]})]}),c.jsxs("div",{className:"sync-modal-actions",children:[c.jsx("button",{className:"sync-btn secondary",onClick:t,children:"Cancel"}),c.jsx("button",{className:"sync-btn primary",onClick:M,disabled:o==="pat"&&!g||o==="connect"&&!b||o!=="connect"&&!d,children:o==="connect"?"Connect & Sync":"Create & Sync"})]})]})]}),n==="progress"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-spinner"}),c.jsx("p",{children:N})]}),n==="done"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-success-icon",children:"✓"}),c.jsx("p",{children:"Successfully synced to GitHub!"}),c.jsx("div",{className:"sync-modal-actions",children:c.jsx("button",{className:"sync-btn primary",onClick:t,children:"Done"})})]}),n==="error"&&c.jsxs("div",{className:"sync-modal-body",children:[c.jsx("div",{className:"sync-error-msg",children:w}),c.jsxs("div",{className:"sync-modal-actions",children:[c.jsx("button",{className:"sync-btn secondary",onClick:()=>r("setup"),children:"Back"}),c.jsx("button",{className:"sync-btn secondary",onClick:t,children:"Close"})]})]})]})})}function tz({onNodeChanges:t,onAgentStatus:e,onDocumentSwitched:n,onDocumentReloaded:r,onDocumentsChanged:s,onWorkspacesChanged:i,onTitleChanged:o,onPendingDocsChanged:l,onMetadataChanged:d,onSyncStatus:f,onWritingStarted:h,onWritingFinished:m,onIdRewrites:g,onPendingFilenamesChanged:v,getEditorState:b}){const k=x.useRef(null),[w,S]=x.useState(!1),N=x.useRef(0),T=x.useRef(new Set),M=()=>{var j;return(j=se.current)==null?void 0:j.call(se,new Set(T.current))},_=x.useRef(t),A=x.useRef(e),O=x.useRef(n),B=x.useRef(s),$=x.useRef(i),W=x.useRef(o),J=x.useRef(l),z=x.useRef(f),G=x.useRef(d),D=x.useRef(h),U=x.useRef(m),q=x.useRef(g),se=x.useRef(v),V=x.useRef(r),re=x.useRef(b);_.current=t,A.current=e,O.current=n,B.current=s,$.current=i,W.current=o,J.current=l,G.current=d,z.current=f,D.current=h,U.current=m,q.current=g,se.current=v,V.current=r,re.current=b,x.useEffect(()=>{const L=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;let ee,he=!1,ge=1e3;function oe(){const we=new WebSocket(L);k.current=we,we.onopen=()=>{S(!0),ge=1e3,he&&we.send(JSON.stringify({type:"request-document"})),he=!0},we.onmessage=We=>{var He,Ze,Oe,Ke,mt,Ye,pe,gt,ft,at,nt,ht,Fe,ve;try{const X=JSON.parse(We.data);if(X.type==="node-changes"&&X.changes&&((He=_.current)==null||He.call(_,X.changes),typeof X.version=="number"&&(N.current=X.version)),X.type==="id-rewrites"&&Array.isArray(X.rewrites)&&((Ze=q.current)==null||Ze.call(q,X.rewrites)),X.type==="agent-status"&&((Oe=A.current)==null||Oe.call(A,!!X.agentConnected)),X.type==="document-switched"&&(N.current=0,(Ke=O.current)==null||Ke.call(O,{document:X.document,title:X.title,filename:X.filename,docId:X.docId,metadata:X.metadata,pendingMetadata:X.pendingMetadata??null}),window.dispatchEvent(new CustomEvent("ow-pending-metadata-changed",{detail:{docId:X.docId,pendingMetadata:X.pendingMetadata??null}}))),X.type==="pending-metadata-changed"&&window.dispatchEvent(new CustomEvent("ow-pending-metadata-changed",{detail:{docId:X.docId,pendingMetadata:X.pendingMetadata??null}})),X.type==="document-reloaded"&&(typeof X.version=="number"&&(N.current=X.version),(mt=V.current)==null||mt.call(V,{document:X.document,title:X.title,filename:X.filename,docId:X.docId,metadata:X.metadata,orphanCount:typeof X.orphanCount=="number"?X.orphanCount:0,staleBaselineCount:typeof X.staleBaselineCount=="number"?X.staleBaselineCount:0})),X.type==="metadata-changed"&&X.metadata&&((Ye=G.current)==null||Ye.call(G,X.metadata)),X.type==="documents-changed"&&((pe=B.current)==null||pe.call(B)),X.type==="workspaces-changed"&&((gt=$.current)==null||gt.call($)),X.type==="title-changed"&&X.title&&((ft=W.current)==null||ft.call(W,X.title)),X.type==="pending-docs-changed"&&X.pendingDocs&&((at=J.current)==null||at.call(J,X.pendingDocs)),X.type==="sync-status"&&((nt=z.current)==null||nt.call(z,{state:X.state,lastSyncTime:X.lastSyncTime,pendingFiles:X.pendingFiles,error:X.error})),X.type==="writing-started"&&X.title&&(typeof X.key=="string"&&(T.current.add(X.key),M()),(ht=D.current)==null||ht.call(D,X.title,X.target||null)),X.type==="writing-finished"&&(typeof X.key=="string"&&X.key?T.current.delete(X.key):T.current.clear(),M(),(Fe=U.current)==null||Fe.call(U)),X.type==="pending-writes-sync"&&Array.isArray(X.writes)&&(T.current=new Set(X.writes.map(Be=>Be.key).filter(Boolean)),M(),X.writes.length>0)){const Be=X.writes.reduce((te,de)=>te.startedAt>de.startedAt?te:de);Be!=null&&Be.title&&((ve=D.current)==null||ve.call(D,Be.title,Be.target||null))}X.type==="plugins-changed"&&window.dispatchEvent(new CustomEvent("ow-plugins-changed")),X.type==="comments-changed"&&X.filename&&window.dispatchEvent(new CustomEvent("ow-comments-changed",{detail:{filename:X.filename}})),X.type==="documents-changed"&&window.dispatchEvent(new CustomEvent("ow-documents-changed")),X.type==="metadata-changed"&&window.dispatchEvent(new CustomEvent("ow-metadata-changed",{detail:{metadata:X.metadata}})),X.type==="activity-log"&&Array.isArray(X.entries)&&window.dispatchEvent(new CustomEvent("ow-activity-seed",{detail:{entries:X.entries}})),X.type==="activity-event"&&X.event&&window.dispatchEvent(new CustomEvent("ow-activity-event",{detail:{event:X.event}}))}catch{}},we.onclose=()=>{S(!1),ee=setTimeout(oe,ge),ge=Math.min(ge*1.5,8e3)},we.onerror=()=>{we.close()}}oe();function xe(){var we;document.visibilityState==="visible"&&((we=k.current)==null?void 0:we.readyState)!==WebSocket.OPEN&&(clearTimeout(ee),ge=1e3,oe())}return document.addEventListener("visibilitychange",xe),()=>{clearTimeout(ee),document.removeEventListener("visibilitychange",xe),k.current&&(k.current.onclose=null,k.current.close())}},[]);const K=x.useCallback(j=>{var L;((L=k.current)==null?void 0:L.readyState)===WebSocket.OPEN&&k.current.send(JSON.stringify(j))},[]);return{connected:w,sendMessage:K,docVersionRef:N}}function nz(t){const[e,n]=x.useState(null),[r,s]=x.useState(!1),[i,o]=x.useState(null),l=x.useRef(void 0);return x.useEffect(()=>{if(!t){n(null),s(!1),o(null),l.current=void 0;return}t!==l.current&&(l.current=t,s(!0),o(null),fetch(`/api/tweet-embed?url=${encodeURIComponent(t)}`).then(d=>d.ok?d.json():d.json().then(f=>Promise.reject(new Error(f.error||`HTTP ${d.status}`)))).then(d=>{n(d),s(!1)}).catch(d=>{o(d.message),s(!1)}))},[t]),{tweet:e,loading:r,error:i}}function rz(t){var r;const e=t.view.dom,n=[];for(const s of e.children){const i=(r=s.innerText)==null?void 0:r.trim();i&&n.push(i)}return n.join(`
|
|
210
210
|
|
|
211
211
|
`)}function sz(t){const e=n=>{var r;if(n.type==="image"&&((r=n.attrs)!=null&&r.src))return n.attrs.src;if(n.content)for(const s of n.content){const i=e(s);if(i)return i}return null};return e(t.getJSON())}async function iz(t){try{const e=await fetch(t);if(!e.ok)return null;const n=await e.blob();return n.type==="image/png"?n:new Promise(r=>{const s=new Image,i=URL.createObjectURL(n);s.onload=()=>{const o=document.createElement("canvas");o.width=s.naturalWidth,o.height=s.naturalHeight,o.getContext("2d").drawImage(s,0,0),o.toBlob(l=>{URL.revokeObjectURL(i),r(l)},"image/png")},s.onerror=()=>{URL.revokeObjectURL(i),r(null)},s.src=i})}catch{return null}}function oz(t,e){const[n,r]=x.useState("idle"),s=x.useRef();return{copyText:x.useCallback(async()=>{const o=t.current[e];if(!o)return;const l=rz(o),d=sz(o);if(!(!l&&!d)){try{const f={};if(l&&(f["text/plain"]=new Blob([l],{type:"text/plain"})),d){const h=await iz(d);h&&(f["image/png"]=h)}Object.keys(f).length>0&&await navigator.clipboard.write([new ClipboardItem(f)])}catch{if(l){const f=document.createElement("textarea");f.value=l,f.style.position="fixed",f.style.opacity="0",document.body.appendChild(f),f.select(),document.execCommand("copy"),document.body.removeChild(f)}}r("copied"),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>r("idle"),2e3)}},[t,e]),copyState:n}}function Bp(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e4?`${(t/1e3).toFixed(0)}K`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString()}function az(t){try{const e=Date.now(),n=new Date(t).getTime(),r=Math.floor((e-n)/1e3);if(r<60)return`${r}s`;const s=Math.floor(r/60);if(s<60)return`${s}m`;const i=Math.floor(s/60);return i<24?`${i}h`:new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric"})}catch{return""}}const lz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M1.751 10c0-4.42 3.584-8 8.005-8h4.366c4.49 0 8.129 3.64 8.129 8.13 0 2.96-1.607 5.68-4.196 7.11l-8.054 4.46v-3.69h-.067c-4.49.1-8.183-3.51-8.183-8.01zm8.005-6c-3.317 0-6.005 2.69-6.005 6 0 3.37 2.77 6.08 6.138 6.01l.351-.01h1.761v2.3l5.087-2.81c1.951-1.08 3.163-3.13 3.163-5.36 0-3.39-2.744-6.13-6.129-6.13H9.756z"})}),cz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M4.5 3.88l4.432 4.14-1.364 1.46L5.5 7.55V16c0 1.1.896 2 2 2H13v2H7.5c-2.209 0-4-1.79-4-4V7.55L1.432 9.48.068 8.02 4.5 3.88zM16.5 6H11V4h5.5c2.209 0 4 1.79 4 4v8.45l2.068-1.93 1.364 1.46-4.432 4.14-4.432-4.14 1.364-1.46 2.068 1.93V8c0-1.1-.896-2-2-2z"})}),uz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M16.697 5.5c-1.222-.06-2.679.51-3.89 2.16l-.805 1.09-.806-1.09C9.984 6.01 8.526 5.44 7.304 5.5c-1.243.07-2.349.78-2.91 1.91-.552 1.12-.633 2.78.479 4.82 1.074 1.97 3.257 4.27 7.129 6.61 3.87-2.34 6.052-4.64 7.126-6.61 1.111-2.04 1.03-3.7.477-4.82-.561-1.13-1.666-1.84-2.908-1.91zm4.187 7.69c-1.351 2.48-4.001 5.12-8.379 7.67l-.503.3-.504-.3c-4.379-2.55-7.029-5.19-8.382-7.67-1.36-2.5-1.41-4.86-.514-6.67.887-1.79 2.647-2.91 4.601-3.01 1.651-.09 3.368.56 4.798 2.01 1.429-1.45 3.146-2.1 4.796-2.01 1.954.1 3.714 1.22 4.601 3.01.896 1.81.846 4.17-.514 6.67z"})}),dz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M4 4.5C4 3.12 5.119 2 6.5 2h11C18.881 2 20 3.12 20 4.5v18.44l-8-5.71-8 5.71V4.5zM6.5 4c-.276 0-.5.22-.5.5v14.56l6-4.29 6 4.29V4.5c0-.28-.224-.5-.5-.5h-11z"})}),fz=()=>c.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":"true",children:c.jsx("path",{fill:"currentColor",d:"M12 2.59l5.7 5.7-1.41 1.42L13 6.41V16h-2V6.41l-3.3 3.3-1.41-1.42L12 2.59zM21 15l-.02 3.51c0 1.38-1.12 2.49-2.5 2.49H5.5C4.11 21 3 19.88 3 18.5V15h2v3.5c0 .28.22.5.5.5h12.98c.28 0 .5-.22.5-.5L19 15h2z"})});function VT({tweet:t,nested:e,url:n}){const r=az(t.createdAt);return c.jsxs("div",{className:`tweet-embed-card${e?" tweet-embed-nested":""}${n?" tweet-embed-card--clickable":""}`,onClick:n?()=>window.open(n,"_blank","noopener,noreferrer"):void 0,role:n?"link":void 0,children:[c.jsxs("div",{className:"tweet-author-row",children:[t.author.avatarUrl?c.jsx("img",{className:"tweet-avatar",src:t.author.avatarUrl,alt:""}):c.jsx("div",{className:"tweet-avatar tweet-avatar-placeholder"}),c.jsxs("div",{className:"tweet-author-info",children:[c.jsx("span",{className:"tweet-author-name",children:t.author.name}),c.jsxs("span",{className:"tweet-author-handle",children:["@",t.author.username]}),r&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"tweet-author-separator",children:"·"}),c.jsx("span",{className:"tweet-author-timestamp",children:r})]})]})]}),c.jsx("div",{className:"tweet-text",children:t.text}),t.media&&t.media.length>0&&c.jsx("div",{className:"tweet-media","data-count":t.media.length,children:t.media.map((s,i)=>s.type==="photo"?c.jsx("img",{className:"tweet-media-img",src:s.url,alt:"",loading:"lazy"},i):s.type==="video"||s.type==="gif"?c.jsx("div",{className:"tweet-media-video-placeholder",children:c.jsx("span",{children:"Video"})},i):null)}),t.quoteTweet&&c.jsx(VT,{tweet:t.quoteTweet,nested:!0}),!e&&c.jsxs("div",{className:"tweet-actions-row",children:[c.jsxs("span",{className:"tweet-action tweet-action-reply",children:[c.jsx(lz,{}),t.metrics.replies>0&&Bp(t.metrics.replies)]}),c.jsxs("span",{className:"tweet-action tweet-action-retweet",children:[c.jsx(cz,{}),t.metrics.retweets>0&&Bp(t.metrics.retweets)]}),c.jsxs("span",{className:"tweet-action tweet-action-like",children:[c.jsx(uz,{}),t.metrics.likes>0&&Bp(t.metrics.likes)]}),c.jsx("span",{className:"tweet-action tweet-action-bookmark",children:c.jsx(dz,{})}),c.jsx("span",{className:"tweet-action tweet-action-share",children:c.jsx(fz,{})})]})]})}function Bk({tweet:t,url:e}){return c.jsx(VT,{tweet:t,url:e})}function hz({initialContent:t,initialPreviewImages:e,placeholder:n="What is happening?!",onUpdate:r,onReady:s,onFocus:i,onPreviewImagesChange:o}){const[l,d]=x.useState(e||[]),f=x.useRef(e||[]),h=x.useRef(!1),m=x.useRef(s);m.current=s;const g=x.useRef(o);g.current=o;const v=x.useCallback(S=>{var T;const N=S.slice(0,4);f.current=N,d(N),(T=g.current)==null||T.call(g,N)},[]),b=x.useCallback(S=>{if(h.current)return;const N=[],T=[];if(S.state.doc.descendants((O,B)=>{var $;O.type.name==="image"&&(($=O.attrs)!=null&&$.src)&&(N.push(O.attrs.src),T.push({from:B,to:B+O.nodeSize}))}),N.length===0)return;h.current=!0;const{tr:M}=S.state;for(let O=T.length-1;O>=0;O--)M.delete(T[O].from,T[O].to);S.view.dispatch(M);const _=f.current,A=4-_.length;A>0&&v([..._,...N.slice(0,A)]),h.current=!1},[v]),k=WC({extensions:[...iT,Gd.configure({placeholder:n})],content:t||"<p></p>",onCreate:({editor:S})=>{b(S)},onUpdate:({editor:S})=>{b(S),r==null||r(S)},onFocus:()=>{i==null||i()},editorProps:{handlePaste:pT,handleDrop:mT}},[t]);x.useEffect(()=>{k&&w5(k.view,{addToPreview:S=>{const N=f.current;N.length>=4||v([...N,S])},getPreviewImages:()=>f.current})},[k,v]),x.useEffect(()=>{if(!k)return;const{state:S}=k.view;if(S.plugins.some(M=>M.key==="pendingDecoration$"))return;const N=uT(),T=S.reconfigure({plugins:[...S.plugins,N]});k.view.updateState(T)},[k]),x.useEffect(()=>{if(!k)return;const{state:S}=k.view;if(S.plugins.some(M=>M.key==="commentDecoration$"))return;const N=fT(),T=S.reconfigure({plugins:[...S.plugins,N]});k.view.updateState(T)},[k]),x.useEffect(()=>{var S;k&&((S=m.current)==null||S.call(m,k))},[k]);const w=x.useCallback(S=>{v(f.current.filter((N,T)=>T!==S))},[v]);return k?c.jsxs(c.Fragment,{children:[c.jsx(Ov,{editor:k}),l.length>0&&c.jsx("div",{className:"tweet-preview-grid","data-count":l.length,children:l.map((S,N)=>c.jsxs("div",{className:"tweet-image-card",children:[c.jsx("img",{className:"tweet-image-card-img",src:S,alt:"",draggable:!1}),c.jsx("button",{className:"tweet-image-card-remove",onClick:()=>w(N),title:"Remove image",children:"×"})]},S))})]}):null}function pz({count:t,softLimit:e=280}){const n=e-t,r=Math.min(t/e,1),s=n<=20,i=s?30:26,o=2,l=(i-o)/2,d=2*Math.PI*l,f=d*(1-r);let h="var(--x-blue, #1d9bf0)";return n<=0?h="var(--x-red, #f4212e)":n<=20&&(h="var(--x-yellow, #ffd400)"),t===0?null:c.jsxs("div",{className:"tweet-char-counter",title:`${t} / ${e}`,style:{width:i,height:i},children:[c.jsxs("svg",{width:i,height:i,viewBox:`0 0 ${i} ${i}`,children:[c.jsx("circle",{cx:i/2,cy:i/2,r:l,fill:"none",stroke:"var(--x-border, #eff3f4)",strokeWidth:o}),c.jsx("circle",{cx:i/2,cy:i/2,r:l,fill:"none",stroke:h,strokeWidth:o,strokeDasharray:d,strokeDashoffset:f,strokeLinecap:"round",transform:`rotate(-90 ${i/2} ${i/2})`,style:{transition:"stroke-dashoffset 0.15s ease, stroke 0.15s ease"}})]}),s&&c.jsx("span",{className:"tweet-char-number",style:{color:h,fontSize:n<-9||n>9?10:11},children:n})]})}const $k="@openwriter/plugin-x-api",zk=[{key:"api-key",label:"API Key",env:"X_API_KEY"},{key:"api-secret",label:"API Secret",env:"X_API_SECRET"},{key:"access-token",label:"Access Token",env:"X_ACCESS_TOKEN"},{key:"access-token-secret",label:"Access Token Secret",env:"X_ACCESS_TOKEN_SECRET"}];function mz({onConnected:t,onCancel:e}){const[n,r]=x.useState({"api-key":"","api-secret":"","access-token":"","access-token-secret":""}),[s,i]=x.useState(!1),[o,l]=x.useState(""),d=zk.every(h=>n[h.key].trim()),f=async()=>{i(!0),l("");try{if(!(await fetch("/api/plugins/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:$k,config:n})})).ok)throw new Error("Failed to save config");const g=await(await fetch("/api/plugins/enable",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:$k})})).json();if(!g.success)throw new Error(g.error||"Failed to enable plugin");const b=await(await fetch("/api/x/status")).json();b.connected?t():l(b.error||"Could not verify X credentials. Check your API keys.")}catch(h){l(h.message||"Connection failed")}finally{i(!1)}};return c.jsxs("div",{className:"x-connect-prompt",children:[c.jsxs("div",{className:"x-connect-header",children:[c.jsx("span",{className:"x-connect-title",children:"Connect your X account to post"}),c.jsx("button",{className:"x-connect-cancel",onClick:e,title:"Cancel",children:c.jsx("svg",{viewBox:"0 0 24 24",width:"18",height:"18",children:c.jsx("path",{fill:"currentColor",d:"M10.59 12L4.54 5.96l1.42-1.42L12 10.59l6.04-6.05 1.42 1.42L13.41 12l6.05 6.04-1.42 1.42L12 13.41l-6.04 6.05-1.42-1.42L10.59 12z"})})})]}),c.jsx("div",{className:"x-connect-fields",children:zk.map(h=>c.jsxs("div",{className:"x-connect-field",children:[c.jsx("label",{className:"x-connect-label",children:h.label}),c.jsx("input",{type:"password",className:"x-connect-input",value:n[h.key],onChange:m=>r(g=>({...g,[h.key]:m.target.value})),placeholder:h.env,spellCheck:!1,autoComplete:"off"})]},h.key))}),o&&c.jsx("div",{className:"x-connect-error",children:o}),c.jsxs("div",{className:"x-connect-actions",children:[c.jsx("a",{className:"x-connect-dev-link",href:"https://developer.x.com/en/portal/dashboard",target:"_blank",rel:"noopener noreferrer",children:"Get credentials"}),c.jsx("button",{className:"x-connect-btn",onClick:f,disabled:!d||s,children:s?"Connecting...":"Connect"})]})]})}var Fk={},$p,Uk;function $s(){return Uk||(Uk=1,$p=function(t){return typeof t=="object"?t!==null:typeof t=="function"}),$p}var zp,Hk;function Tr(){if(Hk)return zp;Hk=1;var t=$s();return zp=function(e){if(!t(e))throw TypeError(e+" is not an object!");return e},zp}var Fp,Wk;function Zd(){return Wk||(Wk=1,Fp=function(t){if(t==null)throw TypeError("Can't call method on "+t);return t}),Fp}var Up,qk;function Mi(){if(qk)return Up;qk=1;var t=Zd();return Up=function(e){return Object(t(e))},Up}var Hp,Vk;function ef(){if(Vk)return Hp;Vk=1;var t=Math.ceil,e=Math.floor;return Hp=function(n){return isNaN(n=+n)?0:(n>0?e:t)(n)},Hp}var Wp,Kk;function go(){if(Kk)return Wp;Kk=1;var t=ef(),e=Math.min;return Wp=function(n){return n>0?e(t(n),9007199254740991):0},Wp}var qp,Gk;function KT(){if(Gk)return qp;Gk=1;var t=ef(),e=Zd();return qp=function(n){return function(r,s){var i=String(e(r)),o=t(s),l=i.length,d,f;return o<0||o>=l?n?"":void 0:(d=i.charCodeAt(o),d<55296||d>56319||o+1===l||(f=i.charCodeAt(o+1))<56320||f>57343?n?i.charAt(o):d:n?i.slice(o,o+2):(d-55296<<10)+(f-56320)+65536)}},qp}var Vp,Jk;function cy(){if(Jk)return Vp;Jk=1;var t=KT()(!0);return Vp=function(e,n,r){return n+(r?t(e,n).length:1)},Vp}var Kp,Yk;function tf(){if(Yk)return Kp;Yk=1;var t={}.toString;return Kp=function(e){return t.call(e).slice(8,-1)},Kp}var Gp={exports:{}},Jp={exports:{}},Yp={exports:{}},Xk;function ha(){if(Xk)return Yp.exports;Xk=1;var t=Yp.exports={version:"2.6.12"};return typeof __e=="number"&&(__e=t),Yp.exports}var Xp={exports:{}},Qk;function Hr(){if(Qk)return Xp.exports;Qk=1;var t=Xp.exports=typeof window<"u"&&window.Math==Math?window:typeof self<"u"&&self.Math==Math?self:Function("return this")();return typeof __g=="number"&&(__g=t),Xp.exports}var Qp,Zk;function nf(){return Zk||(Zk=1,Qp=!1),Qp}var e1;function rf(){if(e1)return Jp.exports;e1=1;var t=ha(),e=Hr(),n="__core-js_shared__",r=e[n]||(e[n]={});return(Jp.exports=function(s,i){return r[s]||(r[s]=i!==void 0?i:{})})("versions",[]).push({version:t.version,mode:nf()?"pure":"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"}),Jp.exports}var Zp,t1;function Bl(){if(t1)return Zp;t1=1;var t=0,e=Math.random();return Zp=function(n){return"Symbol(".concat(n===void 0?"":n,")_",(++t+e).toString(36))},Zp}var n1;function Bn(){if(n1)return Gp.exports;n1=1;var t=rf()("wks"),e=Bl(),n=Hr().Symbol,r=typeof n=="function",s=Gp.exports=function(i){return t[i]||(t[i]=r&&n[i]||(r?n:e)("Symbol."+i))};return s.store=t,Gp.exports}var em,r1;function uy(){if(r1)return em;r1=1;var t=tf(),e=Bn()("toStringTag"),n=t((function(){return arguments})())=="Arguments",r=function(s,i){try{return s[i]}catch{}};return em=function(s){var i,o,l;return s===void 0?"Undefined":s===null?"Null":typeof(o=r(i=Object(s),e))=="string"?o:n?t(i):(l=t(i))=="Object"&&typeof i.callee=="function"?"Arguments":l},em}var tm,s1;function dy(){if(s1)return tm;s1=1;var t=uy(),e=RegExp.prototype.exec;return tm=function(n,r){var s=n.exec;if(typeof s=="function"){var i=s.call(n,r);if(typeof i!="object")throw new TypeError("RegExp exec method returned something other than an Object or null");return i}if(t(n)!=="RegExp")throw new TypeError("RegExp#exec called on incompatible receiver");return e.call(n,r)},tm}var i1={},nm,o1;function sf(){if(o1)return nm;o1=1;var t=Tr();return nm=function(){var e=t(this),n="";return e.global&&(n+="g"),e.ignoreCase&&(n+="i"),e.multiline&&(n+="m"),e.unicode&&(n+="u"),e.sticky&&(n+="y"),n},nm}var rm,a1;function fy(){if(a1)return rm;a1=1;var t=sf(),e=RegExp.prototype.exec,n=String.prototype.replace,r=e,s="lastIndex",i=(function(){var d=/a/,f=/b*/g;return e.call(d,"a"),e.call(f,"a"),d[s]!==0||f[s]!==0})(),o=/()??/.exec("")[1]!==void 0,l=i||o;return l&&(r=function(f){var h=this,m,g,v,b;return o&&(g=new RegExp("^"+h.source+"$(?!\\s)",t.call(h))),i&&(m=h[s]),v=e.call(h,f),i&&v&&(h[s]=h.global?v.index+v[0].length:m),o&&v&&v.length>1&&n.call(v[0],g,function(){for(b=1;b<arguments.length-2;b++)arguments[b]===void 0&&(v[b]=void 0)}),v}),rm=r,rm}var sm={},im,l1;function ss(){return l1||(l1=1,im=function(t){try{return!!t()}catch{return!0}}),im}var om,c1;function Wr(){return c1||(c1=1,om=!ss()(function(){return Object.defineProperty({},"a",{get:function(){return 7}}).a!=7})),om}var am,u1;function GT(){if(u1)return am;u1=1;var t=$s(),e=Hr().document,n=t(e)&&t(e.createElement);return am=function(r){return n?e.createElement(r):{}},am}var lm,d1;function JT(){return d1||(d1=1,lm=!Wr()&&!ss()(function(){return Object.defineProperty(GT()("div"),"a",{get:function(){return 7}}).a!=7})),lm}var cm,f1;function hy(){if(f1)return cm;f1=1;var t=$s();return cm=function(e,n){if(!t(e))return e;var r,s;if(n&&typeof(r=e.toString)=="function"&&!t(s=r.call(e))||typeof(r=e.valueOf)=="function"&&!t(s=r.call(e))||!n&&typeof(r=e.toString)=="function"&&!t(s=r.call(e)))return s;throw TypeError("Can't convert object to primitive value")},cm}var h1;function is(){if(h1)return sm;h1=1;var t=Tr(),e=JT(),n=hy(),r=Object.defineProperty;return sm.f=Wr()?Object.defineProperty:function(i,o,l){if(t(i),o=n(o,!0),t(l),e)try{return r(i,o,l)}catch{}if("get"in l||"set"in l)throw TypeError("Accessors not supported!");return"value"in l&&(i[o]=l.value),i},sm}var um,p1;function $l(){return p1||(p1=1,um=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}}),um}var dm,m1;function ji(){if(m1)return dm;m1=1;var t=is(),e=$l();return dm=Wr()?function(n,r,s){return t.f(n,r,e(1,s))}:function(n,r,s){return n[r]=s,n},dm}var fm={exports:{}},hm,g1;function vo(){if(g1)return hm;g1=1;var t={}.hasOwnProperty;return hm=function(e,n){return t.call(e,n)},hm}var pm,v1;function gz(){return v1||(v1=1,pm=rf()("native-function-to-string",Function.toString)),pm}var y1;function zs(){if(y1)return fm.exports;y1=1;var t=Hr(),e=ji(),n=vo(),r=Bl()("src"),s=gz(),i="toString",o=(""+s).split(i);return ha().inspectSource=function(l){return s.call(l)},(fm.exports=function(l,d,f,h){var m=typeof f=="function";m&&(n(f,"name")||e(f,"name",d)),l[d]!==f&&(m&&(n(f,r)||e(f,r,l[d]?""+l[d]:o.join(String(d)))),l===t?l[d]=f:h?l[d]?l[d]=f:e(l,d,f):(delete l[d],e(l,d,f)))})(Function.prototype,i,function(){return typeof this=="function"&&this[r]||s.call(this)}),fm.exports}var mm,b1;function of(){return b1||(b1=1,mm=function(t){if(typeof t!="function")throw TypeError(t+" is not a function!");return t}),mm}var gm,x1;function af(){if(x1)return gm;x1=1;var t=of();return gm=function(e,n,r){if(t(e),n===void 0)return e;switch(r){case 1:return function(s){return e.call(n,s)};case 2:return function(s,i){return e.call(n,s,i)};case 3:return function(s,i,o){return e.call(n,s,i,o)}}return function(){return e.apply(n,arguments)}},gm}var vm,w1;function xr(){if(w1)return vm;w1=1;var t=Hr(),e=ha(),n=ji(),r=zs(),s=af(),i="prototype",o=function(l,d,f){var h=l&o.F,m=l&o.G,g=l&o.S,v=l&o.P,b=l&o.B,k=m?t:g?t[d]||(t[d]={}):(t[d]||{})[i],w=m?e:e[d]||(e[d]={}),S=w[i]||(w[i]={}),N,T,M,_;m&&(f=d);for(N in f)T=!h&&k&&k[N]!==void 0,M=(T?k:f)[N],_=b&&T?s(M,t):v&&typeof M=="function"?s(Function.call,M):M,k&&r(k,N,M,l&o.U),w[N]!=M&&n(w,N,_),v&&S[N]!=M&&(S[N]=M)};return t.core=e,o.F=1,o.G=2,o.S=4,o.P=8,o.B=16,o.W=32,o.U=64,o.R=128,vm=o,vm}var k1;function vz(){if(k1)return i1;k1=1;var t=fy();return xr()({target:"RegExp",proto:!0,forced:t!==/./.exec},{exec:t}),i1}var ym,S1;function py(){if(S1)return ym;S1=1,vz();var t=zs(),e=ji(),n=ss(),r=Zd(),s=Bn(),i=fy(),o=s("species"),l=!n(function(){var f=/./;return f.exec=function(){var h=[];return h.groups={a:"7"},h},"".replace(f,"$<a>")!=="7"}),d=(function(){var f=/(?:)/,h=f.exec;f.exec=function(){return h.apply(this,arguments)};var m="ab".split(f);return m.length===2&&m[0]==="a"&&m[1]==="b"})();return ym=function(f,h,m){var g=s(f),v=!n(function(){var T={};return T[g]=function(){return 7},""[f](T)!=7}),b=v?!n(function(){var T=!1,M=/a/;return M.exec=function(){return T=!0,null},f==="split"&&(M.constructor={},M.constructor[o]=function(){return M}),M[g](""),!T}):void 0;if(!v||!b||f==="replace"&&!l||f==="split"&&!d){var k=/./[g],w=m(r,g,""[f],function(M,_,A,O,B){return _.exec===i?v&&!B?{done:!0,value:k.call(_,A,O)}:{done:!0,value:M.call(A,_,O)}:{done:!1}}),S=w[0],N=w[1];t(String.prototype,f,S),e(RegExp.prototype,g,h==2?function(T,M){return N.call(T,this,M)}:function(T){return N.call(T,this)})}},ym}var E1;function yz(){if(E1)return Fk;E1=1;var t=Tr(),e=Mi(),n=go(),r=ef(),s=cy(),i=dy(),o=Math.max,l=Math.min,d=Math.floor,f=/\$([$&`']|\d\d?|<[^>]*>)/g,h=/\$([$&`']|\d\d?)/g,m=function(g){return g===void 0?g:String(g)};return py()("replace",2,function(g,v,b,k){return[function(N,T){var M=g(this),_=N==null?void 0:N[v];return _!==void 0?_.call(N,M,T):b.call(String(M),N,T)},function(S,N){var T=k(b,S,this,N);if(T.done)return T.value;var M=t(S),_=String(this),A=typeof N=="function";A||(N=String(N));var O=M.global;if(O){var B=M.unicode;M.lastIndex=0}for(var $=[];;){var W=i(M,_);if(W===null||($.push(W),!O))break;var J=String(W[0]);J===""&&(M.lastIndex=s(_,n(M.lastIndex),B))}for(var z="",G=0,D=0;D<$.length;D++){W=$[D];for(var U=String(W[0]),q=o(l(r(W.index),_.length),0),se=[],V=1;V<W.length;V++)se.push(m(W[V]));var re=W.groups;if(A){var K=[U].concat(se,q,_);re!==void 0&&K.push(re);var j=String(N.apply(void 0,K))}else j=w(U,_,q,se,re,N);q>=G&&(z+=_.slice(G,q)+j,G=q+U.length)}return z+_.slice(G)}];function w(S,N,T,M,_,A){var O=T+S.length,B=M.length,$=h;return _!==void 0&&(_=e(_),$=f),b.call(A,$,function(W,J){var z;switch(J.charAt(0)){case"$":return"$";case"&":return S;case"`":return N.slice(0,T);case"'":return N.slice(O);case"<":z=_[J.slice(1,-1)];break;default:var G=+J;if(G===0)return W;if(G>B){var D=d(G/10);return D===0?W:D<=B?M[D-1]===void 0?J.charAt(1):M[D-1]+J.charAt(1):W}z=M[G-1]}return z===void 0?"":z})}}),Fk}yz();var N1={},bm,C1;function my(){if(C1)return bm;C1=1;var t=tf();return bm=Object("z").propertyIsEnumerable(0)?Object:function(e){return t(e)=="String"?e.split(""):Object(e)},bm}var xm,_1;function yo(){if(_1)return xm;_1=1;var t=my(),e=Zd();return xm=function(n){return t(e(n))},xm}var wm,T1;function bz(){if(T1)return wm;T1=1;var t=ef(),e=Math.max,n=Math.min;return wm=function(r,s){return r=t(r),r<0?e(r+s,0):n(r,s)},wm}var km,M1;function YT(){if(M1)return km;M1=1;var t=yo(),e=go(),n=bz();return km=function(r){return function(s,i,o){var l=t(s),d=e(l.length),f=n(o,d),h;if(r&&i!=i){for(;d>f;)if(h=l[f++],h!=h)return!0}else for(;d>f;f++)if((r||f in l)&&l[f]===i)return r||f||0;return!r&&-1}},km}var Sm,j1;function zl(){if(j1)return Sm;j1=1;var t=ss();return Sm=function(e,n){return!!e&&t(function(){n?e.call(null,function(){},1):e.call(null)})},Sm}var A1;function xz(){if(A1)return N1;A1=1;var t=xr(),e=YT()(!1),n=[].indexOf,r=!!n&&1/[1].indexOf(1,-0)<0;return t(t.P+t.F*(r||!zl()(n)),"Array",{indexOf:function(i){return r?n.apply(this,arguments)||0:e(this,i,arguments[1])}}),N1}xz();var wz=/[a-z]{1,6}(?:[._][a-z]{1,2})?/i,XT=/\!'#%&'\(\)*\+,\\\-\.\/:;<=>\?@\[\]\^_{|}~\$/,R1={},Em={},Nm={},O1;function gy(){return O1||(O1=1,Nm.f={}.propertyIsEnumerable),Nm}var I1;function vy(){if(I1)return Em;I1=1;var t=gy(),e=$l(),n=yo(),r=hy(),s=vo(),i=JT(),o=Object.getOwnPropertyDescriptor;return Em.f=Wr()?o:function(d,f){if(d=n(d),f=r(f,!0),i)try{return o(d,f)}catch{}if(s(d,f))return e(!t.f.call(d,f),d[f])},Em}var Cm,L1;function kz(){if(L1)return Cm;L1=1;var t=$s(),e=Tr(),n=function(r,s){if(e(r),!t(s)&&s!==null)throw TypeError(s+": can't set as prototype!")};return Cm={set:Object.setPrototypeOf||("__proto__"in{}?(function(r,s,i){try{i=af()(Function.call,vy().f(Object.prototype,"__proto__").set,2),i(r,[]),s=!(r instanceof Array)}catch{s=!0}return function(l,d){return n(l,d),s?l.__proto__=d:i(l,d),l}})({},!1):void 0),check:n},Cm}var _m,D1;function Sz(){if(D1)return _m;D1=1;var t=$s(),e=kz().set;return _m=function(n,r,s){var i=r.constructor,o;return i!==s&&typeof i=="function"&&(o=i.prototype)!==s.prototype&&t(o)&&e&&e(n,o),n},_m}var Tm={},Mm,P1;function yy(){if(P1)return Mm;P1=1;var t=rf()("keys"),e=Bl();return Mm=function(n){return t[n]||(t[n]=e(n))},Mm}var jm,B1;function QT(){if(B1)return jm;B1=1;var t=vo(),e=yo(),n=YT()(!1),r=yy()("IE_PROTO");return jm=function(s,i){var o=e(s),l=0,d=[],f;for(f in o)f!=r&&t(o,f)&&d.push(f);for(;i.length>l;)t(o,f=i[l++])&&(~n(d,f)||d.push(f));return d},jm}var Am,$1;function by(){return $1||($1=1,Am="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")),Am}var z1;function lf(){if(z1)return Tm;z1=1;var t=QT(),e=by().concat("length","prototype");return Tm.f=Object.getOwnPropertyNames||function(r){return t(r,e)},Tm}var Rm,F1;function ZT(){if(F1)return Rm;F1=1;var t=$s(),e=tf(),n=Bn()("match");return Rm=function(r){var s;return t(r)&&((s=r[n])!==void 0?!!s:e(r)=="RegExp")},Rm}var Om,U1;function Ez(){if(U1)return Om;U1=1;var t=Hr(),e=is(),n=Wr(),r=Bn()("species");return Om=function(s){var i=t[s];n&&i&&!i[r]&&e.f(i,r,{configurable:!0,get:function(){return this}})},Om}var H1;function Nz(){if(H1)return R1;H1=1;var t=Hr(),e=Sz(),n=is().f,r=lf().f,s=ZT(),i=sf(),o=t.RegExp,l=o,d=o.prototype,f=/a/g,h=/a/g,m=new o(f)!==f;if(Wr()&&(!m||ss()(function(){return h[Bn()("match")]=!1,o(f)!=f||o(h)==h||o(f,"i")!="/a/i"}))){o=function(w,S){var N=this instanceof o,T=s(w),M=S===void 0;return!N&&T&&w.constructor===o&&M?w:e(m?new l(T&&!M?w.source:w,S):l((T=w instanceof o)?w.source:w,T&&M?i.call(w):S),N?this:d,o)};for(var g=function(k){k in o||n(o,k,{configurable:!0,get:function(){return l[k]},set:function(w){l[k]=w}})},v=r(l),b=0;v.length>b;)g(v[b++]);d.constructor=o,o.prototype=d,zs()(t,"RegExp",o)}return Ez()("RegExp"),R1}Nz();function jt(t,e,n){return n=n||"",typeof t!="string"&&(t.global&&n.indexOf("g")<0&&(n+="g"),t.ignoreCase&&n.indexOf("i")<0&&(n+="i"),t.multiline&&n.indexOf("m")<0&&(n+="m"),t=t.source),new RegExp(t.replace(/#\{(\w+)\}/g,function(r,s){var i=e[s]||"";return typeof i!="string"&&(i=i.source),i}),n)}var e2=/\x09-\x0D\x20\x85\xA0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000/;const t2=jt(/[#{spacesGroup}]/,{spacesGroup:e2});jt("(^|#{spaces})(\\$)(#{cashtag})(?=$|\\s|[#{punct}])",{cashtag:wz,spaces:t2,punct:XT},"gi");var W1={},q1;function Cz(){if(q1)return W1;q1=1;var t=Tr(),e=go(),n=cy(),r=dy();return py()("match",1,function(s,i,o,l){return[function(f){var h=s(this),m=f==null?void 0:f[i];return m!==void 0?m.call(f,h):new RegExp(f)[i](String(h))},function(d){var f=l(o,d,this);if(f.done)return f.value;var h=t(d),m=String(this);if(!h.global)return r(h,m);var g=h.unicode;h.lastIndex=0;for(var v=[],b=0,k;(k=r(h,m))!==null;){var w=String(k[0]);v[b]=w,w===""&&(h.lastIndex=n(m,e(h.lastIndex),g)),b++}return b===0?null:v}]}),W1}Cz();var n2=/[##]/;jt(/^(?:#{hashSigns}|:\/\/)/,{hashSigns:n2});var r2=jt(RegExp("(?:(?:한국|香港|澳門|新加坡|台灣|台湾|中國|中国|გე|ລາວ|ไทย|ලංකා|ഭാരതം|ಭಾರತ|భారత్|சிங்கப்பூர்|இலங்கை|இந்தியா|ଭାରତ|ભારત|ਭਾਰਤ|ভাৰত|ভারত|বাংলা|भारोत|भारतम्|भारत|ڀارت|پاکستان|موريتانيا|مليسيا|مصر|قطر|فلسطين|عمان|عراق|سورية|سودان|تونس|بھارت|بارت|ایران|امارات|المغرب|السعودية|الجزائر|البحرين|الاردن|հայ|қаз|укр|срб|рф|мон|мкд|ею|бел|бг|ευ|ελ|zw|zm|za|yt|ye|ws|wf|vu|vn|vi|vg|ve|vc|va|uz|uy|us|um|uk|ug|ua|tz|tw|tv|tt|tr|tp|to|tn|tm|tl|tk|tj|th|tg|tf|td|tc|sz|sy|sx|sv|su|st|ss|sr|so|sn|sm|sl|sk|sj|si|sh|sg|se|sd|sc|sb|sa|rw|ru|rs|ro|re|qa|py|pw|pt|ps|pr|pn|pm|pl|pk|ph|pg|pf|pe|pa|om|nz|nu|nr|np|no|nl|ni|ng|nf|ne|nc|na|mz|my|mx|mw|mv|mu|mt|ms|mr|mq|mp|mo|mn|mm|ml|mk|mh|mg|mf|me|md|mc|ma|ly|lv|lu|lt|ls|lr|lk|li|lc|lb|la|kz|ky|kw|kr|kp|kn|km|ki|kh|kg|ke|jp|jo|jm|je|it|is|ir|iq|io|in|im|il|ie|id|hu|ht|hr|hn|hm|hk|gy|gw|gu|gt|gs|gr|gq|gp|gn|gm|gl|gi|gh|gg|gf|ge|gd|gb|ga|fr|fo|fm|fk|fj|fi|eu|et|es|er|eh|eg|ee|ec|dz|do|dm|dk|dj|de|cz|cy|cx|cw|cv|cu|cr|co|cn|cm|cl|ck|ci|ch|cg|cf|cd|cc|ca|bz|by|bw|bv|bt|bs|br|bq|bo|bn|bm|bl|bj|bi|bh|bg|bf|be|bd|bb|ba|az|ax|aw|au|at|as|ar|aq|ao|an|am|al|ai|ag|af|ae|ad|ac)(?=[^0-9a-zA-Z@+-]|$))")),s2=/\u202A-\u202E\u061C\u200E\u200F\u2066\u2067\u2068\u2069/,xy=/\uFFFE\uFEFF\uFFFF/;function _z(t,e){return t.replace(/#\{(\w+)\}/g,function(n,r){return e[r]||""})}var Tz=_z("#{punct}#{spacesGroup}#{invalidCharsGroup}#{directionalMarkersGroup}",{punct:XT,spacesGroup:e2,invalidCharsGroup:xy,directionalMarkersGroup:s2}),i2=jt(/[^#{invalidDomainChars}]/,{invalidDomainChars:Tz}),Mz=jt(/(?:(?:#{validDomainChars}(?:-|#{validDomainChars})*)?#{validDomainChars}\.)/,{validDomainChars:i2}),o2=jt(RegExp("(?:(?:삼성|닷컴|닷넷|香格里拉|餐厅|食品|飞利浦|電訊盈科|集团|通販|购物|谷歌|诺基亚|联通|网络|网站|网店|网址|组织机构|移动|珠宝|点看|游戏|淡马锡|机构|書籍|时尚|新闻|政府|政务|招聘|手表|手机|我爱你|慈善|微博|广东|工行|家電|娱乐|天主教|大拿|大众汽车|在线|嘉里大酒店|嘉里|商标|商店|商城|公益|公司|八卦|健康|信息|佛山|企业|中文网|中信|世界|ポイント|ファッション|セール|ストア|コム|グーグル|クラウド|みんな|คอม|संगठन|नेट|कॉम|همراه|موقع|موبايلي|كوم|كاثوليك|عرب|شبكة|بيتك|بازار|العليان|ارامكو|اتصالات|ابوظبي|קום|сайт|рус|орг|онлайн|москва|ком|католик|дети|zuerich|zone|zippo|zip|zero|zara|zappos|yun|youtube|you|yokohama|yoga|yodobashi|yandex|yamaxun|yahoo|yachts|xyz|xxx|xperia|xin|xihuan|xfinity|xerox|xbox|wtf|wtc|wow|world|works|work|woodside|wolterskluwer|wme|winners|wine|windows|win|williamhill|wiki|wien|whoswho|weir|weibo|wedding|wed|website|weber|webcam|weatherchannel|weather|watches|watch|warman|wanggou|wang|walter|walmart|wales|vuelos|voyage|voto|voting|vote|volvo|volkswagen|vodka|vlaanderen|vivo|viva|vistaprint|vista|vision|visa|virgin|vip|vin|villas|viking|vig|video|viajes|vet|versicherung|vermögensberatung|vermögensberater|verisign|ventures|vegas|vanguard|vana|vacations|ups|uol|uno|university|unicom|uconnect|ubs|ubank|tvs|tushu|tunes|tui|tube|trv|trust|travelersinsurance|travelers|travelchannel|travel|training|trading|trade|toys|toyota|town|tours|total|toshiba|toray|top|tools|tokyo|today|tmall|tkmaxx|tjx|tjmaxx|tirol|tires|tips|tiffany|tienda|tickets|tiaa|theatre|theater|thd|teva|tennis|temasek|telefonica|telecity|tel|technology|tech|team|tdk|tci|taxi|tax|tattoo|tatar|tatamotors|target|taobao|talk|taipei|tab|systems|symantec|sydney|swiss|swiftcover|swatch|suzuki|surgery|surf|support|supply|supplies|sucks|style|study|studio|stream|store|storage|stockholm|stcgroup|stc|statoil|statefarm|statebank|starhub|star|staples|stada|srt|srl|spreadbetting|spot|sport|spiegel|space|soy|sony|song|solutions|solar|sohu|software|softbank|social|soccer|sncf|smile|smart|sling|skype|sky|skin|ski|site|singles|sina|silk|shriram|showtime|show|shouji|shopping|shop|shoes|shiksha|shia|shell|shaw|sharp|shangrila|sfr|sexy|sex|sew|seven|ses|services|sener|select|seek|security|secure|seat|search|scot|scor|scjohnson|science|schwarz|schule|school|scholarships|schmidt|schaeffler|scb|sca|sbs|sbi|saxo|save|sas|sarl|sapo|sap|sanofi|sandvikcoromant|sandvik|samsung|samsclub|salon|sale|sakura|safety|safe|saarland|ryukyu|rwe|run|ruhr|rugby|rsvp|room|rogers|rodeo|rocks|rocher|rmit|rip|rio|ril|rightathome|ricoh|richardli|rich|rexroth|reviews|review|restaurant|rest|republican|report|repair|rentals|rent|ren|reliance|reit|reisen|reise|rehab|redumbrella|redstone|red|recipes|realty|realtor|realestate|read|raid|radio|racing|qvc|quest|quebec|qpon|pwc|pub|prudential|pru|protection|property|properties|promo|progressive|prof|productions|prod|pro|prime|press|praxi|pramerica|post|porn|politie|poker|pohl|pnc|plus|plumbing|playstation|play|place|pizza|pioneer|pink|ping|pin|pid|pictures|pictet|pics|piaget|physio|photos|photography|photo|phone|philips|phd|pharmacy|pfizer|pet|pccw|pay|passagens|party|parts|partners|pars|paris|panerai|panasonic|pamperedchef|page|ovh|ott|otsuka|osaka|origins|orientexpress|organic|org|orange|oracle|open|ooo|onyourside|online|onl|ong|one|omega|ollo|oldnavy|olayangroup|olayan|okinawa|office|off|observer|obi|nyc|ntt|nrw|nra|nowtv|nowruz|now|norton|northwesternmutual|nokia|nissay|nissan|ninja|nikon|nike|nico|nhk|ngo|nfl|nexus|nextdirect|next|news|newholland|new|neustar|network|netflix|netbank|net|nec|nba|navy|natura|nationwide|name|nagoya|nadex|nab|mutuelle|mutual|museum|mtr|mtpc|mtn|msd|movistar|movie|mov|motorcycles|moto|moscow|mortgage|mormon|mopar|montblanc|monster|money|monash|mom|moi|moe|moda|mobily|mobile|mobi|mma|mls|mlb|mitsubishi|mit|mint|mini|mil|microsoft|miami|metlife|merckmsd|meo|menu|men|memorial|meme|melbourne|meet|media|med|mckinsey|mcdonalds|mcd|mba|mattel|maserati|marshalls|marriott|markets|marketing|market|map|mango|management|man|makeup|maison|maif|madrid|macys|luxury|luxe|lupin|lundbeck|ltda|ltd|lplfinancial|lpl|love|lotto|lotte|london|lol|loft|locus|locker|loans|loan|llp|llc|lixil|living|live|lipsy|link|linde|lincoln|limo|limited|lilly|like|lighting|lifestyle|lifeinsurance|life|lidl|liaison|lgbt|lexus|lego|legal|lefrak|leclerc|lease|lds|lawyer|law|latrobe|latino|lat|lasalle|lanxess|landrover|land|lancome|lancia|lancaster|lamer|lamborghini|ladbrokes|lacaixa|kyoto|kuokgroup|kred|krd|kpn|kpmg|kosher|komatsu|koeln|kiwi|kitchen|kindle|kinder|kim|kia|kfh|kerryproperties|kerrylogistics|kerryhotels|kddi|kaufen|juniper|juegos|jprs|jpmorgan|joy|jot|joburg|jobs|jnj|jmp|jll|jlc|jio|jewelry|jetzt|jeep|jcp|jcb|java|jaguar|iwc|iveco|itv|itau|istanbul|ist|ismaili|iselect|irish|ipiranga|investments|intuit|international|intel|int|insure|insurance|institute|ink|ing|info|infiniti|industries|inc|immobilien|immo|imdb|imamat|ikano|iinet|ifm|ieee|icu|ice|icbc|ibm|hyundai|hyatt|hughes|htc|hsbc|how|house|hotmail|hotels|hoteles|hot|hosting|host|hospital|horse|honeywell|honda|homesense|homes|homegoods|homedepot|holiday|holdings|hockey|hkt|hiv|hitachi|hisamitsu|hiphop|hgtv|hermes|here|helsinki|help|healthcare|health|hdfcbank|hdfc|hbo|haus|hangout|hamburg|hair|guru|guitars|guide|guge|gucci|guardian|group|grocery|gripe|green|gratis|graphics|grainger|gov|got|gop|google|goog|goodyear|goodhands|goo|golf|goldpoint|gold|godaddy|gmx|gmo|gmbh|gmail|globo|global|gle|glass|glade|giving|gives|gifts|gift|ggee|george|genting|gent|gea|gdn|gbiz|gay|garden|gap|games|game|gallup|gallo|gallery|gal|fyi|futbol|furniture|fund|fun|fujixerox|fujitsu|ftr|frontier|frontdoor|frogans|frl|fresenius|free|fox|foundation|forum|forsale|forex|ford|football|foodnetwork|food|foo|fly|flsmidth|flowers|florist|flir|flights|flickr|fitness|fit|fishing|fish|firmdale|firestone|fire|financial|finance|final|film|fido|fidelity|fiat|ferrero|ferrari|feedback|fedex|fast|fashion|farmers|farm|fans|fan|family|faith|fairwinds|fail|fage|extraspace|express|exposed|expert|exchange|everbank|events|eus|eurovision|etisalat|esurance|estate|esq|erni|ericsson|equipment|epson|epost|enterprises|engineering|engineer|energy|emerck|email|education|edu|edeka|eco|eat|earth|dvr|dvag|durban|dupont|duns|dunlop|duck|dubai|dtv|drive|download|dot|doosan|domains|doha|dog|dodge|doctor|docs|dnp|diy|dish|discover|discount|directory|direct|digital|diet|diamonds|dhl|dev|design|desi|dentist|dental|democrat|delta|deloitte|dell|delivery|degree|deals|dealer|deal|dds|dclk|day|datsun|dating|date|data|dance|dad|dabur|cyou|cymru|cuisinella|csc|cruises|cruise|crs|crown|cricket|creditunion|creditcard|credit|cpa|courses|coupons|coupon|country|corsica|coop|cool|cookingchannel|cooking|contractors|contact|consulting|construction|condos|comsec|computer|compare|company|community|commbank|comcast|com|cologne|college|coffee|codes|coach|clubmed|club|cloud|clothing|clinique|clinic|click|cleaning|claims|cityeats|city|citic|citi|citadel|cisco|circle|cipriani|church|chrysler|chrome|christmas|chloe|chintai|cheap|chat|chase|charity|channel|chanel|cfd|cfa|cern|ceo|center|ceb|cbs|cbre|cbn|cba|catholic|catering|cat|casino|cash|caseih|case|casa|cartier|cars|careers|career|care|cards|caravan|car|capitalone|capital|capetown|canon|cancerresearch|camp|camera|cam|calvinklein|call|cal|cafe|cab|bzh|buzz|buy|business|builders|build|bugatti|budapest|brussels|brother|broker|broadway|bridgestone|bradesco|box|boutique|bot|boston|bostik|bosch|boots|booking|book|boo|bond|bom|bofa|boehringer|boats|bnpparibas|bnl|bmw|bms|blue|bloomberg|blog|blockbuster|blanco|blackfriday|black|biz|bio|bingo|bing|bike|bid|bible|bharti|bet|bestbuy|best|berlin|bentley|beer|beauty|beats|bcn|bcg|bbva|bbt|bbc|bayern|bauhaus|basketball|baseball|bargains|barefoot|barclays|barclaycard|barcelona|bar|bank|band|bananarepublic|banamex|baidu|baby|azure|axa|aws|avianca|autos|auto|author|auspost|audio|audible|audi|auction|attorney|athleta|associates|asia|asda|arte|art|arpa|army|archi|aramco|arab|aquarelle|apple|app|apartments|aol|anz|anquan|android|analytics|amsterdam|amica|amfam|amex|americanfamily|americanexpress|alstom|alsace|ally|allstate|allfinanz|alipay|alibaba|alfaromeo|akdn|airtel|airforce|airbus|aigo|aig|agency|agakhan|africa|afl|afamilycompany|aetna|aero|aeg|adult|ads|adac|actor|active|aco|accountants|accountant|accenture|academy|abudhabi|abogado|able|abc|abbvie|abbott|abb|abarth|aarp|aaa|onion)(?=[^0-9a-zA-Z@+-]|$))")),a2=/(?:xn--[\-0-9a-z]+)/,jz=jt(/(?:(?:#{validDomainChars}(?:[_-]|#{validDomainChars})*)?#{validDomainChars}\.)/,{validDomainChars:i2}),Az=jt(/(?:#{validSubdomain}*#{validDomainName}(?:#{validGTLD}|#{validCCTLD}|#{validPunycode}))/,{validDomainName:Mz,validSubdomain:jz,validGTLD:o2,validCCTLD:r2,validPunycode:a2}),Rz=/[0-9]+/,l2=/\u0400-\u04FF/,cf=/\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u024F\u0253\u0254\u0256\u0257\u0259\u025B\u0263\u0268\u026F\u0272\u0289\u028B\u02BB\u0300-\u036F\u1E00-\u1EFF/,c2=jt(/[a-z#{cyrillicLettersAndMarks}0-9!\*';:=\+,\.\$\/%#\[\]\-\u2013_~@\|&#{latinAccentChars}]/i,{cyrillicLettersAndMarks:l2,latinAccentChars:cf}),u2=jt("\\((?:#{validGeneralUrlPathChars}+|(?:#{validGeneralUrlPathChars}*\\(#{validGeneralUrlPathChars}+\\)#{validGeneralUrlPathChars}*))\\)",{validGeneralUrlPathChars:c2},"i"),Oz=jt(/[\+\-a-z#{cyrillicLettersAndMarks}0-9=_#\/#{latinAccentChars}]|(?:#{validUrlBalancedParens})/i,{cyrillicLettersAndMarks:l2,latinAccentChars:cf,validUrlBalancedParens:u2}),Iz=jt("(?:(?:#{validGeneralUrlPathChars}*(?:#{validUrlBalancedParens}#{validGeneralUrlPathChars}*)*#{validUrlPathEndingChars})|(?:@#{validGeneralUrlPathChars}+/))",{validGeneralUrlPathChars:c2,validUrlBalancedParens:u2,validUrlPathEndingChars:Oz},"i"),Lz=jt(/(?:[^A-Za-z0-9@@$###{invalidCharsGroup}]|[#{directionalMarkersGroup}]|^)/,{invalidCharsGroup:xy,directionalMarkersGroup:s2}),d2=/[a-z0-9!?\*'@\(\);:&=\+\$\/%#\[\]\-_\.,~|]/i,f2=/[a-z0-9\-_&=#\/]/i,V1=jt("((#{validUrlPrecedingChars})((https?:\\/\\/)?(#{validDomain})(?::(#{validPortNumber}))?(\\/#{validUrlPath}*)?(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?))",{validUrlPrecedingChars:Lz,validDomain:Az,validPortNumber:Rz,validUrlPath:Iz,validUrlQueryChars:d2,validUrlQueryEndingChars:f2},"gi"),Dz=/[-_.\/]$/,K1={},Im,G1;function Pz(){if(G1)return Im;G1=1;var t=Tr(),e=of(),n=Bn()("species");return Im=function(r,s){var i=t(r).constructor,o;return i===void 0||(o=t(i)[n])==null?s:e(o)},Im}var J1;function Bz(){if(J1)return K1;J1=1;var t=ZT(),e=Tr(),n=Pz(),r=cy(),s=go(),i=dy(),o=fy(),l=ss(),d=Math.min,f=[].push,h="split",m="length",g="lastIndex",v=4294967295,b=!l(function(){});return py()("split",2,function(k,w,S,N){var T;return"abbc"[h](/(b)*/)[1]=="c"||"test"[h](/(?:)/,-1)[m]!=4||"ab"[h](/(?:ab)*/)[m]!=2||"."[h](/(.?)(.?)/)[m]!=4||"."[h](/()()/)[m]>1||""[h](/.?/)[m]?T=function(M,_){var A=String(this);if(M===void 0&&_===0)return[];if(!t(M))return S.call(A,M,_);for(var O=[],B=(M.ignoreCase?"i":"")+(M.multiline?"m":"")+(M.unicode?"u":"")+(M.sticky?"y":""),$=0,W=_===void 0?v:_>>>0,J=new RegExp(M.source,B+"g"),z,G,D;(z=o.call(J,A))&&(G=J[g],!(G>$&&(O.push(A.slice($,z.index)),z[m]>1&&z.index<A[m]&&f.apply(O,z.slice(1)),D=z[0][m],$=G,O[m]>=W)));)J[g]===z.index&&J[g]++;return $===A[m]?(D||!J.test(""))&&O.push(""):O.push(A.slice($)),O[m]>W?O.slice(0,W):O}:"0"[h](void 0,0)[m]?T=function(M,_){return M===void 0&&_===0?[]:S.call(this,M,_)}:T=S,[function(_,A){var O=k(this),B=_==null?void 0:_[w];return B!==void 0?B.call(_,O,A):T.call(String(O),_,A)},function(M,_){var A=N(T,M,this,_,T!==S);if(A.done)return A.value;var O=e(M),B=String(this),$=n(O,RegExp),W=O.unicode,J=(O.ignoreCase?"i":"")+(O.multiline?"m":"")+(O.unicode?"u":"")+(b?"y":"g"),z=new $(b?O:"^(?:"+O.source+")",J),G=_===void 0?v:_>>>0;if(G===0)return[];if(B.length===0)return i(z,B)===null?[B]:[];for(var D=0,U=0,q=[];U<B.length;){z.lastIndex=b?U:0;var se=i(z,b?B:B.slice(U)),V;if(se===null||(V=d(s(z.lastIndex+(b?0:U)),B.length))===D)U=r(B,U,W);else{if(q.push(B.slice(D,U)),q.length===G)return q;for(var re=1;re<=se.length-1;re++)if(q.push(se[re]),q.length===G)return q;U=D=V}}return q.push(B.slice(D)),q}]}),K1}Bz();var il={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */var $z=il.exports,Y1;function zz(){return Y1||(Y1=1,(function(t,e){(function(n){var r=e&&!e.nodeType&&e,s=t&&!t.nodeType&&t,i=typeof U0=="object"&&U0;(i.global===i||i.window===i||i.self===i)&&(n=i);var o,l=2147483647,d=36,f=1,h=26,m=38,g=700,v=72,b=128,k="-",w=/^xn--/,S=/[^\x20-\x7E]/,N=/[\x2E\u3002\uFF0E\uFF61]/g,T={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},M=d-f,_=Math.floor,A=String.fromCharCode,O;function B(K){throw new RangeError(T[K])}function $(K,j){for(var L=K.length,ee=[];L--;)ee[L]=j(K[L]);return ee}function W(K,j){var L=K.split("@"),ee="";L.length>1&&(ee=L[0]+"@",K=L[1]),K=K.replace(N,".");var he=K.split("."),ge=$(he,j).join(".");return ee+ge}function J(K){for(var j=[],L=0,ee=K.length,he,ge;L<ee;)he=K.charCodeAt(L++),he>=55296&&he<=56319&&L<ee?(ge=K.charCodeAt(L++),(ge&64512)==56320?j.push(((he&1023)<<10)+(ge&1023)+65536):(j.push(he),L--)):j.push(he);return j}function z(K){return $(K,function(j){var L="";return j>65535&&(j-=65536,L+=A(j>>>10&1023|55296),j=56320|j&1023),L+=A(j),L}).join("")}function G(K){return K-48<10?K-22:K-65<26?K-65:K-97<26?K-97:d}function D(K,j){return K+22+75*(K<26)-((j!=0)<<5)}function U(K,j,L){var ee=0;for(K=L?_(K/g):K>>1,K+=_(K/j);K>M*h>>1;ee+=d)K=_(K/M);return _(ee+(M+1)*K/(K+m))}function q(K){var j=[],L=K.length,ee,he=0,ge=b,oe=v,xe,we,We,He,Ze,Oe,Ke,mt,Ye;for(xe=K.lastIndexOf(k),xe<0&&(xe=0),we=0;we<xe;++we)K.charCodeAt(we)>=128&&B("not-basic"),j.push(K.charCodeAt(we));for(We=xe>0?xe+1:0;We<L;){for(He=he,Ze=1,Oe=d;We>=L&&B("invalid-input"),Ke=G(K.charCodeAt(We++)),(Ke>=d||Ke>_((l-he)/Ze))&&B("overflow"),he+=Ke*Ze,mt=Oe<=oe?f:Oe>=oe+h?h:Oe-oe,!(Ke<mt);Oe+=d)Ye=d-mt,Ze>_(l/Ye)&&B("overflow"),Ze*=Ye;ee=j.length+1,oe=U(he-He,ee,He==0),_(he/ee)>l-ge&&B("overflow"),ge+=_(he/ee),he%=ee,j.splice(he++,0,ge)}return z(j)}function se(K){var j,L,ee,he,ge,oe,xe,we,We,He,Ze,Oe=[],Ke,mt,Ye,pe;for(K=J(K),Ke=K.length,j=b,L=0,ge=v,oe=0;oe<Ke;++oe)Ze=K[oe],Ze<128&&Oe.push(A(Ze));for(ee=he=Oe.length,he&&Oe.push(k);ee<Ke;){for(xe=l,oe=0;oe<Ke;++oe)Ze=K[oe],Ze>=j&&Ze<xe&&(xe=Ze);for(mt=ee+1,xe-j>_((l-L)/mt)&&B("overflow"),L+=(xe-j)*mt,j=xe,oe=0;oe<Ke;++oe)if(Ze=K[oe],Ze<j&&++L>l&&B("overflow"),Ze==j){for(we=L,We=d;He=We<=ge?f:We>=ge+h?h:We-ge,!(we<He);We+=d)pe=we-He,Ye=d-He,Oe.push(A(D(He+pe%Ye,0))),we=_(pe/Ye);Oe.push(A(D(we,0))),ge=U(L,mt,ee==he),L=0,++ee}++L,++j}return Oe.join("")}function V(K){return W(K,function(j){return w.test(j)?q(j.slice(4).toLowerCase()):j})}function re(K){return W(K,function(j){return S.test(j)?"xn--"+se(j):j})}if(o={version:"1.4.1",ucs2:{decode:J,encode:z},decode:q,encode:se,toASCII:re,toUnicode:V},r&&s)if(t.exports==r)s.exports=o;else for(O in o)o.hasOwnProperty(O)&&(r[O]=o[O]);else n.punycode=o})($z)})(il,il.exports)),il.exports}var Fz=zz();const Uz=jl(Fz);var h2=jt(/(?:(?:[\-a-z0-9#{latinAccentChars}]+)\.)+(?:#{validGTLD}|#{validCCTLD}|#{validPunycode})/gi,{latinAccentChars:cf,validGTLD:o2,validCCTLD:r2,validPunycode:a2}),Hz=63,Wz="xn--",qz={toAscii:function(e){if(!(e.substring(0,4)===Wz&&!e.match(h2))){for(var n=e.split("."),r=0;r<n.length;r++){var s=n[r],i=Uz.toASCII(s);if(i.length<1||i.length>Hz)return}return n.join(".")}}},Vz=jt(/^https?:\/\/t\.co\/([a-z0-9]+)(?:\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?/,{validUrlQueryChars:d2,validUrlQueryEndingChars:f2},"i"),Kz="https://",Gz={extractUrlsWithoutProtocol:!0},Jz=4096,Yz=40,Xz=function(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Gz;if(!e||(n.extractUrlsWithoutProtocol?!e.match(/\./):!e.match(/:/)))return[];for(var r=[],s=function(){var l=RegExp.$2,d=RegExp.$3,f=RegExp.$4,h=RegExp.$5,m=RegExp.$7,g=V1.lastIndex,v=g-d.length;if(!Qz(d,f||Kz,h))return"continue";if(f){if(d.match(Vz)){var w=RegExp.$1;if(w&&w.length>Yz)return"continue";d=RegExp.lastMatch,g=v+d.length}r.push({url:d,indices:[v,g]})}else{if(!n.extractUrlsWithoutProtocol||l.match(Dz))return"continue";var b=null,k=0;if(h.replace(h2,function(S){var N=h.indexOf(S,k);k=N+S.length,b={url:S,indices:[v+N,v+k]},r.push(b)}),b==null)return"continue";m&&(b.url=d.replace(h,b.url),b.indices[1]=g)}};V1.exec(e);)var i=s();return r},Qz=function(e,n,r){var s=e.length,i=qz.toAscii(r);return!i||!i.length?!1:(s=s+i.length-r.length,n.length+s<=Jz)},X1={},Q1;function Zz(){if(Q1)return X1;Q1=1;var t=xr(),e=of(),n=Mi(),r=ss(),s=[].sort,i=[1,2,3];return t(t.P+t.F*(r(function(){i.sort(void 0)})||!r(function(){i.sort(null)})||!zl()(s)),"Array",{sort:function(l){return l===void 0?s.call(n(this)):s.call(n(this),e(l))}}),X1}Zz();var p2=/\ud800[\udc00-\udc0b\udc0d-\udc26\udc28-\udc3a\udc3c\udc3d\udc3f-\udc4d\udc50-\udc5d\udc80-\udcfa\uddfd\ude80-\ude9c\udea0-\uded0\udee0\udf00-\udf1f\udf30-\udf40\udf42-\udf49\udf50-\udf7a\udf80-\udf9d\udfa0-\udfc3\udfc8-\udfcf]|\ud801[\udc00-\udc9d\udd00-\udd27\udd30-\udd63\ude00-\udf36\udf40-\udf55\udf60-\udf67]|\ud802[\udc00-\udc05\udc08\udc0a-\udc35\udc37\udc38\udc3c\udc3f-\udc55\udc60-\udc76\udc80-\udc9e\udd00-\udd15\udd20-\udd39\udd80-\uddb7\uddbe\uddbf\ude00-\ude03\ude05\ude06\ude0c-\ude13\ude15-\ude17\ude19-\ude33\ude38-\ude3a\ude3f\ude60-\ude7c\ude80-\ude9c\udec0-\udec7\udec9-\udee6\udf00-\udf35\udf40-\udf55\udf60-\udf72\udf80-\udf91]|\ud803[\udc00-\udc48]|\ud804[\udc00-\udc46\udc7f-\udcba\udcd0-\udce8\udd00-\udd34\udd50-\udd73\udd76\udd80-\uddc4\uddda\ude00-\ude11\ude13-\ude37\udeb0-\udeea\udf01-\udf03\udf05-\udf0c\udf0f\udf10\udf13-\udf28\udf2a-\udf30\udf32\udf33\udf35-\udf39\udf3c-\udf44\udf47\udf48\udf4b-\udf4d\udf57\udf5d-\udf63\udf66-\udf6c\udf70-\udf74]|\ud805[\udc80-\udcc5\udcc7\udd80-\uddb5\uddb8-\uddc0\ude00-\ude40\ude44\ude80-\udeb7]|\ud806[\udca0-\udcdf\udcff\udec0-\udef8]|\ud808[\udc00-\udf98]|\ud80c[\udc00-\udfff]|\ud80d[\udc00-\udc2e]|\ud81a[\udc00-\ude38\ude40-\ude5e\uded0-\udeed\udef0-\udef4\udf00-\udf36\udf40-\udf43\udf63-\udf77\udf7d-\udf8f]|\ud81b[\udf00-\udf44\udf50-\udf7e\udf8f-\udf9f]|\ud82c[\udc00\udc01]|\ud82f[\udc00-\udc6a\udc70-\udc7c\udc80-\udc88\udc90-\udc99\udc9d\udc9e]|\ud834[\udd65-\udd69\udd6d-\udd72\udd7b-\udd82\udd85-\udd8b\uddaa-\uddad\ude42-\ude44]|\ud835[\udc00-\udc54\udc56-\udc9c\udc9e\udc9f\udca2\udca5\udca6\udca9-\udcac\udcae-\udcb9\udcbb\udcbd-\udcc3\udcc5-\udd05\udd07-\udd0a\udd0d-\udd14\udd16-\udd1c\udd1e-\udd39\udd3b-\udd3e\udd40-\udd44\udd46\udd4a-\udd50\udd52-\udea5\udea8-\udec0\udec2-\udeda\udedc-\udefa\udefc-\udf14\udf16-\udf34\udf36-\udf4e\udf50-\udf6e\udf70-\udf88\udf8a-\udfa8\udfaa-\udfc2\udfc4-\udfcb]|\ud83a[\udc00-\udcc4\udcd0-\udcd6]|\ud83b[\ude00-\ude03\ude05-\ude1f\ude21\ude22\ude24\ude27\ude29-\ude32\ude34-\ude37\ude39\ude3b\ude42\ude47\ude49\ude4b\ude4d-\ude4f\ude51\ude52\ude54\ude57\ude59\ude5b\ude5d\ude5f\ude61\ude62\ude64\ude67-\ude6a\ude6c-\ude72\ude74-\ude77\ude79-\ude7c\ude7e\ude80-\ude89\ude8b-\ude9b\udea1-\udea3\udea5-\udea9\udeab-\udebb]|\ud840[\udc00-\udfff]|\ud841[\udc00-\udfff]|\ud842[\udc00-\udfff]|\ud843[\udc00-\udfff]|\ud844[\udc00-\udfff]|\ud845[\udc00-\udfff]|\ud846[\udc00-\udfff]|\ud847[\udc00-\udfff]|\ud848[\udc00-\udfff]|\ud849[\udc00-\udfff]|\ud84a[\udc00-\udfff]|\ud84b[\udc00-\udfff]|\ud84c[\udc00-\udfff]|\ud84d[\udc00-\udfff]|\ud84e[\udc00-\udfff]|\ud84f[\udc00-\udfff]|\ud850[\udc00-\udfff]|\ud851[\udc00-\udfff]|\ud852[\udc00-\udfff]|\ud853[\udc00-\udfff]|\ud854[\udc00-\udfff]|\ud855[\udc00-\udfff]|\ud856[\udc00-\udfff]|\ud857[\udc00-\udfff]|\ud858[\udc00-\udfff]|\ud859[\udc00-\udfff]|\ud85a[\udc00-\udfff]|\ud85b[\udc00-\udfff]|\ud85c[\udc00-\udfff]|\ud85d[\udc00-\udfff]|\ud85e[\udc00-\udfff]|\ud85f[\udc00-\udfff]|\ud860[\udc00-\udfff]|\ud861[\udc00-\udfff]|\ud862[\udc00-\udfff]|\ud863[\udc00-\udfff]|\ud864[\udc00-\udfff]|\ud865[\udc00-\udfff]|\ud866[\udc00-\udfff]|\ud867[\udc00-\udfff]|\ud868[\udc00-\udfff]|\ud869[\udc00-\uded6\udf00-\udfff]|\ud86a[\udc00-\udfff]|\ud86b[\udc00-\udfff]|\ud86c[\udc00-\udfff]|\ud86d[\udc00-\udf34\udf40-\udfff]|\ud86e[\udc00-\udc1d]|\ud87e[\udc00-\ude1d]|\udb40[\udd00-\uddef]/,m2=/A-Za-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0300-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u0483-\u052f\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f2\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06df-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u06ff\u0710-\u074a\u074d-\u07b1\u07ca-\u07f5\u07fa\u0800-\u082d\u0840-\u085b\u08a0-\u08b2\u08e4-\u0963\u0971-\u0983\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bc-\u09c4\u09c7\u09c8\u09cb-\u09ce\u09d7\u09dc\u09dd\u09df-\u09e3\u09f0\u09f1\u0a01-\u0a03\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a59-\u0a5c\u0a5e\u0a70-\u0a75\u0a81-\u0a83\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abc-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ad0\u0ae0-\u0ae3\u0b01-\u0b03\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3c-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5c\u0b5d\u0b5f-\u0b63\u0b71\u0b82\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd0\u0bd7\u0c00-\u0c03\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c58\u0c59\u0c60-\u0c63\u0c81-\u0c83\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbc-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0cde\u0ce0-\u0ce3\u0cf1\u0cf2\u0d01-\u0d03\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d-\u0d44\u0d46-\u0d48\u0d4a-\u0d4e\u0d57\u0d60-\u0d63\u0d7a-\u0d7f\u0d82\u0d83\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e01-\u0e3a\u0e40-\u0e4e\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb9\u0ebb-\u0ebd\u0ec0-\u0ec4\u0ec6\u0ec8-\u0ecd\u0edc-\u0edf\u0f00\u0f18\u0f19\u0f35\u0f37\u0f39\u0f3e-\u0f47\u0f49-\u0f6c\u0f71-\u0f84\u0f86-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u103f\u1050-\u108f\u109a-\u109d\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u135d-\u135f\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16f1-\u16f8\u1700-\u170c\u170e-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176c\u176e-\u1770\u1772\u1773\u1780-\u17d3\u17d7\u17dc\u17dd\u180b-\u180d\u1820-\u1877\u1880-\u18aa\u18b0-\u18f5\u1900-\u191e\u1920-\u192b\u1930-\u193b\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a1b\u1a20-\u1a5e\u1a60-\u1a7c\u1a7f\u1aa7\u1ab0-\u1abe\u1b00-\u1b4b\u1b6b-\u1b73\u1b80-\u1baf\u1bba-\u1bf3\u1c00-\u1c37\u1c4d-\u1c4f\u1c5a-\u1c7d\u1cd0-\u1cd2\u1cd4-\u1cf6\u1cf8\u1cf9\u1d00-\u1df5\u1dfc-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u20d0-\u20f0\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2183\u2184\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d7f-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2de0-\u2dff\u2e2f\u3005\u3006\u302a-\u302f\u3031-\u3035\u303b\u303c\u3041-\u3096\u3099\u309a\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua672\ua674-\ua67d\ua67f-\ua69d\ua69f-\ua6e5\ua6f0\ua6f1\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua7ad\ua7b0\ua7b1\ua7f7-\ua827\ua840-\ua873\ua880-\ua8c4\ua8e0-\ua8f7\ua8fb\ua90a-\ua92d\ua930-\ua953\ua960-\ua97c\ua980-\ua9c0\ua9cf\ua9e0-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa36\uaa40-\uaa4d\uaa60-\uaa76\uaa7a-\uaac2\uaadb-\uaadd\uaae0-\uaaef\uaaf2-\uaaf6\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab5f\uab64\uab65\uabc0-\uabea\uabec\uabed\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf870-\uf87f\uf882\uf884-\uf89f\uf8b8\uf8c1-\uf8d6\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe00-\ufe0f\ufe20-\ufe2d\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc/,g2=/[\uD800-\uDBFF][\uDC00-\uDFFF]/gm,eF=jt(/(?:[#{bmpLetterAndMarks}]|(?=#{nonBmpCodePairs})(?:#{astralLetterAndMarks}))/,{bmpLetterAndMarks:m2,nonBmpCodePairs:g2,astralLetterAndMarks:p2}),tF=/\ud801[\udca0-\udca9]|\ud804[\udc66-\udc6f\udcf0-\udcf9\udd36-\udd3f\uddd0-\uddd9\udef0-\udef9]|\ud805[\udcd0-\udcd9\ude50-\ude59\udec0-\udec9]|\ud806[\udce0-\udce9]|\ud81a[\ude60-\ude69\udf50-\udf59]|\ud835[\udfce-\udfff]/,nF=/0-9\u0660-\u0669\u06f0-\u06f9\u07c0-\u07c9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be6-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0de6-\u0def\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u1040-\u1049\u1090-\u1099\u17e0-\u17e9\u1810-\u1819\u1946-\u194f\u19d0-\u19d9\u1a80-\u1a89\u1a90-\u1a99\u1b50-\u1b59\u1bb0-\u1bb9\u1c40-\u1c49\u1c50-\u1c59\ua620-\ua629\ua8d0-\ua8d9\ua900-\ua909\ua9d0-\ua9d9\ua9f0-\ua9f9\uaa50-\uaa59\uabf0-\uabf9\uff10-\uff19/,rF=/_\u200c\u200d\ua67e\u05be\u05f3\u05f4\uff5e\u301c\u309b\u309c\u30a0\u30fb\u3003\u0f0b\u0f0c\xb7/,v2=jt(/(?:[#{bmpLetterAndMarks}#{bmpNumerals}#{hashtagSpecialChars}]|(?=#{nonBmpCodePairs})(?:#{astralLetterAndMarks}|#{astralNumerals}))/,{bmpLetterAndMarks:m2,bmpNumerals:nF,hashtagSpecialChars:rF,nonBmpCodePairs:g2,astralLetterAndMarks:p2,astralNumerals:tF}),sF=/(?:[^\uD800-\uDFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF])/,iF=jt(/(?:^|\uFE0E|\uFE0F|$|(?!#{hashtagAlphaNumeric}|&)#{codePoint})/,{codePoint:sF,hashtagAlphaNumeric:v2});jt(/(#{hashtagBoundary})(#{hashSigns})(?!\uFE0F|\u20E3)(#{hashtagAlphaNumeric}*#{hashtagAlpha}#{hashtagAlphaNumeric}*)/gi,{hashtagBoundary:iF,hashSigns:n2,hashtagAlphaNumeric:v2,hashtagAlpha:eF});var wy=/[@@]/;jt(/^(?:#{atSigns}|[#{latinAccentChars}]|:\/\/)/,{atSigns:wy,latinAccentChars:cf});var oF=/(?:^|[^a-zA-Z0-9_!#$%&*@@]|(?:^|[^a-zA-Z0-9_+~.-])(?:rt|RT|rT|Rt):?)/,aF=jt("(#{validMentionPrecedingChars})(#{atSigns})([a-zA-Z0-9_]{1,20})(/[a-zA-Z][a-zA-Z0-9_-]{0,24})?",{validMentionPrecedingChars:oF,atSigns:wy},"g"),Z1={},eS={},tS;function lF(){return tS||(tS=1,Wr()&&/./g.flags!="g"&&is().f(RegExp.prototype,"flags",{configurable:!0,get:sf()})),eS}var nS;function cF(){if(nS)return Z1;nS=1,lF();var t=Tr(),e=sf(),n=Wr(),r="toString",s=/./[r],i=function(o){zs()(RegExp.prototype,r,o,!0)};return ss()(function(){return s.call({source:"a",flags:"b"})!="/a/b"})?i(function(){var l=t(this);return"/".concat(l.source,"/","flags"in l?l.flags:!n&&l instanceof RegExp?e.call(l):void 0)}):s.name!=r&&i(function(){return s.call(this)}),Z1}cF();var rS={},sS;function uF(){if(sS)return rS;sS=1;var t=Date.prototype,e="Invalid Date",n="toString",r=t[n],s=t.getTime;return new Date(NaN)+""!=e&&zs()(t,n,function(){var o=s.call(this);return o===o?r.call(this):e}),rS}uF();var iS={},oS;function dF(){if(oS)return iS;oS=1;var t=uy(),e={};return e[Bn()("toStringTag")]="z",e+""!="[object z]"&&zs()(Object.prototype,"toString",function(){return"[object "+t(this)+"]"},!0),iS}dF();const aS={defaults:{version:3,maxWeightedTweetLength:280,scale:100,defaultWeight:200,emojiParsingEnabled:!0,transformedURLLength:23,ranges:[{start:0,end:4351,weight:100},{start:8192,end:8205,weight:100},{start:8208,end:8223,weight:100},{start:8242,end:8247,weight:100}]}};jt(/^(?:#{spaces})*#{atSigns}([a-zA-Z0-9_]{1,20})/,{atSigns:wy,spaces:t2});var lS={},Lm,cS;function ky(){if(cS)return Lm;cS=1;var t=tf();return Lm=Array.isArray||function(n){return t(n)=="Array"},Lm}var uS;function fF(){if(uS)return lS;uS=1;var t=xr();return t(t.S,"Array",{isArray:ky()}),lS}fF();var hF=function(e,n){var r=n.defaultWeight,s=n.ranges,i=r,o=e.charCodeAt(0);if(Array.isArray(s))for(var l=0,d=s.length;l<d;l++){var f=s[l];if(o>=f.start&&o<=f.end){i=f.weight;break}}return i},dS={},Dm,fS;function pF(){if(fS)return Dm;fS=1;var t=of(),e=Mi(),n=my(),r=go();return Dm=function(s,i,o,l,d){t(i);var f=e(s),h=n(f),m=r(f.length),g=d?m-1:0,v=d?-1:1;if(o<2)for(;;){if(g in h){l=h[g],g+=v;break}if(g+=v,d?g<0:m<=g)throw TypeError("Reduce of empty array with no initial value")}for(;d?g>=0:m>g;g+=v)g in h&&(l=i(l,h[g],g,f));return l},Dm}var hS;function mF(){if(hS)return dS;hS=1;var t=xr(),e=pF();return t(t.P+t.F*!zl()([].reduce,!0),"Array",{reduce:function(r){return e(this,r,arguments.length,arguments[1],!1)}}),dS}mF();var pS={},Pm,mS;function gF(){if(mS)return Pm;mS=1;var t=Bn()("unscopables"),e=Array.prototype;return e[t]==null&&ji()(e,t,{}),Pm=function(n){e[t][n]=!0},Pm}var Bm,gS;function vF(){return gS||(gS=1,Bm=function(t,e){return{value:e,done:!!t}}),Bm}var $m,vS;function Fl(){return vS||(vS=1,$m={}),$m}var zm,yS;function Ul(){if(yS)return zm;yS=1;var t=QT(),e=by();return zm=Object.keys||function(r){return t(r,e)},zm}var Fm,bS;function y2(){if(bS)return Fm;bS=1;var t=is(),e=Tr(),n=Ul();return Fm=Wr()?Object.defineProperties:function(s,i){e(s);for(var o=n(i),l=o.length,d=0,f;l>d;)t.f(s,f=o[d++],i[f]);return s},Fm}var Um,xS;function yF(){if(xS)return Um;xS=1;var t=Hr().document;return Um=t&&t.documentElement,Um}var Hm,wS;function b2(){if(wS)return Hm;wS=1;var t=Tr(),e=y2(),n=by(),r=yy()("IE_PROTO"),s=function(){},i="prototype",o=function(){var l=GT()("iframe"),d=n.length,f="<",h=">",m;for(l.style.display="none",yF().appendChild(l),l.src="javascript:",m=l.contentWindow.document,m.open(),m.write(f+"script"+h+"document.F=Object"+f+"/script"+h),m.close(),o=m.F;d--;)delete o[i][n[d]];return o()};return Hm=Object.create||function(d,f){var h;return d!==null?(s[i]=t(d),h=new s,s[i]=null,h[r]=d):h=o(),f===void 0?h:e(h,f)},Hm}var Wm,kS;function Sy(){if(kS)return Wm;kS=1;var t=is().f,e=vo(),n=Bn()("toStringTag");return Wm=function(r,s,i){r&&!e(r=i?r:r.prototype,n)&&t(r,n,{configurable:!0,value:s})},Wm}var qm,SS;function bF(){if(SS)return qm;SS=1;var t=b2(),e=$l(),n=Sy(),r={};return ji()(r,Bn()("iterator"),function(){return this}),qm=function(s,i,o){s.prototype=t(r,{next:e(1,o)}),n(s,i+" Iterator")},qm}var Vm,ES;function xF(){if(ES)return Vm;ES=1;var t=vo(),e=Mi(),n=yy()("IE_PROTO"),r=Object.prototype;return Vm=Object.getPrototypeOf||function(s){return s=e(s),t(s,n)?s[n]:typeof s.constructor=="function"&&s instanceof s.constructor?s.constructor.prototype:s instanceof Object?r:null},Vm}var Km,NS;function x2(){if(NS)return Km;NS=1;var t=nf(),e=xr(),n=zs(),r=ji(),s=Fl(),i=bF(),o=Sy(),l=xF(),d=Bn()("iterator"),f=!([].keys&&"next"in[].keys()),h="@@iterator",m="keys",g="values",v=function(){return this};return Km=function(b,k,w,S,N,T,M){i(w,k,S);var _=function(se){if(!f&&se in $)return $[se];switch(se){case m:return function(){return new w(this,se)};case g:return function(){return new w(this,se)}}return function(){return new w(this,se)}},A=k+" Iterator",O=N==g,B=!1,$=b.prototype,W=$[d]||$[h]||N&&$[N],J=W||_(N),z=N?O?_("entries"):J:void 0,G=k=="Array"&&$.entries||W,D,U,q;if(G&&(q=l(G.call(new b)),q!==Object.prototype&&q.next&&(o(q,A,!0),!t&&typeof q[d]!="function"&&r(q,d,v))),O&&W&&W.name!==g&&(B=!0,J=function(){return W.call(this)}),(!t||M)&&(f||B||!$[d])&&r($,d,J),s[k]=J,s[A]=v,N)if(D={values:O?J:_(g),keys:T?J:_(m),entries:z},M)for(U in D)U in $||n($,U,D[U]);else e(e.P+e.F*(f||B),k,D);return D},Km}var Gm,CS;function w2(){if(CS)return Gm;CS=1;var t=gF(),e=vF(),n=Fl(),r=yo();return Gm=x2()(Array,"Array",function(s,i){this._t=r(s),this._i=0,this._k=i},function(){var s=this._t,i=this._k,o=this._i++;return!s||o>=s.length?(this._t=void 0,e(1)):i=="keys"?e(0,o):i=="values"?e(0,s[o]):e(0,[o,s[o]])},"values"),n.Arguments=n.Array,t("keys"),t("values"),t("entries"),Gm}var _S;function wF(){if(_S)return pS;_S=1;for(var t=w2(),e=Ul(),n=zs(),r=Hr(),s=ji(),i=Fl(),o=Bn(),l=o("iterator"),d=o("toStringTag"),f=i.Array,h={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},m=e(h),g=0;g<m.length;g++){var v=m[g],b=h[v],k=r[v],w=k&&k.prototype,S;if(w&&(w[l]||s(w,l,f),w[d]||s(w,d,v),i[v]=f,b))for(S in t)w[S]||n(w,S,t[S],!0)}return pS}wF();w2();var TS={},Jm,MS;function kF(){if(MS)return Jm;MS=1;var t=xr(),e=ha(),n=ss();return Jm=function(r,s){var i=(e.Object||{})[r]||Object[r],o={};o[r]=s(i),t(t.S+t.F*n(function(){i(1)}),"Object",o)},Jm}var jS;function SF(){if(jS)return TS;jS=1;var t=Mi(),e=Ul();return kF()("keys",function(){return function(r){return e(t(r))}}),TS}SF();var EF=jt(/[#{invalidCharsGroup}]/,{invalidCharsGroup:xy});function NF(t){return EF.test(t)}var Gi={},xu={},AS;function CF(){return AS||(AS=1,Object.defineProperty(xu,"__esModule",{value:!0}),xu.default=/(?:\ud83d[\udc68\udc69])(?:\ud83c[\udffb-\udfff])?\u200d(?:\u2695\ufe0f|\u2696\ufe0f|\u2708\ufe0f|\ud83c[\udf3e\udf73\udf93\udfa4\udfa8\udfeb\udfed]|\ud83d[\udcbb\udcbc\udd27\udd2c\ude80\ude92]|\ud83e[\uddb0-\uddb3])|(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75]|\u26f9)((?:\ud83c[\udffb-\udfff]|\ufe0f)\u200d[\u2640\u2642]\ufe0f)|(?:\ud83c[\udfc3\udfc4\udfca]|\ud83d[\udc6e\udc71\udc73\udc77\udc81\udc82\udc86\udc87\ude45-\ude47\ude4b\ude4d\ude4e\udea3\udeb4-\udeb6]|\ud83e[\udd26\udd35\udd37-\udd39\udd3d\udd3e\uddb8\uddb9\uddd6-\udddd])(?:\ud83c[\udffb-\udfff])?\u200d[\u2640\u2642]\ufe0f|(?:\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d\udc8b\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\u2764\ufe0f\u200d\ud83d\udc68|\ud83d\udc68\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc68\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\u2764\ufe0f\u200d\ud83d[\udc68\udc69]|\ud83d\udc69\u200d\ud83d\udc66\u200d\ud83d\udc66|\ud83d\udc69\u200d\ud83d\udc67\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83c\udff3\ufe0f\u200d\ud83c\udf08|\ud83c\udff4\u200d\u2620\ufe0f|\ud83d\udc41\u200d\ud83d\udde8|\ud83d\udc68\u200d\ud83d[\udc66\udc67]|\ud83d\udc69\u200d\ud83d[\udc66\udc67]|\ud83d\udc6f\u200d\u2640\ufe0f|\ud83d\udc6f\u200d\u2642\ufe0f|\ud83e\udd3c\u200d\u2640\ufe0f|\ud83e\udd3c\u200d\u2642\ufe0f|\ud83e\uddde\u200d\u2640\ufe0f|\ud83e\uddde\u200d\u2642\ufe0f|\ud83e\udddf\u200d\u2640\ufe0f|\ud83e\udddf\u200d\u2642\ufe0f)|[#*0-9]\ufe0f?\u20e3|(?:[©®\u2122\u265f]\ufe0f)|(?:\ud83c[\udc04\udd70\udd71\udd7e\udd7f\ude02\ude1a\ude2f\ude37\udf21\udf24-\udf2c\udf36\udf7d\udf96\udf97\udf99-\udf9b\udf9e\udf9f\udfcd\udfce\udfd4-\udfdf\udff3\udff5\udff7]|\ud83d[\udc3f\udc41\udcfd\udd49\udd4a\udd6f\udd70\udd73\udd76-\udd79\udd87\udd8a-\udd8d\udda5\udda8\uddb1\uddb2\uddbc\uddc2-\uddc4\uddd1-\uddd3\udddc-\uddde\udde1\udde3\udde8\uddef\uddf3\uddfa\udecb\udecd-\udecf\udee0-\udee5\udee9\udef0\udef3]|[\u203c\u2049\u2139\u2194-\u2199\u21a9\u21aa\u231a\u231b\u2328\u23cf\u23ed-\u23ef\u23f1\u23f2\u23f8-\u23fa\u24c2\u25aa\u25ab\u25b6\u25c0\u25fb-\u25fe\u2600-\u2604\u260e\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262a\u262e\u262f\u2638-\u263a\u2640\u2642\u2648-\u2653\u2660\u2663\u2665\u2666\u2668\u267b\u267f\u2692-\u2697\u2699\u269b\u269c\u26a0\u26a1\u26aa\u26ab\u26b0\u26b1\u26bd\u26be\u26c4\u26c5\u26c8\u26cf\u26d1\u26d3\u26d4\u26e9\u26ea\u26f0-\u26f5\u26f8\u26fa\u26fd\u2702\u2708\u2709\u270f\u2712\u2714\u2716\u271d\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u2764\u27a1\u2934\u2935\u2b05-\u2b07\u2b1b\u2b1c\u2b50\u2b55\u3030\u303d\u3297\u3299])(?:\ufe0f|(?!\ufe0e))|(?:(?:\ud83c[\udfcb\udfcc]|\ud83d[\udd74\udd75\udd90]|[\u261d\u26f7\u26f9\u270c\u270d])(?:\ufe0f|(?!\ufe0e))|(?:\ud83c[\udf85\udfc2-\udfc4\udfc7\udfca]|\ud83d[\udc42\udc43\udc46-\udc50\udc66-\udc69\udc6e\udc70-\udc78\udc7c\udc81-\udc83\udc85-\udc87\udcaa\udd7a\udd95\udd96\ude45-\ude47\ude4b-\ude4f\udea3\udeb4-\udeb6\udec0\udecc]|\ud83e[\udd18-\udd1c\udd1e\udd1f\udd26\udd30-\udd39\udd3d\udd3e\uddb5\uddb6\uddb8\uddb9\uddd1-\udddd]|[\u270a\u270b]))(?:\ud83c[\udffb-\udfff])?|(?:\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc65\udb40\udc6e\udb40\udc67\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc73\udb40\udc63\udb40\udc74\udb40\udc7f|\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc77\udb40\udc6c\udb40\udc73\udb40\udc7f|\ud83c\udde6\ud83c[\udde8-\uddec\uddee\uddf1\uddf2\uddf4\uddf6-\uddfa\uddfc\uddfd\uddff]|\ud83c\udde7\ud83c[\udde6\udde7\udde9-\uddef\uddf1-\uddf4\uddf6-\uddf9\uddfb\uddfc\uddfe\uddff]|\ud83c\udde8\ud83c[\udde6\udde8\udde9\uddeb-\uddee\uddf0-\uddf5\uddf7\uddfa-\uddff]|\ud83c\udde9\ud83c[\uddea\uddec\uddef\uddf0\uddf2\uddf4\uddff]|\ud83c\uddea\ud83c[\udde6\udde8\uddea\uddec\udded\uddf7-\uddfa]|\ud83c\uddeb\ud83c[\uddee-\uddf0\uddf2\uddf4\uddf7]|\ud83c\uddec\ud83c[\udde6\udde7\udde9-\uddee\uddf1-\uddf3\uddf5-\uddfa\uddfc\uddfe]|\ud83c\udded\ud83c[\uddf0\uddf2\uddf3\uddf7\uddf9\uddfa]|\ud83c\uddee\ud83c[\udde8-\uddea\uddf1-\uddf4\uddf6-\uddf9]|\ud83c\uddef\ud83c[\uddea\uddf2\uddf4\uddf5]|\ud83c\uddf0\ud83c[\uddea\uddec-\uddee\uddf2\uddf3\uddf5\uddf7\uddfc\uddfe\uddff]|\ud83c\uddf1\ud83c[\udde6-\udde8\uddee\uddf0\uddf7-\uddfb\uddfe]|\ud83c\uddf2\ud83c[\udde6\udde8-\udded\uddf0-\uddff]|\ud83c\uddf3\ud83c[\udde6\udde8\uddea-\uddec\uddee\uddf1\uddf4\uddf5\uddf7\uddfa\uddff]|\ud83c\uddf4\ud83c\uddf2|\ud83c\uddf5\ud83c[\udde6\uddea-\udded\uddf0-\uddf3\uddf7-\uddf9\uddfc\uddfe]|\ud83c\uddf6\ud83c\udde6|\ud83c\uddf7\ud83c[\uddea\uddf4\uddf8\uddfa\uddfc]|\ud83c\uddf8\ud83c[\udde6-\uddea\uddec-\uddf4\uddf7-\uddf9\uddfb\uddfd-\uddff]|\ud83c\uddf9\ud83c[\udde6\udde8\udde9\uddeb-\udded\uddef-\uddf4\uddf7\uddf9\uddfb\uddfc\uddff]|\ud83c\uddfa\ud83c[\udde6\uddec\uddf2\uddf3\uddf8\uddfe\uddff]|\ud83c\uddfb\ud83c[\udde6\udde8\uddea\uddec\uddee\uddf3\uddfa]|\ud83c\uddfc\ud83c[\uddeb\uddf8]|\ud83c\uddfd\ud83c\uddf0|\ud83c\uddfe\ud83c[\uddea\uddf9]|\ud83c\uddff\ud83c[\udde6\uddf2\uddfc]|\ud83c[\udccf\udd8e\udd91-\udd9a\udde6-\uddff\ude01\ude32-\ude36\ude38-\ude3a\ude50\ude51\udf00-\udf20\udf2d-\udf35\udf37-\udf7c\udf7e-\udf84\udf86-\udf93\udfa0-\udfc1\udfc5\udfc6\udfc8\udfc9\udfcf-\udfd3\udfe0-\udff0\udff4\udff8-\udfff]|\ud83d[\udc00-\udc3e\udc40\udc44\udc45\udc51-\udc65\udc6a-\udc6d\udc6f\udc79-\udc7b\udc7d-\udc80\udc84\udc88-\udca9\udcab-\udcfc\udcff-\udd3d\udd4b-\udd4e\udd50-\udd67\udda4\uddfb-\ude44\ude48-\ude4a\ude80-\udea2\udea4-\udeb3\udeb7-\udebf\udec1-\udec5\uded0-\uded2\udeeb\udeec\udef4-\udef9]|\ud83e[\udd10-\udd17\udd1d\udd20-\udd25\udd27-\udd2f\udd3a\udd3c\udd40-\udd45\udd47-\udd70\udd73-\udd76\udd7a\udd7c-\udda2\uddb4\uddb7\uddc0-\uddc2\uddd0\uddde-\uddff]|[\u23e9-\u23ec\u23f0\u23f3\u267e\u26ce\u2705\u2728\u274c\u274e\u2753-\u2755\u2795-\u2797\u27b0\u27bf\ue50a])|\ufe0f/g),xu}var RS;function _F(){if(RS)return Gi;RS=1,Object.defineProperty(Gi,"__esModule",{value:!0}),Gi.TypeName=void 0,Gi.parse=s,Gi.toCodePoints=d;var t=CF(),e=n(t);function n(f){return f&&f.__esModule?f:{default:f}}var r=Gi.TypeName="emoji";function s(f,h){var m=h&&h.assetType?h.assetType:"svg",g=h&&h.buildUrl?h.buildUrl:function(S,N){return N==="png"?"https://twemoji.maxcdn.com/2/72x72/"+S+".png":"https://twemoji.maxcdn.com/2/svg/"+S+".svg"},v=[];for(e.default.lastIndex=0;;){var b=e.default.exec(f);if(!b)break;var k=b[0],w=d(l(k)).join("-");v.push({url:w?g(w,m):"",indices:[b.index,e.default.lastIndex],text:k,type:r})}return v}var i=/\uFE0F/g,o="",l=function(h){return h.indexOf(o)<0?h.replace(i,""):h};function d(f){for(var h=[],m=0,g=0,v=0;v<f.length;)m=f.charCodeAt(v++),g?(h.push((65536+(g-55296<<10)+(m-56320)).toString(16)),g=0):m>55296&&m<=56319?g=m:h.push(m.toString(16));return h}return Gi}var TF=_F(),MF=function(){for(var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:aS.defaults,r=Object.keys(n).length?n:aS.defaults,s=r.defaultWeight,i=r.emojiParsingEnabled,o=r.scale,l=r.maxWeightedTweetLength,d=r.transformedURLLength,f=typeof String.prototype.normalize=="function"?e.normalize():e,h=OS(Xz(f)),m=i?OS(TF.parse(f)):[],g=f.length,v=0,b=0,k=!0,w=0;w<g;w++){if(h[w]){var S=h[w],N=S.url;S.indices,v+=d*o,w+=N.length-1}else if(i&&m[w]){var T=m[w],M=T.text;T.indices,v+=s,w+=M.length-1}else w+=jF(f,w)?1:0,v+=hF(f.charAt(w),r);k&&(k=!NF(f.substring(w,w+1))),k&&v<=l*o&&(b=w)}v=v/o,k=k&&v>0&&v<=l;var _=Math.floor(v/l*1e3),A=e.length-f.length;return b+=A,{weightedLength:v,valid:k,permillage:_,validRangeStart:0,validRangeEnd:b,displayRangeStart:0,displayRangeEnd:e.length>0?e.length-1:0}},OS=function(e){return e.reduce(function(n,r){return n[r.indices[0]]=r,n},{})},jF=function(e,n){if(n<e.length-1){var r=e.charCodeAt(n),s=e.charCodeAt(n+1);return 55296<=r&&r<=56319&&56320<=s&&s<=57343}return!1},IS={},LS;function AF(){if(LS)return IS;LS=1;var t=xr();return t(t.S+t.F*!Wr(),"Object",{defineProperty:is().f}),IS}AF();var DS={},PS;function RF(){if(PS)return DS;PS=1;var t=xr();return t(t.S+t.F*!Wr(),"Object",{defineProperties:y2()}),DS}RF();var BS={},Ym={},$S;function Ey(){return $S||($S=1,Ym.f=Object.getOwnPropertySymbols),Ym}var Xm,zS;function OF(){if(zS)return Xm;zS=1;var t=lf(),e=Ey(),n=Tr(),r=Hr().Reflect;return Xm=r&&r.ownKeys||function(i){var o=t.f(n(i)),l=e.f;return l?o.concat(l(i)):o},Xm}var Qm,FS;function k2(){if(FS)return Qm;FS=1;var t=is(),e=$l();return Qm=function(n,r,s){r in n?t.f(n,r,e(0,s)):n[r]=s},Qm}var US;function IF(){if(US)return BS;US=1;var t=xr(),e=OF(),n=yo(),r=vy(),s=k2();return t(t.S,"Object",{getOwnPropertyDescriptors:function(o){for(var l=n(o),d=r.f,f=e(l),h={},m=0,g,v;f.length>m;)v=d(l,g=f[m++]),v!==void 0&&s(h,g,v);return h}}),BS}IF();var HS={},Zm,WS;function LF(){if(WS)return Zm;WS=1;var t=$s(),e=ky(),n=Bn()("species");return Zm=function(r){var s;return e(r)&&(s=r.constructor,typeof s=="function"&&(s===Array||e(s.prototype))&&(s=void 0),t(s)&&(s=s[n],s===null&&(s=void 0))),s===void 0?Array:s},Zm}var eg,qS;function DF(){if(qS)return eg;qS=1;var t=LF();return eg=function(e,n){return new(t(e))(n)},eg}var tg,VS;function S2(){if(VS)return tg;VS=1;var t=af(),e=my(),n=Mi(),r=go(),s=DF();return tg=function(i,o){var l=i==1,d=i==2,f=i==3,h=i==4,m=i==6,g=i==5||m,v=o||s;return function(b,k,w){for(var S=n(b),N=e(S),T=t(k,w,3),M=r(N.length),_=0,A=l?v(b,M):d?v(b,0):void 0,O,B;M>_;_++)if((g||_ in N)&&(O=N[_],B=T(O,_,S),i)){if(l)A[_]=B;else if(B)switch(i){case 3:return!0;case 5:return O;case 6:return _;case 2:A.push(O)}else if(h)return!1}return m?-1:f||h?h:A}},tg}var KS;function PF(){if(KS)return HS;KS=1;var t=xr(),e=S2()(0),n=zl()([].forEach,!0);return t(t.P+t.F*!n,"Array",{forEach:function(s){return e(this,s,arguments[1])}}),HS}PF();var GS={},JS;function BF(){if(JS)return GS;JS=1;var t=xr(),e=S2()(2);return t(t.P+t.F*!zl()([].filter,!0),"Array",{filter:function(r){return e(this,r,arguments[1])}}),GS}BF();var YS={},ng={exports:{}},XS;function $F(){if(XS)return ng.exports;XS=1;var t=Bl()("meta"),e=$s(),n=vo(),r=is().f,s=0,i=Object.isExtensible||function(){return!0},o=!ss()(function(){return i(Object.preventExtensions({}))}),l=function(g){r(g,t,{value:{i:"O"+ ++s,w:{}}})},d=function(g,v){if(!e(g))return typeof g=="symbol"?g:(typeof g=="string"?"S":"P")+g;if(!n(g,t)){if(!i(g))return"F";if(!v)return"E";l(g)}return g[t].i},f=function(g,v){if(!n(g,t)){if(!i(g))return!0;if(!v)return!1;l(g)}return g[t].w},h=function(g){return o&&m.NEED&&i(g)&&!n(g,t)&&l(g),g},m=ng.exports={KEY:t,NEED:!1,fastKey:d,getWeak:f,onFreeze:h};return ng.exports}var rg={},QS;function E2(){return QS||(QS=1,rg.f=Bn()),rg}var sg,ZS;function zF(){if(ZS)return sg;ZS=1;var t=Hr(),e=ha(),n=nf(),r=E2(),s=is().f;return sg=function(i){var o=e.Symbol||(e.Symbol=n?{}:t.Symbol||{});i.charAt(0)!="_"&&!(i in o)&&s(o,i,{value:r.f(i)})},sg}var ig,eE;function FF(){if(eE)return ig;eE=1;var t=Ul(),e=Ey(),n=gy();return ig=function(r){var s=t(r),i=e.f;if(i)for(var o=i(r),l=n.f,d=0,f;o.length>d;)l.call(r,f=o[d++])&&s.push(f);return s},ig}var og={},tE;function UF(){if(tE)return og;tE=1;var t=yo(),e=lf().f,n={}.toString,r=typeof window=="object"&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],s=function(i){try{return e(i)}catch{return r.slice()}};return og.f=function(o){return r&&n.call(o)=="[object Window]"?s(o):e(t(o))},og}var nE;function HF(){if(nE)return YS;nE=1;var t=Hr(),e=vo(),n=Wr(),r=xr(),s=zs(),i=$F().KEY,o=ss(),l=rf(),d=Sy(),f=Bl(),h=Bn(),m=E2(),g=zF(),v=FF(),b=ky(),k=Tr(),w=$s(),S=Mi(),N=yo(),T=hy(),M=$l(),_=b2(),A=UF(),O=vy(),B=Ey(),$=is(),W=Ul(),J=O.f,z=$.f,G=A.f,D=t.Symbol,U=t.JSON,q=U&&U.stringify,se="prototype",V=h("_hidden"),re=h("toPrimitive"),K={}.propertyIsEnumerable,j=l("symbol-registry"),L=l("symbols"),ee=l("op-symbols"),he=Object[se],ge=typeof D=="function"&&!!B.f,oe=t.QObject,xe=!oe||!oe[se]||!oe[se].findChild,we=n&&o(function(){return _(z({},"a",{get:function(){return z(this,"a",{value:7}).a}})).a!=7})?function(ve,X,Be){var te=J(he,X);te&&delete he[X],z(ve,X,Be),te&&ve!==he&&z(he,X,te)}:z,We=function(ve){var X=L[ve]=_(D[se]);return X._k=ve,X},He=ge&&typeof D.iterator=="symbol"?function(ve){return typeof ve=="symbol"}:function(ve){return ve instanceof D},Ze=function(X,Be,te){return X===he&&Ze(ee,Be,te),k(X),Be=T(Be,!0),k(te),e(L,Be)?(te.enumerable?(e(X,V)&&X[V][Be]&&(X[V][Be]=!1),te=_(te,{enumerable:M(0,!1)})):(e(X,V)||z(X,V,M(1,{})),X[V][Be]=!0),we(X,Be,te)):z(X,Be,te)},Oe=function(X,Be){k(X);for(var te=v(Be=N(Be)),de=0,fe=te.length,Je;fe>de;)Ze(X,Je=te[de++],Be[Je]);return X},Ke=function(X,Be){return Be===void 0?_(X):Oe(_(X),Be)},mt=function(X){var Be=K.call(this,X=T(X,!0));return this===he&&e(L,X)&&!e(ee,X)?!1:Be||!e(this,X)||!e(L,X)||e(this,V)&&this[V][X]?Be:!0},Ye=function(X,Be){if(X=N(X),Be=T(Be,!0),!(X===he&&e(L,Be)&&!e(ee,Be))){var te=J(X,Be);return te&&e(L,Be)&&!(e(X,V)&&X[V][Be])&&(te.enumerable=!0),te}},pe=function(X){for(var Be=G(N(X)),te=[],de=0,fe;Be.length>de;)!e(L,fe=Be[de++])&&fe!=V&&fe!=i&&te.push(fe);return te},gt=function(X){for(var Be=X===he,te=G(Be?ee:N(X)),de=[],fe=0,Je;te.length>fe;)e(L,Je=te[fe++])&&(!Be||e(he,Je))&&de.push(L[Je]);return de};ge||(D=function(){if(this instanceof D)throw TypeError("Symbol is not a constructor!");var X=f(arguments.length>0?arguments[0]:void 0),Be=function(te){this===he&&Be.call(ee,te),e(this,V)&&e(this[V],X)&&(this[V][X]=!1),we(this,X,M(1,te))};return n&&xe&&we(he,X,{configurable:!0,set:Be}),We(X)},s(D[se],"toString",function(){return this._k}),O.f=Ye,$.f=Ze,lf().f=A.f=pe,gy().f=mt,B.f=gt,n&&!nf()&&s(he,"propertyIsEnumerable",mt,!0),m.f=function(ve){return We(h(ve))}),r(r.G+r.W+r.F*!ge,{Symbol:D});for(var ft="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),at=0;ft.length>at;)h(ft[at++]);for(var nt=W(h.store),ht=0;nt.length>ht;)g(nt[ht++]);r(r.S+r.F*!ge,"Symbol",{for:function(ve){return e(j,ve+="")?j[ve]:j[ve]=D(ve)},keyFor:function(X){if(!He(X))throw TypeError(X+" is not a symbol!");for(var Be in j)if(j[Be]===X)return Be},useSetter:function(){xe=!0},useSimple:function(){xe=!1}}),r(r.S+r.F*!ge,"Object",{create:Ke,defineProperty:Ze,defineProperties:Oe,getOwnPropertyDescriptor:Ye,getOwnPropertyNames:pe,getOwnPropertySymbols:gt});var Fe=o(function(){B.f(1)});return r(r.S+r.F*Fe,"Object",{getOwnPropertySymbols:function(X){return B.f(S(X))}}),U&&r(r.S+r.F*(!ge||o(function(){var ve=D();return q([ve])!="[null]"||q({a:ve})!="{}"||q(Object(ve))!="{}"})),"JSON",{stringify:function(X){for(var Be=[X],te=1,de,fe;arguments.length>te;)Be.push(arguments[te++]);if(fe=de=Be[1],!(!w(de)&&X===void 0||He(X)))return b(de)||(de=function(Je,Le){if(typeof fe=="function"&&(Le=fe.call(this,Je,Le)),!He(Le))return Le}),Be[1]=de,q.apply(U,Be)}}),D[se][re]||ji()(D[se],re,D[se].valueOf),d(D,"Symbol"),d(Math,"Math",!0),d(t.JSON,"JSON",!0),YS}HF();jt(/^#{validMentionOrList}$/,{validMentionOrList:aF});var N2=/[a-z\u0400-\u04FF0-9\-._~]/i,C2=/(?:%[0-9a-f]{2})/i,_2=/[!$&'()*+,;=]/i,T2=jt("(?:#{validateUrlUnreserved}|#{validateUrlPctEncoded}|#{validateUrlSubDelims}|:)*",{validateUrlUnreserved:N2,validateUrlPctEncoded:C2,validateUrlSubDelims:_2},"i"),WF=/(?:[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?)/i,qF=/(?:[a-z](?:[a-z0-9\-]*[a-z0-9])?)/i,VF=/(?:[a-z0-9](?:[a-z0-9_\-]*[a-z0-9])?)/i,KF=jt(/(?:(?:#{validateUrlSubDomainSegment}\.)*(?:#{validateUrlDomainSegment}\.)#{validateUrlDomainTld})/i,{validateUrlSubDomainSegment:VF,validateUrlDomainSegment:WF,validateUrlDomainTld:qF}),GF=/(?:[0-9]|(?:[1-9][0-9])|(?:1[0-9]{2})|(?:2[0-4][0-9])|(?:25[0-5]))/i,JF=jt(/(?:#{validateUrlDecOctet}(?:\.#{validateUrlDecOctet}){3})/i,{validateUrlDecOctet:GF}),YF=/(?:\[[a-f0-9:\.]+\])/i,M2=jt("(?:#{validateUrlIpv4}|#{validateUrlIpv6})",{validateUrlIpv4:JF,validateUrlIpv6:YF},"i"),XF=jt("(?:#{validateUrlIp}|#{validateUrlDomain})",{validateUrlIp:M2,validateUrlDomain:KF},"i"),j2=/[0-9]{1,5}/;jt("(?:(#{validateUrlUserinfo})@)?(#{validateUrlHost})(?::(#{validateUrlPort}))?",{validateUrlUserinfo:T2,validateUrlHost:XF,validateUrlPort:j2},"i");var Ny=jt("(?:#{validateUrlUnreserved}|#{validateUrlPctEncoded}|#{validateUrlSubDelims}|[:|@])",{validateUrlUnreserved:N2,validateUrlPctEncoded:C2,validateUrlSubDelims:_2},"i");jt(/(#{validateUrlPchar}|\/|\?)*/i,{validateUrlPchar:Ny});jt(/(\/#{validateUrlPchar}*)*/i,{validateUrlPchar:Ny});jt(/(#{validateUrlPchar}|\/|\?)*/i,{validateUrlPchar:Ny});jt("^(?:([^:/?#]+):\\/\\/)?([^/?#]*)([^?#]*)(?:\\?([^#]*))?(?:#(.*))?$","i");var QF=/(?:(?:[a-z0-9]|[^\u0000-\u007f])(?:(?:[a-z0-9_\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,ZF=/(?:(?:[a-z0-9]|[^\u0000-\u007f])(?:(?:[a-z0-9\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,eU=/(?:(?:[a-z]|[^\u0000-\u007f])(?:(?:[a-z0-9\-]|[^\u0000-\u007f])*(?:[a-z0-9]|[^\u0000-\u007f]))?)/i,tU=jt(/(?:(?:#{validateUrlUnicodeSubDomainSegment}\.)*(?:#{validateUrlUnicodeDomainSegment}\.)#{validateUrlUnicodeDomainTld})/i,{validateUrlUnicodeSubDomainSegment:QF,validateUrlUnicodeDomainSegment:ZF,validateUrlUnicodeDomainTld:eU}),nU=jt("(?:#{validateUrlIp}|#{validateUrlUnicodeDomain})",{validateUrlIp:M2,validateUrlUnicodeDomain:tU},"i");jt("(?:(#{validateUrlUserinfo})@)?(#{validateUrlUnicodeHost})(?::(#{validateUrlPort}))?",{validateUrlUserinfo:T2,validateUrlUnicodeHost:nU,validateUrlPort:j2},"i");var rE={},sE;function rU(){if(sE)return rE;sE=1;var t=KT()(!0);return x2()(String,"String",function(e){this._t=String(e),this._i=0},function(){var e=this._t,n=this._i,r;return n>=e.length?{value:void 0,done:!0}:(r=t(e,n),this._i+=r.length,{value:r,done:!1})}),rE}rU();var iE={},ag,oE;function sU(){if(oE)return ag;oE=1;var t=Tr();return ag=function(e,n,r,s){try{return s?n(t(r)[0],r[1]):n(r)}catch(o){var i=e.return;throw i!==void 0&&t(i.call(e)),o}},ag}var lg,aE;function iU(){if(aE)return lg;aE=1;var t=Fl(),e=Bn()("iterator"),n=Array.prototype;return lg=function(r){return r!==void 0&&(t.Array===r||n[e]===r)},lg}var cg,lE;function oU(){if(lE)return cg;lE=1;var t=uy(),e=Bn()("iterator"),n=Fl();return cg=ha().getIteratorMethod=function(r){if(r!=null)return r[e]||r["@@iterator"]||n[t(r)]},cg}var ug,cE;function aU(){if(cE)return ug;cE=1;var t=Bn()("iterator"),e=!1;try{var n=[7][t]();n.return=function(){e=!0},Array.from(n,function(){throw 2})}catch{}return ug=function(r,s){if(!s&&!e)return!1;var i=!1;try{var o=[7],l=o[t]();l.next=function(){return{done:i=!0}},o[t]=function(){return l},r(o)}catch{}return i},ug}var uE;function lU(){if(uE)return iE;uE=1;var t=af(),e=xr(),n=Mi(),r=sU(),s=iU(),i=go(),o=k2(),l=oU();return e(e.S+e.F*!aU()(function(d){Array.from(d)}),"Array",{from:function(f){var h=n(f),m=typeof this=="function"?this:Array,g=arguments.length,v=g>1?arguments[1]:void 0,b=v!==void 0,k=0,w=l(h),S,N,T,M;if(b&&(v=t(v,g>2?arguments[2]:void 0,2)),w!=null&&!(m==Array&&s(w)))for(M=w.call(h),N=new m;!(T=M.next()).done;k++)o(N,k,b?r(M,v,[T.value,k],!0):T.value);else for(S=i(h.length),N=new m(S);S>k;k++)o(N,k,b?v(h[k],k):h[k]);return N.length=k,N}}),iE}lU();const cU={parseTweet:MF},{parseTweet:uU}=cU;function dE(t){return uU(t).weightedLength}const fE="ow-x-handle";function dU(){const[t,e]=x.useState(()=>localStorage.getItem(fE)||""),[n,r]=x.useState(!1),[s,i]=x.useState(""),o=x.useRef(null),l=x.useRef(null),d=()=>{const m=s.replace(/^@/,"").trim();m&&(localStorage.setItem(fE,m),e(m)),r(!1)},f=()=>{i(t),r(!0),setTimeout(()=>{var m;return(m=o.current)==null?void 0:m.focus()},0)};x.useEffect(()=>{if(!n)return;const m=g=>{l.current&&!l.current.contains(g.target)&&d()};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[n,s]);const h=t?`https://unavatar.io/twitter/${t}`:"";return c.jsxs("div",{className:"tweet-compose-avatar-wrapper",ref:l,children:[t?c.jsx("img",{className:"tweet-compose-avatar tweet-compose-avatar-img",src:h,alt:`@${t}`,onClick:f,title:`@${t} — click to change`}):c.jsx("div",{className:"tweet-compose-avatar",onClick:f,title:"Set your @handle"}),n&&c.jsx("div",{className:"tweet-handle-popover",children:c.jsx("input",{ref:o,className:"tweet-handle-input",value:s,onChange:m=>i(m.target.value),onKeyDown:m=>{m.key==="Enter"&&d(),m.key==="Escape"&&r(!1)},placeholder:"your_handle",spellCheck:!1})})]})}const fU={tweet:!0,reply:!0,quote:!1};function hE(){return c.jsxs("div",{className:"tweet-skeleton",children:[c.jsxs("div",{className:"tweet-author-row",children:[c.jsx("div",{className:"tweet-avatar tweet-avatar-placeholder tweet-pulse"}),c.jsxs("div",{className:"tweet-author-info",children:[c.jsx("span",{className:"tweet-skeleton-line tweet-pulse",style:{width:120}}),c.jsx("span",{className:"tweet-skeleton-line tweet-pulse",style:{width:80}})]})]}),c.jsx("div",{className:"tweet-skeleton-line tweet-pulse",style:{width:"100%",height:16,marginTop:12}}),c.jsx("div",{className:"tweet-skeleton-line tweet-pulse",style:{width:"75%",height:16,marginTop:8}})]})}function hU(t){var e;if(t)return(e=t.match(/\/status\/(\d+)/))==null?void 0:e[1]}function wu(t){if(!t)return[null];if(typeof t=="string"){const e=t.split(/<hr\s*\/?>/i).map(n=>n.trim()).filter(Boolean);return e.length?e:[null]}if((t==null?void 0:t.type)==="doc"&&Array.isArray(t.content)){const e=[[]];for(const r of t.content)r.type==="horizontalRule"?e.push([]):e[e.length-1].push(r);const n=e.map(r=>r.length?{type:"doc",content:r}:null).filter(Boolean);return n.length?n:[null]}return[t]}function ku(t){var n;if(!t||typeof t=="string"||!t.content)return[];const e=[];for(let r=t.content.length-1;r>=0&&(t.content[r].type==="image"&&((n=t.content[r].attrs)!=null&&n.src));r--)e.unshift(t.content[r].attrs.src);return e}function pE(t,e){if(!t||typeof t=="string"||!t.content||e===0)return t;const n=t.content.slice(0,t.content.length-e);return n.length===0?{type:"doc",content:[{type:"paragraph",content:[]}]}:{...t,content:n}}function Su(t,e){const n=[];let r=0;return t.forEach((s,i)=>{if(!s)return;r>0&&n.push({type:"horizontalRule"});const o=s.getJSON();o.content&&n.push(...o.content);const l=e==null?void 0:e[i];if(l)for(const d of l){const f=crypto.randomUUID().replace(/-/g,"").slice(0,8);n.push({type:"image",attrs:{src:d,id:f}})}r++}),{type:"doc",content:n}}function mE(t,e){const n=[],r=s=>{var i;s.type==="image"&&((i=s.attrs)!=null&&i.src)&&n.push(s.attrs.src),s.content&&s.content.forEach(r)};return r(t.getJSON()),e&&n.push(...e),n.slice(0,4)}function Eu(t){fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tweetContext:t}),keepalive:!0}).catch(()=>{})}function pU({tweetContext:t,initialContent:e,onUpdate:n,onEditorReady:r,onEditorsChange:s,onActiveEditorChange:i,filename:o,title:l,autoplug:d}){var Nt;const{tweet:f,loading:h,error:m}=nz(t==null?void 0:t.url),[g,v]=x.useState(()=>wu(e).map(je=>{const qe=ku(je);return pE(je,qe.length)})),[b,k]=x.useState(0),w=x.useRef([]),S=x.useRef(null),N=x.useRef(!0),T=x.useRef(!1),M=x.useRef(g.length),[_,A]=x.useState(()=>g.map(()=>0)),[O,B]=x.useState(0),[$,W]=x.useState(0),J=x.useRef(wu(e).map(Ie=>ku(Ie))),[z,G]=x.useState(()=>wu(e).map(je=>ku(je).length)),[D,U]=x.useState(null),[q,se]=x.useState(),[V,re]=x.useState(!1),[K,j]=x.useState("idle"),[L,ee]=x.useState(""),he=x.useRef(),{copyText:ge,copyState:oe}=oz(w,O),[xe,we]=x.useState(!1),We=fU[(t==null?void 0:t.mode)??"tweet"],He=!!((Nt=t==null?void 0:t.lastPost)!=null&&Nt.postedAt),[Ze,Oe]=x.useState(!1),[Ke,mt]=x.useState(""),Ye=x.useRef(null),pe=x.useRef(null);x.useEffect(()=>{if(!Ze)return;setTimeout(()=>{var je;return(je=Ye.current)==null?void 0:je.focus()},0);const Ie=je=>{pe.current&&!pe.current.contains(je.target)&&(Oe(!1),mt(""))};return document.addEventListener("mousedown",Ie),()=>document.removeEventListener("mousedown",Ie)},[Ze]);const gt=()=>{var F;const Ie=Ke.trim();if(!(!Ie||Ie.includes("x.com")||Ie.includes("twitter.com")))return;const qe=(F=t==null?void 0:t.lastPost)==null?void 0:F.postedAt;Eu({lastPost:{postedAt:qe??new Date().toISOString(),tweetUrl:Ie||void 0}}),Oe(!1),mt("")},ft=()=>{Eu({lastPost:null})},at=d!==!1,nt=()=>{fetch("/api/metadata",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({autoplug:!at}),keepalive:!0}).catch(()=>{})};x.useEffect(()=>{let Ie=!1;return(async()=>{try{const je=await fetch("/api/x/status");if(Ie)return;if(je.ok){const qe=await je.json();U(qe.connected),se(qe.username)}else U(!1)}catch{Ie||U(!1)}})(),()=>{Ie=!0}},[]),x.useEffect(()=>{if(N.current){N.current=!1;return}if(!e||JSON.stringify(e)===S.current)return;const je=wu(e),qe=je.map(ce=>ku(ce)),F=je.map((ce,Ne)=>pE(ce,qe[Ne].length));T.current=!0,M.current=F.length,w.current=[],J.current=qe,v(F),A(F.map(()=>0)),G(qe.map(ce=>ce.length)),k(ce=>ce+1)},[e]);const ht=x.useCallback((Ie,je)=>{if(w.current[Ie]=je,A(F=>{const ce=[...F];return ce[Ie]=dE(je.getText()),ce}),T.current)return;const qe=Su(w.current,J.current);S.current=JSON.stringify(qe),n==null||n(qe)},[n]),Fe=x.useCallback((Ie,je)=>{if(w.current[Ie]=je,A(qe=>{const F=[...qe];return F[Ie]=dE(je.getText()),F}),W(qe=>qe+1),T.current&&w.current.filter(Boolean).length>=M.current){T.current=!1;const F=Su(w.current,J.current);S.current=JSON.stringify(F)}Ie===0&&(r==null||r(je)),s==null||s(w.current.filter(Boolean))},[r,s]),ve=g.length>1;_.reduce((Ie,je)=>Ie+je,0);const X=x.useCallback(()=>{const Ie=O+1;v(je=>[...je.slice(0,Ie),"<p></p>",...je.slice(Ie)]),A(je=>[...je.slice(0,Ie),0,...je.slice(Ie)]),J.current.splice(Ie,0,[]),G(je=>[...je.slice(0,Ie),0,...je.slice(Ie)]),B(Ie)},[O]),Be=x.useCallback(Ie=>{Ie!==0&&(w.current.splice(Ie,1),J.current.splice(Ie,1),v(je=>je.filter((qe,F)=>F!==Ie)),A(je=>je.filter((qe,F)=>F!==Ie)),G(je=>je.filter((qe,F)=>F!==Ie)),setTimeout(()=>{const je=Su(w.current,J.current);n==null||n(je),s==null||s(w.current.filter(Boolean))},0))},[n,s]),te=!!(t!=null&&t.url),de=(t==null?void 0:t.mode)==="reply",fe=(()=>{const je=w.current.filter(Boolean).some(F=>F.getText().trim()||mE(F).length>0),qe=z.some(F=>F>0);return je||qe})(),Je=D&&fe&&K==="idle",Le=async()=>{if(!D){re(!0);return}if(Je){j("uploading"),ee("");try{const Ie=[];for(let qe=0;qe<w.current.length;qe++){const F=w.current[qe];if(!F)continue;const ce=F.getText().trim(),Ne=mE(F,J.current[qe]);if(!ce&&Ne.length===0)continue;const P=[];for(const Z of Ne){const ne=await(await fetch("/api/x/upload-media",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({src:Z})})).json();if(!ne.success)throw new Error(ne.error||"Image upload failed");P.push(ne.mediaId)}Ie.push({text:ce,mediaIds:P})}if(Ie.length===0)return;j("posting");const je=hU(t==null?void 0:t.url);if(Ie.length===1){const qe={};Ie[0].text&&(qe.text=Ie[0].text),Ie[0].mediaIds.length>0&&(qe.mediaIds=Ie[0].mediaIds),(t==null?void 0:t.mode)==="reply"&&je?qe.replyTo=je:(t==null?void 0:t.mode)==="quote"&&je&&(qe.quoteTweetId=je);const ce=await(await fetch("/api/x/post",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(qe)})).json();ce.success?(Eu({lastPost:{postedAt:new Date().toISOString(),tweetUrl:ce.tweetUrl}}),j("success"),he.current=setTimeout(()=>j("idle"),2500)):(console.error("[TweetCompose] Post error:",ce.error),ee(ce.error||"Post failed"),j("error"),setTimeout(()=>j("idle"),3e3))}else{const F={tweets:Ie.map(P=>({text:P.text,...P.mediaIds.length>0?{mediaIds:P.mediaIds}:{}}))};(t==null?void 0:t.mode)==="reply"&&je&&(F.replyTo=je);const Ne=await(await fetch("/api/x/post-thread",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)})).json();Ne.success?(Eu({lastPost:{postedAt:new Date().toISOString(),tweetUrl:Ne.threadUrl}}),j("success"),he.current=setTimeout(()=>j("idle"),2500)):(ee(Ne.error||"Thread post failed"),j("error"),setTimeout(()=>j("idle"),3e3))}}catch(Ie){ee(Ie.message||"Network error"),j("error"),setTimeout(()=>j("idle"),3e3)}}};x.useEffect(()=>()=>{he.current&&clearTimeout(he.current)},[]);const et=()=>{U(!0),re(!1),fetch("/api/x/status").then(Ie=>Ie.json()).then(Ie=>{Ie.username&&se(Ie.username)}).catch(()=>{})},ot=K==="uploading"?"Uploading...":K==="posting"?"Posting...":K==="success"?"Posted!":K==="error"?"Failed":ve?O===0?"Post Thread":"Post All":"Post",bt=g.map((Ie,je)=>je===0?de?"Post your reply":"What is happening?!":"Add another tweet"),Ge=Ie=>{var je;return c.jsxs("div",{className:`tweet-compose-footer${Ie?" tweet-compose-footer--inline":""}`,children:[O===0&&((je=t==null?void 0:t.lastPost)==null?void 0:je.postedAt)&&c.jsxs("a",{className:"tweet-posted-status",href:t.lastPost.tweetUrl,target:"_blank",rel:"noopener noreferrer",title:t.lastPost.tweetUrl||"Posted to X",children:[c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Posted ",new Date(t.lastPost.postedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})]}),K==="error"&&L&&c.jsx("span",{className:"tweet-post-error",children:L}),ve&&c.jsxs("span",{className:"tweet-thread-counter",children:[O+1,"/",g.length]}),c.jsx(pz,{count:_[O]||0}),c.jsx("button",{className:"tweet-thread-add",onClick:X,title:"Add another tweet",children:c.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[c.jsx("line",{x1:"10",y1:"4",x2:"10",y2:"16",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),c.jsx("line",{x1:"4",y1:"10",x2:"16",y2:"10",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}),c.jsx("button",{className:`tweet-copy-btn${oe==="copied"?" tweet-copy-btn--copied":""}`,disabled:!fe,onClick:ge,title:"Copy tweet text to clipboard",children:oe==="copied"?c.jsxs(c.Fragment,{children:[c.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:c.jsx("path",{d:"M3 8.5L6.5 12L13 4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),"Copied!"]}):c.jsxs(c.Fragment,{children:[c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[c.jsx("rect",{x:"5.5",y:"2",width:"8.5",height:"10.5",rx:"1.5",stroke:"currentColor",strokeWidth:"1.5"}),c.jsx("path",{d:"M3.5 5H2.5A1.5 1.5 0 001 6.5V13a1.5 1.5 0 001.5 1.5H9A1.5 1.5 0 0010.5 13v-1",stroke:"currentColor",strokeWidth:"1.5"})]}),"Copy"]})}),O===0&&!We&&(()=>{var ce;const qe=((ce=t==null?void 0:t.lastPost)==null?void 0:ce.tweetUrl)??"",F=()=>{if(He){ft(),Oe(!1),mt("");return}mt(qe),Oe(!0)};return c.jsxs("div",{className:"tweet-mark-sent-wrap",ref:pe,children:[c.jsx("button",{className:`tweet-mark-sent-btn${He?" tweet-mark-sent-btn--done":""}`,onClick:F,title:He?qe?`Posted — click to unmark (${qe})`:"Posted — click to unmark":"Mark as manually posted",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:He?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"8 12 11 15 16 9",stroke:He?"#fff":"currentColor"})]})}),Ze&&(()=>{const Ne=Ke.trim(),P=!Ne||Ne.includes("x.com")||Ne.includes("twitter.com");return c.jsxs("div",{className:"tweet-mark-sent-url",children:[c.jsx("input",{ref:Ye,type:"text",placeholder:"Paste posted tweet URL...",value:Ke,onChange:Z=>mt(Z.target.value),onKeyDown:Z=>{Z.key==="Enter"&&(Z.preventDefault(),gt()),Z.key==="Escape"&&(Oe(!1),mt(""))}}),c.jsx("button",{onClick:gt,disabled:!P,title:Ne?"Save URL":"Mark posted without URL",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})})]})})()]})})(),c.jsx("button",{className:`tweet-autoplug-toggle${at?" tweet-autoplug-toggle--on":""}`,onClick:nt,title:at?"Auto-plug ON — engagement autoplugs may reply to this post with your configured promo. Click to opt out.":"Auto-plug OFF — this post is excluded from autoplugs. Click to opt in.",children:at?"Auto-plug on":"Auto-plug off"}),o&&!He&&c.jsx("button",{className:"tweet-schedule-btn",onClick:()=>we(!0),title:"Schedule post",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("polyline",{points:"12 6 12 12 16 14"})]})}),We&&c.jsx("button",{className:`tweet-post-btn${Je||!D&&D!==null?" tweet-post-btn--active":""}${K==="success"?" tweet-post-btn--success":""}${K==="error"?" tweet-post-btn--error":""}`,disabled:D?!Je:!1,onClick:Le,title:D?q?`Post as @${q}`:"Post to X":"Connect X to post",children:ot})]})},it=te&&!de,pt=()=>c.jsx("div",{className:"tweet-thread-editors",children:g.map((Ie,je)=>c.jsxs("div",{className:`tweet-thread-item${je===O?" tweet-thread-item--active":" tweet-thread-item--inactive"}`,children:[c.jsxs("div",{className:"tweet-thread-item-left",children:[c.jsx(dU,{}),je<g.length-1&&c.jsx("div",{className:"tweet-thread-line"})]}),c.jsxs("div",{className:"tweet-thread-item-right",children:[je>0&&c.jsx("button",{className:"tweet-thread-remove",onClick:()=>Be(je),title:"Remove this tweet",children:"×"}),c.jsx("div",{className:`tweet-compose-box${je===0&&!ve?" tweet-compose-box--standalone":""}`,children:c.jsx(hz,{initialContent:Ie,initialPreviewImages:J.current[je],placeholder:bt[je],onUpdate:qe=>ht(je,qe),onReady:qe=>Fe(je,qe),onFocus:()=>{B(je);const qe=w.current[je];qe&&(i==null||i(qe))},onPreviewImagesChange:qe=>{if(J.current[je]=qe,G(F=>{const ce=[...F];return ce[je]=qe.length,ce}),!T.current){const F=Su(w.current,J.current);S.current=JSON.stringify(F),n==null||n(F)}}})}),je===O&&!it&&Ge(je<g.length-1)]})]},`${b}-${je}`))});return c.jsxs("div",{className:"tweet-compose-wrapper",children:[te&&de&&c.jsxs(c.Fragment,{children:[h&&c.jsx("div",{className:"tweet-context-section",children:c.jsx(hE,{})}),m&&c.jsx("div",{className:"tweet-context-section",children:c.jsxs("div",{className:"tweet-embed-error",children:[c.jsx("span",{children:"Could not load tweet"}),c.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"tweet-fallback-link",children:t.url})]})}),f&&c.jsxs("div",{className:"tweet-reply-parent-section",children:[c.jsx("div",{className:"tweet-reply-parent-card",children:c.jsx(Bk,{tweet:f,url:t==null?void 0:t.url})}),c.jsxs("div",{className:"tweet-replying-to",children:["Replying to ",c.jsxs("span",{className:"tweet-reply-handle",children:["@",f.author.username]})]})]}),pt()]}),it&&c.jsxs(c.Fragment,{children:[pt(),c.jsxs("div",{className:"tweet-quote-section",style:{padding:"0 16px 12px"},children:[h&&c.jsx(hE,{}),m&&c.jsxs("div",{className:"tweet-embed-error",children:[c.jsx("span",{children:"Could not load tweet"}),c.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"tweet-fallback-link",children:t.url})]}),f&&c.jsx(Bk,{tweet:f,url:t==null?void 0:t.url})]}),c.jsx("div",{className:"tweet-quote-footer",children:Ge()})]}),!te&&pt(),V&&c.jsx(mz,{onConnected:et,onCancel:()=>re(!1)}),xe&&o&&c.jsx(Pl,{filename:o,title:l||"Untitled",onClose:()=>we(!1)})]})}function mU(){const[t,e]=x.useState("idle"),n=x.useRef();return{copyAsHtml:x.useCallback(async()=>{const s=document.querySelector(".ProseMirror");if(!s)return;const i=s.cloneNode(!0);i.querySelectorAll(".ProseMirror-widget, [data-widget], .ProseMirror-gapcursor").forEach(h=>h.remove());let o="";const l=document.querySelector(".article-title-input");l!=null&&l.value&&l.value!=="Untitled"&&(o+=`<h1>${l.value}</h1>
|
|
212
212
|
`);const d=o+i.innerHTML,f=gU(i);try{const h=new ClipboardItem({"text/html":new Blob([d],{type:"text/html"}),"text/plain":new Blob([f],{type:"text/plain"})});await navigator.clipboard.write([h])}catch{try{await navigator.clipboard.writeText(f)}catch{const h=document.createElement("textarea");h.value=f,h.style.position="fixed",h.style.opacity="0",document.body.appendChild(h),h.select(),document.execCommand("copy"),document.body.removeChild(h)}}e("copied"),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>e("idle"),2e3)},[]),copyState:t}}function gU(t){var n;const e=[];for(const r of t.children){const s=(n=r.innerText)==null?void 0:n.trim();s&&e.push(s)}return e.join(`
|