1import{r as w,j as t,H as Ye,L as et}from"./app-DFIp5Htm.js";import{A as tt}from"./AuthenticatedLayout-DMDEM-p1.js";import{M as nt}from"./Modal-D1OaAlfM.js";import{u as st}from"./csrf-C4hPLC2l.js";import"./Dropdown-CqFLw4H_.js";import"./transition-o0hBPGmW.js";import"./with-selector-C4LPXTzr.js";const Ce="(?:png|jpe?g|gif|webp|svg)",re=/\[([^\]]+)\]\(([^)]+)\)/g,le=/\[([^\]]+)\]\[([^\]]+)\]/g,it=/!\[[^\]]*]\[[^\]]+]/g,oe=s=>(s||"").replace(/\r\n/g,` 2`).replace(/\r/g,` 3`).split(` 4`),rt=s=>s.replace(/\s{2,}/g," ").replace(/\s+([,.;:!?])/g,"$1").replace(/([,.;:!?]){2,}/g,"$1").replace(/([,.;:!?])\s{2,}/g,"$1 ").trim(),pe=s=>/[A-Za-z0-9]/.test(s||""),lt=s=>/\[[^\]]+]\([^)]+\)/.test(s||"")||/\[[^\]]+]\([^\s)]*/.test(s||"")||/\[[^\]]+]\[[^\]]+]/.test(s||""),ot=s=>/^\s*[*+-]\s*[\[\]\(\)\{\}\s.,;:!?'"\-ââ]+$/.test(s||""),at=s=>{const n=(s||"").trim();return n?pe(n)?!1:/^[\[\]\(\)\{\}\s.,;:!?'"\-ââ]+$/.test(n):!0},ct=s=>{const n=[];let r=0;for(;r<s.length;){const l=s[r],g=l.match(/^(#{1,6})\s+(.*)$/);if(!g){n.push(l),r+=1;continue}const m=g[1].length;let a=r+1,u=!1;for(;a<s.length;a+=1){const c=s[a],y=c.match(/^(#{1,6})\s+/);if(y&&y[1].length<=m)break;pe(c)&&(u=!0)}if(u){n.push(l);for(let c=r+1;c<a;c+=1)n.push(s[c])}r=a}return n};function B(s){let n=(s||"").replace(/\(\s*\)|\[\s*\]|\{\s*\}/g,"");const r=oe(n),l=[];let g=0;r.forEach(u=>{let c=u.replace(/^[\t ]+|[\t ]+$/g,"");if(!c){g+=1,g<=2&&l.push("");return}g=0;const y=c.indexOf("](");if(y!==-1&&c.indexOf(")",y)===-1){const S=c.lastIndexOf("[",y);if(S!==-1){const f=c.slice(S+1,y);c=c.slice(0,S)+f}else c=c.slice(0,y)}/^#{1,6}\s+/.test(c)&&(c=c.replace(/\s*\{#[^}]+\}\s*/g," ")),!/^\s*[*+-]\s*\[[^\]]+?\]\s*$/.test(c)&&(pe(c)&&!lt(c)&&(c=c.replace(/^[\s\[\]\(\)\{\}]+/,""),c=c.replace(/[\s\[\]\(\)\{\}]+$/,"")),c=rt(c),!ot(c)&&(at(c)||l.push(c)))});const m=ct(l),a=[];return g=0,m.forEach(u=>{if(!u.trim()){g+=1,g<=2&&a.push("");return}g=0,a.push(u)}),a.join(` 5`).trim()}function Te(s){const n=oe(s),r=[];for(let m=0;m<n.length;m+=1){let a=(n[m]||"").replace(/\(\s*\)|\[\s*\]|\{\s*\}/g,"");const u=m+1<n.length&&n[m+1]||"",c=a.includes("["),y=a.includes("]"),S=a.includes("]("),f=u.includes("](");if(c&&!y&&!S&&f){r.push(`${a.trim()} ${u.trim()}`.replace(/\s{2,}/g," ")),m+=1;continue}if(a.includes("](")&&!a.includes("[")){const $=r.length-1,j=$>=0?r[$]:"";j&&j.includes("[")&&!j.includes("](")&&(r[$]=`${j.trim()} ${a.trim()}`.replace(/\s{2,}/g," "));continue}const x=a.includes("||u.includes(")");if(x&&h){r.push(`${a.trim()} ${u.trim()}`.replace(/\s{2,}/g," ")),m+=1;continue}const N=a.trim();if(!N){r.push("");continue}/^[\[\]\(\)\{\}\s.,;:!?'"\-ââ]+$/.test(N)||r.push(a)}const l=[];let g=0;for(const m of r){if(!(m||"").trim()){g+=1,g<=2&&l.push("");continue}g=0,l.push(m)}return l.join(` 6`)}function Se(s){let n=Te(s||"");return n=n.replace(it,""),n=n.replace(/\[!\[[^\]]*]\([^)]+\)\]\([^)]+\)/g,""),n=n.replace(/\[!\[[^\]]*]\([^\s)]*/g,""),n=n.replace(/<img\b[^>]*>/gi,""),n=n.replace(/!\[[^\]]*]\([^\)]*\)/g,""),n=n.replace(/!\[[^\]]*]\[[^\]]*]/g,""),n=n.replace(/!\[[^\]]*]\(\s*\)/g,""),n=n.replace(/!\[[^\]]*]\([^\s)]*/g,""),n=n.replace(/!\([^\s)]+/g,""),n=n.replace(/!\[[^\]]*$/gm,""),n=n.replace(/!\[[^\]]*]\s*$/gm,""),n=n.replace(/!\[[^\]]*]\([^\n)]*$/gm,""),n=n.replace(new RegExp(`\\bhttps?:\\/\\/\\S+\\.${Ce}(?:\\?\\S*)?`,"gi"),""),n=n.replace(new RegExp(`\\/assets\\/[^\\s)]+?\\.${Ce}(?:\\?\\S*)?`,"gi"),""),B(n)}const dt=s=>{const n=[];let r;for(re.lastIndex=0;r=re.exec(s);)n.push({label:r[1],url:r[2]});for(le.lastIndex=0;r=le.exec(s);)n.push({label:r[1],url:r[2]});return n},mt=s=>{const n=[],r=/\[([^\]]+)\]\([^\s)]*/g;let l;for(;l=r.exec(s);)n.push(l[1]);return n},ut=s=>{const n=s.match(/\[[^\]]+\]\([^\s)]*/g);return n?n.length:0},ht=s=>/^\s*[*+-]\s*\[[^\]]+?\]\([^\s)]*\s*$/.test(s||""),pt=s=>/[^\[]\]\([^\s)]*\s*$/.test(s||""),xt=s=>(s||"").replace(/\[!\[[^\]]*]\([^)]+\)\]\([^)]+\)/g,"").replace(/\[!\[[^\]]*]\([^\s)]*/g,"").replace(/!\[[^\]]*]\([^)]+\)/g,"").replace(/!\[[^\]]*]\([^\s)]*/g,"").replace(/!\([^\s)]+/g,""),gt=s=>{const n=xt(s).replace(/\]\([^\s)]*/g,"");return!/[A-Za-z0-9]/.test(n||"")},_e=s=>{const n=[],r=/\[([^\]]+)\]\(([^)\s]+)?/g;let l;for(;l=r.exec(s||"");)n.push({label:l[1],url:l[2]||""});return n},$e=s=>{const n=_e(s);if(!n.length)return!1;const r=(s||"").replace(/\[[^\]]+\]\([^)]+\)/g,"").replace(/\[[^\]]+\]\([^\s)]*/g,"").replace(/^[\s*+\-0-9.)
6]+/g,"").trim();return/[A-Za-z0-9]/.test(r)||!n.every(m=>he(m.url))?!1:n.length>=3?!0:n.map(m=>(m.label||"").trim()).join(" ").length<=80},he=s=>/^\/|^#|^\.\.?\//.test(s||""),ft=s=>{if(!s||!s.startsWith("/"))return null;const r=s.split(/[?#]/)[0].split("/").filter(Boolean);return r.length?`/${r.slice(0,2).join("/")}`:null};function Me(s,{mode:n="keep-label"}={}){const r=oe(s),l=[];return r.forEach(g=>{const m=g||"";if(n==="keep-label"){const u=m.replace(re,"$1").replace(le,"$1").replace(/<https?:\/\/[^>]+>/g,"").replace(/https?:\/\/\S+/g,"");l.push(u);return}const a=m.replace(re,"").replace(le,"").replace(/<https?:\/\/[^>]+>/g,"").replace(/https?:\/\/\S+/g,"");a.replace(/[\s\W_]+/g,"")&&l.push(a)}),l.join(` 7`)}function Re(s){const n=oe(Te(s)),r=[];let l=[];n.forEach(a=>{if(!a.trim()){l.length&&r.push(l),r.push([""]),l=[];return}l.push(a)}),l.length&&r.push(l);const g=a=>{if(a.length===1&&a[0]==="")return!1;const u=a.join(` 8`).toLowerCase(),c=/table of contents|contents/.test(u);let y=0,S=0,f=0,x=0,h=0,N=0,$=0,j=0,F=0,P=0,O=0,E=0;const L={};a.forEach(C=>{const A=dt(C),p=ut(C),Q=mt(C),U=_e(C);/^\s*([-*+]|[0-9]+[.)])\s+/.test(C)&&(h+=1),/\|/.test(C)&&(N+=1),$=Math.max($,A.length),j=Math.max(j,Math.max(p,U.length)),x+=p,(A.length||p||U.length)&&(F+=1),U.forEach(I=>{P+=1,he(I.url)&&(O+=1)}),$e(C)&&(E+=1),Q.forEach(I=>{f+=(I||"").length}),A.forEach(I=>{y+=1,f+=(I.label||"").length,he(I.url)&&(S+=1);const te=ft(I.url);te&&(L[te]=(L[te]||0)+1)})});const _=a.length||1,T=Math.max(y,x,P),Z=T/_,W=P?O/P:y?S/y:0,X=T?f/T:0,ee=Math.max(0,...Object.values(L));if(c&&T>0||$>=4&&W>=.5||j>=4||u.includes("prev")&&u.includes("next")&&T>=2||h>=3&&F>=Math.ceil(_*.5)&&T>=3||E>=3&&T>=3)return!0;let k=0;return T>=6&&(k+=3),T>=10&&(k+=2),W>=.6&&(k+=2),X>0&&X<=25&&(k+=1),Z>=1.2&&(k+=2),h>=Math.ceil(_*.5)&&(k+=1),N>=1&&T>=2&&(k+=1),ee>=3&&(k+=1),k>=5},m=[];for(let a=0;a<r.length;a+=1){const u=r[a];if(u.length===1&&u[0]===""){m.push("");continue}const c=u.join(` 9`).toLowerCase(),y=u.length===1&&/^#{1,6}\s+/.test(u[0]),S=/table of contents|contents/.test(c),f=r[a+1];if(!g(u)){if(S&&f&&g(f)){a+=1;continue}S&&y||y&&u[0].trim().length<=30&&f&&g(f)||u.forEach(x=>{ht(x)||pt(x)||$e(x)||gt(x)||m.push(x)})}}return B(m.join(` 10`))}const ue=2e3;function Y(s){const n=(s||"").split(` 11`),r=[];let l=null,g=!1,m=null;const a=x=>{const h=(x||"").trim();if(!h.match(/(\s*\{#[^}]+\}\s*)+$/))return{text:h,anchor:null};const $=h.replace(/(\s*\{#[^}]+\}\s*)+$/,"").trim(),j=h.match(/\{#([^}]+)\}\s*$/);return{text:$,anchor:j?j[1].trim():null}},u=x=>{const h=x.trim();if(!h||h.startsWith(">"))return null;const N=h.match(/^(?:~~)?(?:\*\*|__)(.+?)(?:\*\*|__)(?:~~)?$/);return N?N[1].trim():null},c=x=>{const h=(x||"").trim();return h?/^([0-9]+[.)]|[a-zA-Z][.)]|[-*+]|[â¢â¦âªâ«â£Â·]|[ââ])\s+/.test(h):!1},y=x=>{const h=(x||"").split(` 12`).map(N=>N.trim()).filter(Boolean);return h.length?h[h.length-1]:""},S=(x,h,N)=>{if(c(N))return!1;const $=u(x);if(!$)return!1;const j=a($).text;return!(!j||j.endsWith(":")||c(j)||j.split(/\s+/).filter(Boolean).length>12||j.length>120||(h||"").trim()==="")},f=()=>{l&&r.push({...l,content:(l.content||"").trim()})};for(let x=0;x<n.length;x+=1){const h=n[x],N=x+1<n.length?n[x+1]:"",$=x>0?n[x-1]:"",j=g,F=h.match(/^\s*(```+|~~~+)/);if(F){const E=F[1];g?m&&E[0]===m[0]&&E.length>=m.length&&(g=!1,m=null):(g=!0,m=E)}if(j||!!F){l?l.content+=(l.content?` 13`:"")+h:l={id:`section-${r.length+1}-${Date.now()}`,level:2,heading:"Intro",anchor:null,content:h};continue}const O=h.match(/^(#{1,6})\s+(.*)$/);if(O){const E=a(O[2]);let L=E.text,_="";const T=/(\*\*|__|~~)/.test(O[2]),Z=L.split(/\s+/).filter(Boolean).length,W=L.length>140||Z>18;if(!T&&W){const C=L.match(/^(.+?[.!?])\s+(.+)/);if(C)L=C[1].trim(),_=C[2].trim();else{const A=L.match(/^(.+?)\s[ââ-]\s+(.+)/);A&&(L=A[1].trim(),_=A[2].trim())}}if(c(L)){l||(l={id:`section-${r.length+1}-${Date.now()}`,level:2,heading:"Intro",anchor:null,content:""}),l.content+=(l.content?` 14`:"")+L;continue}!_&&W&&(_=L),f(),l={id:`section-${r.length+1}-${Date.now()}`,level:O[1].length,heading:L||"Untitled",anchor:E.anchor||null,content:_};const X=20,ee=160,k=N.trim();if(k&&!k.startsWith("#")&&!k.startsWith(">")&&!S(k,n[x+2]||"")&&u(k)){const C=`${L} ${k}
14`.trim(),A=C.split(/\s+/).filter(Boolean).length;C.length<=ee&&A<=X&&(l.heading=C,x+=1)}continue}if(l&&u(h)&&c(y(l.content))){l.content+=(l.content?` 15`:"")+`- ${h.trim()}`;continue}if(S(h,N,$)){const E=a(u(h)).text;f(),l={id:`section-${r.length+1}-${Date.now()}`,level:2,heading:E||"Untitled",anchor:null,content:""};continue}if(!l){l={id:`section-${r.length+1}-${Date.now()}`,level:2,heading:"Intro",anchor:null,content:h};continue}l.content+=(l.content?` 16`:"")+h}return f(),r.length||r.push({id:`section-1-${Date.now()}`,level:2,heading:"Intro",anchor:null,content:""}),r}function Ee(s){return s.map(n=>{const r=(n.anchor||"").trim(),l=n.heading.trim()||"Untitled",g=`${"#".repeat(n.level)} ${l}${r?` {#${r}}`:""}`,m=(n.content||"").trim();return m?`${g} 17${m}`:g}).join(` 18 19`).trim()}function ie(s){const n=typeof s=="number"?s:(s||"").length;return Math.ceil(n/4)}const G=({message:s})=>t.jsx("button",{type:"button",onClick:()=>alert(s),title:s,className:"inline-flex items-center justify-center w-4 h-4 text-[10px] border border-gray-400 rounded-full text-gray-600 hover:text-gray-800","aria-label":"Info",children:"?"});function Lt({entity:s,revisions:n=[],active_md_revision_id:r,selected_revision_id:l,selected_md_path:g,selected_content:m,embedded:a=!1}){const u=`MD Editor â ${s?.label||"Source"}`,c=st(),[y,S]=w.useState(m||""),[f,x]=w.useState(l||null),[h,N]=w.useState(g||""),[$,j]=w.useState(r||null),[F,P]=w.useState(n),[O,E]=w.useState(""),[L,_]=w.useState(!1),[T,Z]=w.useState(!1),[W,X]=w.useState("sections"),[ee,k]=w.useState(!1),[C,A]=w.useState("remove-all"),[p,Q]=w.useState(()=>Y(m||"")),[U,I]=w.useState(p[0]?.id??null),[te,Ie]=w.useState({}),K=w.useMemo(()=>Ee(p),[p]),ne=K!==y;w.useEffect(()=>{S(K)},[]);const M=p.find(e=>e.id===U)||p[0]||null;w.useEffect(()=>{!U&&p.length&&I(p[0].id)},[U,p]);const He=async e=>{if(!L&&!(ne&&!confirm("Discard unsaved changes?"))){_(!0);try{const i=await fetch(route("md.revisions.content",{revision:e}),{headers:{Accept:"application/json"}});if(!i.ok){const R=await i.text();throw new Error(R||"Failed to load revision.")}const o=await i.json(),d=o.content||"",v=Y(d),b=Ee(v);Q(v),I(v[0]?.id??null),S(b),x(o.id),N(o.md_path||""),E("")}catch(i){alert(i?.message||String(i))}finally{_(!1)}}},Ae=async()=>{if(f){_(!0);try{const e=await fetch(route(s?.type==="document"?"md.documents.set-active":"md.urls.set-active",s?.type==="document"?{test:s.test_id,document:s.id}:{test:s.test_id,url:s.id}),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest","X-CSRF-TOKEN":c},body:JSON.stringify({md_revision_id:f})});if(!e.ok){const o=await e.text();throw new Error(o||"Failed to set active.")}const i=await e.json();j(i.active_md_revision_id)}catch(e){alert(e?.message||String(e))}finally{_(!1)}}},Oe=async()=>{if(!f){alert("Select a base revision first.");return}Z(!0);try{const e=await fetch(route(s?.type==="document"?"md.documents.save-version":"md.urls.save-version",s?.type==="document"?{test:s.test_id,document:s.id}:{test:s.test_id,url:s.id}),{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest","X-CSRF-TOKEN":c},body:JSON.stringify({base_md_revision_id:f,md_content:K,label:O||void 0,model_name:"manual"})});if(!e.ok){const d=await e.text();throw new Error(d||"Failed to save revision.")}const i=await e.json(),o={id:i.new_revision_id,md_path:i.md_path,origin:"manual_edit",label:O||null,base_md_revision_id:f,created_at:i.created_at,updated_at:i.created_at};x(o.id),N(o.md_path),S(K),E(""),j($),P(d=>[o,...d])}catch(e){alert(e?.message||String(e))}finally{Z(!1)}},De=()=>{if(!ne||!confirm("Discard changes and revert to selected revision?"))return;const e=Y(y);Q(e),I(e[0]?.id??null)},D=e=>{Q(e),e.find(i=>i.id===U)||I(e[0]?.id??null)},Be=e=>{const i=(e||"").split(` 20`),o=[];let d=0;return i.forEach(v=>{const b=v.replace(/\s+$/g,""),R=b.trim(),H=/^#{1,6}\s*$/.test(b),z=/^(\s*[-*+]|\s*\d+\.)\s*$/.test(b);if(!(H||z)){if(!R){if(d+=1,d>1)return;o.push("");return}d=0,o.push(b)}}),o.join(` 21`)},V=e=>{const i=B(e(K));D(Y(i))},Fe=()=>{let e=K;e=B(fe(e)),e=B(ge(e)),e=B(xe(e)),e=B(Re(e)),e=B(Me(e,{mode:"keep-label"})),e=B(Se(e)),e=B(e),e=B(Be(e)),D(Y(e))},We=()=>{k(!0)},ze=()=>{k(!1),V(e=>Me(e,{mode:C}))},Ue=()=>{V(e=>Re(e))},xe=e=>{const i=[/related/i,/read more/i,/advertisement/i,/subscribe/i,/newsletter/i,/sign up/i,/all rights reserved/i,/privacy policy/i,/terms of/i,/cookies?/i,/share/i];return(e||"").split(` 22`).filter(o=>!i.some(d=>d.test(o))).join(` 23`)},Ke=()=>{V(e=>xe(e))},ge=e=>(e||"").replace(/<!--[\s\S]*?-->/g,"").split(` 24`).filter(i=>!/^\[\^.+\]:/.test(i)&&!/^\[[^\]]+\]:\s+\S+/.test(i)).join(` 25`),Pe=()=>{V(e=>ge(e))},fe=e=>(e||"").replace(/<\/?[^>]+>/g,""),Xe=()=>{V(e=>fe(e))},Je=()=>{V(e=>Se(e))},J=e=>p.find(i=>i.id===e),qe=e=>{const i=J(e.id)||e,o=prompt("Edit heading",i.heading);o!==null&&D(p.map(d=>d.id===i.id?{...d,heading:o.trim()||"Untitled"}:d))},ae=(e,i)=>{D(p.map(o=>o.id===e?{...o,...i}:o))},Ge=e=>{const i=J(e.id)||e,o=prompt("New subsection title","New subsection");if(!o)return;const d=Math.min(i.level+1,6),v=p.findIndex(R=>R.id===i.id);if(v===-1)return;const b=[...p];b.splice(v+1,0,{id:`section-${Date.now()}-${Math.random().toString(16).slice(2)}`,level:d,heading:o.trim(),content:""}),D(b)},be=e=>{const i=J(e.id)||e;confirm("Delete this section?")&&D(p.filter(o=>o.id!==i.id))},ve=e=>{const i=J(e.id)||e,o=p.findIndex(z=>z.id===i.id);if(o===-1||o>=p.length-1)return;const d=p[o+1],v=`${i.heading||"Untitled"} + ${d.heading||"Untitled"}`,b=prompt(`Merged heading title (merging: ${v})`,i.heading||d.heading||"Merged section");if(b===null)return;const R={...i,heading:b.trim()||"Merged section",content:[i.content,d.content].filter(
25Boolean).join(` 26 27`)},H=[...p];H.splice(o,2,R),D(H)},we=(e,i)=>{const o=J(e.id)||e,d=p.findIndex(H=>H.id===o.id);if(d===-1)return;const v=d+i;if(v<0||v>=p.length)return;const b=[...p],[R]=b.splice(d,1);b.splice(v,0,R),D(b)},Ze=e=>{const i=J(e.id)||e,o=te[i.id],d=i.content||"",v=Number.isFinite(o)&&o>=0&&o<=d.length?o:Math.floor(d.length/2),b=d.slice(0,v).trimEnd(),R=d.slice(v).trimStart();if(!R)return;const H=prompt("New section heading","New section");if(!H)return;const z=p.findIndex(me=>me.id===i.id);if(z===-1)return;const se=[...p];se[z]={...i,content:b},se.splice(z+1,0,{id:`section-${Date.now()}-${Math.random().toString(16).slice(2)}`,level:i.level,heading:H.trim(),content:R}),D(se)},Qe=e=>{const i=J(e.id)||e,o=prompt("New section heading","New section");if(!o)return;const d=p.findIndex(b=>b.id===i.id);if(d===-1)return;const v=[...p];v.splice(d+1,0,{id:`section-${Date.now()}-${Math.random().toString(16).slice(2)}`,level:i.level,heading:o.trim(),content:""}),D(v)},ye=w.useMemo(()=>p.map(e=>({key:e.id,id:e.id,title:e.heading,level:e.level,length:e.content.length,anchor:e.anchor})),[p]),Ve=w.useMemo(()=>p.reduce((e,i)=>e+ie(i.content),0),[p]),ce=w.useRef(null),[q,je]=w.useState({height:0,top:0,visible:!1}),[ke,Ne]=w.useState(!1),de=w.useRef({y:0,top:0});w.useEffect(()=>{const e=ce.current;if(!e)return;const i=()=>{const{scrollHeight:o,clientHeight:d,scrollTop:v}=e;if(o<=d){je({height:0,top:0,visible:!1});return}const b=Math.max(24,Math.round(d/o*d)),R=d-b,H=Math.round(v/(o-d)*R);je({height:b,top:H,visible:!0})};return i(),e.addEventListener("scroll",i,{passive:!0}),window.addEventListener("resize",i),()=>{e.removeEventListener("scroll",i),window.removeEventListener("resize",i)}},[p.length]),w.useEffect(()=>{if(!ke)return;const e=ce.current;if(!e)return;const i=d=>{const{scrollHeight:v,clientHeight:b}=e;if(v<=b)return;const R=d.clientY-de.current.y,H=v-b,z=b-q.height,me=Math.min(Math.max(0,de.current.top+R),z)/z*H;e.scrollTop=me},o=()=>Ne(!1);return window.addEventListener("mousemove",i),window.addEventListener("mouseup",o),()=>{window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",o)}},[ke,q.height,q.top]);const Le=t.jsxs(t.Fragment,{children:[t.jsx(Ye,{title:u}),t.jsx("style",{children:` 28 .outline-scroll::-webkit-scrollbar {
29 display: none; 30 } 31 `}),t.jsx(nt,{show:ee,onClose:()=>k(!1),maxWidth:"md",children:t.jsxs("div",{className:"p-4 space-y-4",children:[t.jsx("div",{className:"text-lg font-semibold text-slate-800",children:"Remove links"}),t.jsxs("div",{className:"space-y-3 text-sm text-slate-700",children:[t.jsxs("label",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"radio",name:"remove-links-mode",value:"remove-all",checked:C==="remove-all",onChange:()=>A("remove-all"),className:"mt-1"}),t.jsxs("span",{children:[t.jsx("span",{className:"font-semibold block",children:"Remove links completely (remove label too)"}),t.jsx("span",{className:"text-xs text-slate-500",children:"Link-only lines are dropped; inline links are removed."})]})]}),t.jsxs("label",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"radio",name:"remove-links-mode",value:"keep-label",checked:C==="keep-label",onChange:()=>A("keep-label"),className:"mt-1"}),t.jsxs("span",{children:[t.jsx("span",{className:"font-semibold block",children:"Keep labels (replace [label](url) with label)"}),t.jsx("span",{className:"text-xs text-slate-500",children:"Keeps text label, removes URLs."})]})]})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:()=>k(!1),className:"rounded-full border border-slate-200 bg-white px-4 py-1.5 text-sm text-slate-700 hover:bg-slate-50",children:"Cancel"}),t.jsx("button",{type:"button",onClick:ze,className:"rounded-full border border-emerald-600 bg-emerald-600 px-4 py-1.5 text-sm text-white hover:bg-emerald-500",children:"Apply"})]})]})}),t.jsx("div",{className:"py-4 sm:py-6",children:t.jsxs("div",{className:"w-full max-w-full lg:max-w-6xl mx-auto px-2 sm:px-4 lg:px-8 space-y-4 sm:space-y-6",children:[!a&&t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("h1",{className:"text-xl font-semibold",children:u}),t.jsxs("div",{className:"text-xs text-gray-600 break-words",children:[s?.type==="document"?"Document":"URL",": ",s?.path]}),t.jsxs("div",{className:"text-xs text-gray-500 break-words",children:["Selected MD: ",h||"â"]}
31)]}),t.jsx("div",{className:"shrink-0",children:t.jsx(et,{href:route("tests.show",{test:s?.test_id}),className:"text-sm text-indigo-600 hover:underline",children:"Back to Test"})})]}),t.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[240px_1fr_320px] gap-3 sm:gap-4",children:[t.jsxs("div",{className:"order-2 lg:order-1 border border-slate-200 bg-white/90 p-3 rounded-lg",children:[t.jsx("div",{className:"text-sm font-semibold mb-2 text-slate-700",children:"Revisions"}),F?.length?t.jsx("div",{className:"space-y-2 text-xs",children:F.map(e=>{const i=e.id===f,o=e.id===$;return t.jsxs("button",{type:"button",onClick:()=>He(e.id),className:"w-full text-left border rounded px-2 py-1 hover:bg-slate-50 "+(i?"border-indigo-300 bg-indigo-50 ":"border-slate-200")+(o?" ring-1 ring-emerald-200":""),disabled:L,children:[t.jsx("div",{className:"break-words",children:e.md_path}),t.jsxs("div",{className:"text-gray-500",children:[e.created_at||"â",e.id?` · #${e.id}`:"",e.label?` · ${e.label}`:"",o?" · active":""]})]},e.id)})}):t.jsx("div",{className:"text-xs text-gray-500",children:"No MD revisions yet."})]}),t.jsxs("div",{className:"order-1 lg:order-2 border border-slate-200 bg-white/95 p-3 rounded-lg space-y-4",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 border border-slate-200 bg-slate-50 px-3 py-1 text-[11px] text-slate-500",children:[t.jsx("span",{className:"uppercase tracking-wide",children:"Label"}),t.jsx("input",{type:"text",value:O,onChange:e=>E(e.target.value),placeholder:"Optional",className:"w-40 rounded-sm border border-slate-200 bg-white px-2 py-0.5 text-xs text-slate-700 placeholder-slate-400 outline-none"})]}),t.jsx("button",{type:"button",onClick:Oe,disabled:T||!f,className:"rounded-full inline-flex items-center border border-indigo-600 bg-indigo-600 px-4 py-1.5 text-sm text-white shadow-sm transition hover:bg-indigo-500 disabled:opacity-60",children:T?"Savingâ¦":"Save as New Version"}),t.jsx("button",{type:"button",onClick:Ae,disabled:!f||L,className:"rounded-full inline-flex items-center border px-4 py-1.5 text-sm shadow-sm transition disabled:opacity-60 "+(f&&f===$?"border-emerald-300 bg-emerald-300 text-emerald-900 hover:bg-emerald-200":"border-emerald-600 bg-emerald-600 text-white hover:bg-emerald-500"),children:"Set Active"}),t.jsx("div",{className:"text-xs text-gray-500",children:ne?"Unsaved changes":"Saved"}),t.jsx("button",{type:"button",onClick:De,disabled:!ne,className:"rounded-full inline-flex items-center border border-amber-200 bg-amber-50 px-4 py-1.5 text-sm text-amber-700 shadow-sm transition hover:bg-amber-100 disabled:opacity-60",children:"Discard Changes"})]}),t.jsxs("div",{className:"rounded border border-slate-200 bg-slate-50 px-3 py-2 text-xs text-slate-600",children:[t.jsx("div",{className:"font-semibold text-slate-700",children:"Curation checklist"}),t.jsxs("ul",{className:"mt-1 space-y-1",children:[t.jsx("li",{children:"Keep only sections that matter for MCQs."}),t.jsx("li",{children:"Remove navigation, related links, and promos."}),t.jsx("li",{children:"Split long sections into smaller ones."}),t.jsx("li",{children:"Delete empty headings or one-line fragments."})]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsxs("div",{className:"inline-flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:Ue,className:"rounded-full inline-flex items-center border border-emerald-200 bg-emerald-50/70 px-3 py-1.5 text-sm text-emerald-800 shadow-sm transition hover:bg-emerald-100",children:"Remove TOC"}),t.jsx(G,{message:"Removes table-of-contents blocks and link lists. Risk: may remove a non-TOC list that looks like a TOC."})]}),t.jsxs("div",{className:"inline-flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:We,className:"rounded-full inline-flex items-center border border-yellow-300 bg-yellow-50 px-3 py-1.5 text-sm text-yellow-900 shadow-sm transition hover:bg-yellow-100",children:"Remove links"}),t.jsx(G,{message:"Strips Markdown links and raw URLs. Risk: loses source references or important identifiers embedded in URLs."})]}),t.jsxs("div",{className:"inline-flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:Je,className:"rounded-full inline-flex items-center border border-yellow-200 bg-yellow-50/70 px-3 py-1.5 text-sm text-yellow-800 shadow-sm transition hover:bg-yellow-100",children:"Remove images"}),t.jsx(G,{message:"Removes all image references (Markdown and HTML). Risk: loses figures that might carry key context."})]}),t.jsxs("div",{className:"inline-flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:Pe,className:"rounded-full inline-flex items-center border border-orange-300 bg-orange-50 px-3 py-1.5 text-sm text-orange-900 shadow-sm transition hover:bg-orange-100",children:"Remove c
31omments/refs"}),t.jsx(G,{message:"Removes HTML comments and footnote/reference definitions. Risk: deletes footnotes that carry key facts."})]}),t.jsxs("div",{className:"inline-flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:Ke,className:"rounded-full inline-flex items-center border border-orange-400 bg-orange-100 px-3 py-1.5 text-sm text-orange-950 shadow-sm transition hover:bg-orange-200",children:"Remove boilerplate"}),t.jsx(G,{message:"Removes lines with promo/legal keywords (subscribe, privacy, terms, etc.). Risk: can delete valid content containing those terms."})]}),t.jsxs("div",{className:"inline-flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:Xe,className:"rounded-full inline-flex items-center border border-red-300 bg-red-50 px-3 py-1.5 text-sm text-red-900 shadow-sm transition hover:bg-red-100",children:"Strip HTML"}),t.jsx(G,{message:"Removes all HTML tags. Risk: loses structure (tables, code, superscripts), which can break meaning for MCQs."})]}),t.jsxs("div",{className:"inline-flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:Fe,className:"rounded-full inline-flex items-center border border-red-600 bg-red-600 px-3 py-1.5 text-sm text-white shadow-sm transition hover:bg-red-500",children:"Clean noise"}),t.jsx(G,{message:"Runs full cleaning pipeline (HTML, refs, boilerplate, TOC, links, images) plus sanitization. Risk: may remove content you meant to keep."})]})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-end gap-1 border-b border-slate-200",children:[t.jsx("button",{type:"button",onClick:()=>X("sections"),className:"relative -mb-px px-4 py-2 text-sm border rounded-t transition "+(W==="sections"?"bg-white text-indigo-700 border-slate-200 border-b-white":"bg-slate-100 text-gray-600 border-transparent hover:text-gray-900"),children:"Section editor"}),t.jsx("button",{type:"button",onClick:()=>X("full"),className:"relative -mb-px px-4 py-2 text-sm border rounded-t transition "+(W==="full"?"bg-white text-indigo-700 border-slate-200 border-b-white":"bg-slate-100 text-gray-600 border-transparent hover:text-gray-900"),children:"Full editor"})]}),t.jsxs("div",{className:"border border-slate-200 rounded-b-lg bg-white/90 p-3 space-y-3",children:[W==="sections"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("div",{className:"text-sm font-semibold",children:"Section editor"}),M&&t.jsxs("div",{className:"text-xs text-gray-500",children:[M.content.length," chars · ~",ie(M.content)," tokens"]})]}),M?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("input",{type:"text",value:M.heading,onChange:e=>ae(M.id,{heading:e.target.value}),className:"border border-slate-200 rounded px-2 py-1 text-sm flex-1 min-w-[220px]"}),t.jsx("select",{value:M.level,onChange:e=>ae(M.id,{level:Number(e.target.value)}),className:"border border-slate-200 rounded px-2 py-1 text-sm",title:"Heading level",children:[1,2,3,4,5,6].map(e=>t.jsxs("option",{value:e,children:["H",e]},e))}),t.jsx("button",{type:"button",onClick:()=>Qe(M),className:"rounded-full inline-flex items-center border border-slate-200 bg-slate-50 px-3 py-1.5 text-sm text-slate-700 shadow-sm transition hover:bg-slate-100",children:"Add section below"})]}),t.jsx("textarea",{value:M.content,onChange:e=>ae(M.id,{content:e.target.value}),onSelect:e=>Ie(i=>({...i,[M.id]:e.target.selectionStart})),className:"w-full min-h-[260px] border border-slate-200 rounded px-3 py-2 text-sm bg-white",placeholder:"Section content..."}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",onClick:()=>Ze(M),className:"rounded-full inline-flex items-center border border-slate-200 bg-white px-3 py-1.5 text-sm text-slate-700 shadow-sm transition hover:bg-slate-50",children:"Split at cursor"}),t.jsx("button",{type:"button",onClick:()=>ve(M),className:"rounded-full inline-flex items-center border border-slate-200 bg-white px-3 py-1.5 text-sm text-slate-700 shadow-sm transition hover:bg-slate-50",children:"Merge with next"}),t.jsx("button",{type:"button",onClick:()=>be(M),className:"rounded-full inline-flex items-center border border-red-200 bg-red-50 px-3 py-1.5 text-sm text-red-700 shadow-sm transition hover:bg-red-100",children:"Delete section"}),M.content.length>ue&&t.jsx("span",{className:"text-xs text-amber-600",children:"Long section â consider splitting."})]}),t.jsxs("div",{className:"mt-2 rounded-md border border-indigo-200 bg-indigo-50/50 px-3 py-2 text-xs text-indigo-700",children:["Total tokens across all sections: ~",Ve]})]}):t.jsxs("div",{className:"text-xs text-gray-500",children:["No sections available.",t.jsx("button",{type:"button",onClick:()=>D([{id:`section-${Date.now()}`,level:2,heading:"New section",content:""}]),className:"ml-2 text-indigo-600 hover:underline",children:"Add section"})]})]}),W==="full"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("div",{className:"text-sm font-semibold",children:"Full editor"}),t.jsxs("div",{className:"text-xs text-gray-500",children:[K.length," chars · ~",ie(K)," tokens"]})]}),t.jsx("textarea",{value:K,onChange:e=>{const i=Y(e.target.value);Q(i),I(i[0]?.id??null)},className:"w-full min-h-[260px] border border-slate-200 rounded px-3 py-2 text-sm bg-white",placeholder:"Full markdown content..."})]})]})]}),!f&&t.jsx("div",{className:"text-xs text-amber-600",children:"Markdown file could not be loaded. Check the selected path or shared storage."})]}),t.jsxs("div",{className:"outline-panel relative order-3 border border-slate-200 bg-white/90 p-3 rounded-lg lg:sticky lg:top-4 lg:max-h-[calc(100vh-2rem)]",children:[t.jsxs("div",{ref:ce,className:"outline-scroll max-h-[calc(100vh-4rem)] overflow-y-auto scroll-smooth pr-4",style:{scrollbarGutter:"stable",scrollbarWidth:"none"},children:[t.jsx("div",{className:"text-sm font-semibold mb-2 text-slate-700",children:"Outline"}),ye.length?t.jsx("div",{className:"space-y-2 text-xs",children:ye.map((e,i)=>t.jsxs("div",{className:"group flex items-start justify-between gap-2 rounded-md border border-slate-200 px-2 py-2 "+(i%2===0?"bg-white":"bg-indigo-50/40"),children:[t.jsxs("button",{type:"button",onClick:()=>I(e.id),className:"text-left flex-1 min-w-0 break-words "+(e.id===U?"text-indigo-700":""),title:e.length>ue?"Long section":"Jump to section",children:[t.jsx("span",{className:"text-gray-400 mr-1",children:"·".repeat(Math.max(0,e.level-1))}),e.title||"(untitled)",e.anchor&&t.jsxs("span",{className:"ml-2 text-[10px] text-slate-500",children:["#",e.anchor]}),e.length>ue&&t.jsx("span",{className:"ml-2 text-[10px] text-amber-600",children:"Long"}),t.jsxs("span",{className:"mt-1 inline-flex items-center gap-2 rounded-full border border-slate-200 bg-white px-2 py-0.5 text-[10px] text-slate-600 whitespace-nowrap no-underline hover:no-underline max-w-full",children:[e.length," chars · ~",ie(e.length)," tokens"]})]}),t.jsxs("div",{className:"flex flex-col items-end gap-1 opacity-30 group-hover:opacity-100 flex-shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:()=>qe(e),className:"rounded-full border border-indigo-200 bg-indigo-50 px-2 py-0.5 text-[11px] text-indigo-700 shadow-sm transition hover:bg-indigo-100",children:"Edit"}),t.jsx("button",{type:"button",onClick:()=>be(e),className:"rounded-full border border-red-200 bg-red-50 px-2 py-0.5 text-[11px] text-red-700 shadow-sm transition hover:bg-red-100",children:"Delete"}),t.jsx("button",{type:"button",onClick:()=>we(e,-1),className:"rounded-full border border-slate-200 bg-white px-2 py-0.5 text-[11px] text-gray-600 shadow-sm transition hover:bg-slate-100",title:"Move up",children:"â"})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("button",{type:"button",onClick:()=>Ge(e),className:"rounded-full border border-emerald-200 bg-emerald-50 px-2 py-0.5 text-[11px] text-emerald-700 shadow-sm transition hover:bg-emerald-100",children:"+"}),t.jsx("button",{type:"button",onClick:()=>ve(e),className:"rounded-full border border-slate-200 bg-slate-50 px-2 py-0.5 text-[11px] text-slate-700 shadow-sm transition hover:bg-slate-100",children:"Merge"}),t.jsx("button",{type:"button",onClick:()=>we(e,1),className:"rounded-full border border-slate-200 bg-white px-2 py-0.5 text-[11px] text-gray-600 shadow-sm transition hover:bg-slate-100",title:"Move down",children:"â"})]})]})]},e.key))}):t.jsx("div",{className:"text-xs text-gray-500",children:"No headings detected."})]}),q.visible&&t.jsx("div",{className:"pointer-events-none absolute right-2 top-8 bottom-4 w-2",children:t.jsx("div",{className:"relative h-full rounded-full bg-slate-100/80",children:t.jsx("div",{className:"pointer-events-auto absolute left-0 right-0 rounded-full bg-slate-400/80 hover:bg-slate-500/90",style:{height:`${q.height}px`,top:`${q.top}px`},onMouseDown:e=>
31{e.preventDefault(),de.current={y:e.clientY,top:q.top},Ne(!0)}})})})]})]})]})})]});return a?t.jsx("div",{className:"bg-white",children:Le}):t.jsx(tt,{children:Le})}export{Lt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.