import{c as ne}from"./chunk-3TWYSNJO.js";import{a as ee}from"./chunk-2H3HTOVO.js";import{A as f,B as I,C as te,m as l,o as S,v as T,w as v}from"./chunk-B4FSAK53.js";import{c as we}from"./chunk-FSRPMVAS.js";var K={};we(K,{createDefaultFindOptions:()=>Te,createSearchPattern:()=>ae,escapeRegexString:()=>re,findAllMatches:()=>H,findInDocument:()=>Ae,findInParagraph:()=>oe,getDefaultHighlightOptions:()=>Oe,getMatchCountText:()=>Me,isEmptySearch:()=>Se,replaceAllInContent:()=>Ne,replaceFirstInContent:()=>Fe,scrollToMatch:()=>Le});function Te(){return{matchCase:!1,matchWholeWord:!1,useRegex:!1}}function re(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ae(e,n){if(!e)return null;try{let t;n.useRegex?t=e:t=re(e),n.matchWholeWord&&(t=`\\b${t}\\b`);let i=n.matchCase?"g":"gi";return new RegExp(t,i)}catch{return null}}function H(e,n,t){if(!e||!n)return[];let i=[],c=n;t.matchCase||(c=n.toLowerCase());let x=W=>W.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),p;t.matchWholeWord?p=`\\b${x(c)}\\b`:p=x(c);let d=t.matchCase?"g":"gi",b=new RegExp(p,d),y;for(;(y=b.exec(e))!==null;)i.push({start:y.index,end:y.index+y[0].length}),y[0].length===0&&b.lastIndex++;return i}function Ne(e,n,t,i){let c=ae(n,i);return c?e.replace(c,t):e}function Fe(e,n,t,i,c=0){let x=H(e,n,i),p=x.find(d=>d.start>=c)||x[0];return p?{content:e.substring(0,p.start)+t+e.substring(p.end),replaced:!0,matchStart:p.start,matchEnd:p.start+t.length}:{content:e,replaced:!1,matchStart:-1,matchEnd:-1}}function Me(e){return e?e.totalCount===0?"No results":e.totalCount===1?"1 match":`${e.currentIndex+1} of ${e.totalCount} matches`:""}function Se(e){return!e||e.trim()===""}function Oe(){return{currentMatchColor:"#FFFF00",otherMatchColor:"#FFFFAA"}}function A(e){if(!e||!e.content)return"";let n="";for(let t of e.content)t.type==="text"?n+=t.text||"":t.type==="tab"?n+="	":t.type==="break"&&t.breakType==="textWrapping"&&(n+=`
`);return n}function De(e){if(!e||!e.content)return"";let n="";for(let t of e.content)if(t.type==="run")n+=A(t);else if(t.type==="hyperlink")for(let i of t.children||[])i.type==="run"&&(n+=A(i));return n}function Ae(e,n,t){if(!e||!n)return[];let i=[],c=e.package?.document||e.package?.document;if(!c||!c.content)return i;let x=0;for(let p of c.content)if(p.type==="paragraph"){let d=oe(p,n,t,x);i.push(...d),x++}else if(p.type==="table")for(let d of p.rows||[])for(let b of d.cells||[])for(let y of b.content||[])y.type;return i}function oe(e,n,t,i){let c=[],x=De(e);if(!x)return c;let p=H(x,n,t);for(let d of p){let b=Ee(e,d.start);c.push({paragraphIndex:i,contentIndex:b.contentIndex,startOffset:b.offsetInContent,endOffset:b.offsetInContent+(d.end-d.start),text:x.substring(d.start,d.end)})}return c}function Ee(e,n){if(!e||!e.content)return{contentIndex:0,runIndex:0,offsetInContent:n};let t=0,i=0;for(let c of e.content){let x="";if(c.type==="run")x=A(c);else if(c.type==="hyperlink")for(let d of c.children||[])d.type==="run"&&(x+=A(d));let p=x.length;if(t+p>n)return{contentIndex:i,runIndex:i,offsetInContent:n-t};t+=p,i++}return{contentIndex:Math.max(0,e.content.length-1),runIndex:Math.max(0,e.content.length-1),offsetInContent:0}}function Le(e,n){if(!e||!n)return;let t=e.querySelector(`[data-paragraph-index="${n.paragraphIndex}"]`);t&&t.scrollIntoView({behavior:"smooth",block:"center"})}var le={};ee(le,K);function Ue(e){let[n,t]=v({isOpen:!1,searchText:"",replaceText:"",options:(0,le.createDefaultFindOptions)(),matches:[],currentIndex:0,replaceMode:e?.initialReplaceMode??!1}),i=l(a=>{t(r=>({...r,isOpen:!0,replaceMode:!1,searchText:a||r.searchText,matches:[],currentIndex:0}))},[]),c=l(a=>{t(r=>({...r,isOpen:!0,replaceMode:!0,searchText:a||r.searchText,matches:[],currentIndex:0}))},[]),x=l(()=>{t(a=>({...a,isOpen:!1}))},[]),p=l(()=>{t(a=>({...a,isOpen:!a.isOpen}))},[]),d=l(a=>{t(r=>({...r,searchText:a}))},[]),b=l(a=>{t(r=>({...r,replaceText:a}))},[]),y=l(a=>{t(r=>({...r,options:{...r.options,...a}}))},[]),W=l((a,r=0)=>{let w=Math.max(0,Math.min(r,a.length-1));t(F=>({...F,matches:a,currentIndex:a.length>0?w:0})),e?.onMatchesChange?.(a),a.length>0?e?.onCurrentMatchChange?.(a[w],w):e?.onCurrentMatchChange?.(null,-1)},[e]),N=l(()=>{let a=0;return t(r=>r.matches.length===0?r:(a=(r.currentIndex+1)%r.matches.length,{...r,currentIndex:a})),a},[]),E=l(()=>{let a=0;return t(r=>r.matches.length===0?r:(a=r.currentIndex===0?r.matches.length-1:r.currentIndex-1,{...r,currentIndex:a})),a},[]),L=l(a=>{t(r=>r.matches.length===0||a<0||a>=r.matches.length?r:{...r,currentIndex:a})},[]),h=l(()=>n.matches.length===0?null:n.matches[n.currentIndex]||null,[n.matches,n.currentIndex]),u=l(()=>n.matches.length>0,[n.matches.length]);return{state:n,openFind:i,openReplace:c,close:x,toggle:p,setSearchText:d,setReplaceText:b,setOptions:y,setMatches:W,goToNextMatch:N,goToPreviousMatch:E,goToMatch:L,getCurrentMatch:h,hasMatches:u}}var $e={position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"transparent",display:"flex",alignItems:"flex-start",justifyContent:"flex-end",zIndex:1e4,pointerEvents:"none"},ze={backgroundColor:"var(--doc-surface)",borderRadius:"4px",boxShadow:"0 4px 20px var(--doc-shadow)",minWidth:"360px",maxWidth:"440px",width:"100%",margin:"60px 20px 20px 20px",pointerEvents:"auto"},Pe={display:"flex",justifyContent:"space-between",alignItems:"center",padding:"12px 16px",borderBottom:"1px solid var(--doc-border)",backgroundColor:"var(--doc-bg-subtle)",borderTopLeftRadius:"4px",borderTopRightRadius:"4px"},Be={margin:0,fontSize:"14px",fontWeight:600,color:"var(--doc-text)"},je={background:"none",border:"none",fontSize:"18px",cursor:"pointer",color:"var(--doc-text-muted)",padding:"2px 6px",lineHeight:1},He={padding:"16px"},ie={display:"flex",alignItems:"center",gap:"8px",marginBottom:"12px"},ce={width:"60px",fontSize:"13px",color:"var(--doc-text)",flexShrink:0},_={flex:1,padding:"8px 10px",border:"1px solid var(--doc-border-input)",borderRadius:"3px",fontSize:"13px",boxSizing:"border-box",outline:"none"},de={..._,borderColor:"var(--doc-link)",boxShadow:"0 0 0 2px var(--doc-focus-ring)"},Ke={display:"flex",flexDirection:"column",gap:"6px",marginLeft:"8px"},q={padding:"6px 12px",borderRadius:"3px",fontSize:"12px",fontWeight:500,cursor:"pointer",border:"1px solid var(--doc-border-input)",backgroundColor:"var(--doc-bg-input)",color:"var(--doc-text)",minWidth:"80px",textAlign:"center"},se={...q,backgroundColor:"var(--doc-bg-hover)",color:"var(--doc-text-placeholder)",cursor:"not-allowed"},G={padding:"6px 10px",borderRadius:"3px",fontSize:"14px",cursor:"pointer",border:"1px solid var(--doc-border-input)",backgroundColor:"var(--doc-bg-input)",color:"var(--doc-text)"},pe={...G,color:"var(--doc-border-input)",cursor:"not-allowed"},Ve={display:"flex",gap:"16px",marginTop:"4px",marginLeft:"68px"},V={display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",color:"var(--doc-text-muted)",cursor:"pointer"},ue={width:"14px",height:"14px",cursor:"pointer"},fe={marginLeft:"68px",fontSize:"12px",color:"var(--doc-text-muted)",marginBottom:"8px"},_e={...fe,color:"var(--doc-error)"},qe=220,Ge=({style:e})=>f("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:e,children:f("polyline",{points:"18 15 12 9 6 15"})}),Je=({style:e})=>f("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:e,children:f("polyline",{points:"6 9 12 15 18 9"})});function Qe({isOpen:e,onClose:n,onFind:t,onFindNext:i,onFindPrevious:c,onReplace:x,onReplaceAll:p,onHighlightMatches:d,onClearHighlights:b,initialSearchText:y="",replaceMode:W=!1,currentResult:N,className:E,style:L}){let{t:h}=ne(),[u,a]=v(""),[r,w]=v(""),[F,J]=v(W),[g,he]=v(!1),[m,xe]=v(!1),[s,k]=v(null),[ge,Q]=v(!1),[me,X]=v(!1),$=T(null),Z=T(null),U=T(t),Y=T(d),M=T(b);S(()=>{U.current=t,Y.current=d,M.current=b},[t,d,b]),S(()=>{N!==void 0&&k(N)},[N]),S(()=>{e?(a(y),w(""),J(W),k(null),setTimeout(()=>{$.current?.focus(),$.current?.select()},100)):M.current?.()},[e,y,W]);let O=l(()=>{k(null),M.current?.()},[]),C=l((o,D)=>{if(!o.trim()){O();return}let j=U.current(o,D);k(j),j?.matches?Y.current?.(j.matches):M.current?.()},[O]);S(()=>{if(!e)return;if(!u.trim()){O();return}let o=window.setTimeout(()=>{C(u,{matchCase:g,matchWholeWord:m})},qe);return()=>window.clearTimeout(o)},[e,u,g,m,C,O]);let be=l(o=>{a(o.target.value),k(null)},[]),z=l(()=>{if(!u.trim()){C(u,{matchCase:g,matchWholeWord:m});return}if(!s){C(u,{matchCase:g,matchWholeWord:m});return}if(i()&&s){let o=(s.currentIndex+1)%s.totalCount;k({...s,currentIndex:o})}},[u,g,m,s,C,i]),P=l(()=>{if(!u.trim()){C(u,{matchCase:g,matchWholeWord:m});return}if(!s){C(u,{matchCase:g,matchWholeWord:m});return}if(c()&&s){let o=s.currentIndex===0?s.totalCount-1:s.currentIndex-1;k({...s,currentIndex:o})}},[u,g,m,s,C,c]),ye=l(o=>{o.key==="Enter"?(o.preventDefault(),o.shiftKey?P():s?z():C(u,{matchCase:g,matchWholeWord:m})):o.key==="Escape"&&n()},[s,u,g,m,C,z,P,n]),B=l(()=>{if(!(!s||s.totalCount===0)&&x(r)){let o=t(u,{matchCase:g,matchWholeWord:m});k(o),o?.matches&&d&&d(o.matches)}},[s,r,u,g,m,x,t,d]),Ce=l(o=>{o.key==="Enter"?(o.preventDefault(),B()):o.key==="Escape"&&n()},[B,n]),ve=l(()=>{u.trim()&&p(u,r,{matchCase:g,matchWholeWord:m})>0&&(k(null),M.current?.())},[u,r,g,m,p]),Ie=l(()=>{J(o=>{let D=!o;return D&&setTimeout(()=>Z.current?.focus(),100),D})},[]),ke=l(o=>{o.target,o.currentTarget},[]),Re=l(o=>{o.key==="Escape"&&n()},[n]);if(!e)return null;let R=s&&s.totalCount>0,We=s&&s.totalCount===0&&u.trim();return f("div",{className:`docx-find-replace-dialog-overlay ${E||""}`,style:{...$e,...L},onClick:ke,onKeyDown:Re,children:I("div",{className:"docx-find-replace-dialog","data-testid":"find-replace-dialog",style:ze,role:"dialog","aria-modal":"false","aria-labelledby":"find-replace-dialog-title",children:[I("div",{className:"docx-find-replace-dialog-header",style:Pe,children:[f("h2",{id:"find-replace-dialog-title",style:Be,children:h(F?"dialogs.findReplace.titleFindReplace":"dialogs.findReplace.titleFind")}),f("button",{type:"button",className:"docx-find-replace-dialog-close",style:je,onClick:n,"aria-label":h("common.closeDialog"),children:"\xD7"})]}),I("div",{className:"docx-find-replace-dialog-body",style:He,children:[I("div",{className:"docx-find-replace-dialog-row",style:ie,children:[f("label",{htmlFor:"find-text",style:ce,children:h("dialogs.findReplace.findLabel")}),f("input",{ref:$,id:"find-text",type:"text",className:"docx-find-replace-dialog-input",style:ge?de:_,value:u,onChange:be,onKeyDown:ye,onFocus:()=>Q(!0),onBlur:()=>{Q(!1),u.trim()&&!s&&C(u,{matchCase:g,matchWholeWord:m})},placeholder:h("dialogs.findReplace.findPlaceholder"),"aria-label":h("dialogs.findReplace.findAriaLabel")}),I("div",{style:{display:"flex",gap:"4px"},children:[f("button",{type:"button",className:"docx-find-replace-dialog-nav",style:R?G:pe,onClick:P,disabled:!R,"aria-label":h("dialogs.findReplace.findPrevious"),title:h("dialogs.findReplace.findPreviousTitle"),children:f(Ge,{})}),f("button",{type:"button",className:"docx-find-replace-dialog-nav",style:R?G:pe,onClick:z,disabled:!R,"aria-label":h("dialogs.findReplace.findNext"),title:h("dialogs.findReplace.findNextTitle"),children:f(Je,{})})]})]}),R&&f("div",{className:"docx-find-replace-dialog-status",style:fe,children:h("dialogs.findReplace.matchCount",{current:s.currentIndex+1,total:s.totalCount})}),We&&f("div",{className:"docx-find-replace-dialog-status",style:_e,children:h("dialogs.findReplace.noResults")}),F&&f(te,{children:I("div",{className:"docx-find-replace-dialog-row",style:ie,children:[f("label",{htmlFor:"replace-text",style:ce,children:h("dialogs.findReplace.replaceLabel")}),f("input",{ref:Z,id:"replace-text",type:"text",className:"docx-find-replace-dialog-input",style:me?de:_,value:r,onChange:o=>w(o.target.value),onKeyDown:Ce,onFocus:()=>X(!0),onBlur:()=>X(!1),placeholder:h("dialogs.findReplace.replacePlaceholder"),"aria-label":h("dialogs.findReplace.replaceAriaLabel")}),I("div",{style:Ke,children:[f("button",{type:"button",className:"docx-find-replace-dialog-button",style:R?q:se,onClick:B,disabled:!R,title:h("dialogs.findReplace.replaceCurrentTitle"),children:h("dialogs.findReplace.replaceButton")}),f("button",{type:"button",className:"docx-find-replace-dialog-button",style:R?q:se,onClick:ve,disabled:!R,title:h("dialogs.findReplace.replaceAllTitle"),children:h("dialogs.findReplace.replaceAllButton")})]})]})}),I("div",{className:"docx-find-replace-dialog-options",style:Ve,children:[I("label",{className:"docx-find-replace-dialog-option",style:V,children:[f("input",{type:"checkbox",style:ue,checked:g,onChange:o=>he(o.target.checked)}),h("dialogs.findReplace.matchCase")]}),I("label",{className:"docx-find-replace-dialog-option",style:V,children:[f("input",{type:"checkbox",style:ue,checked:m,onChange:o=>xe(o.target.checked)}),h("dialogs.findReplace.wholeWords")]}),!F&&f("button",{type:"button",style:{...V,background:"none",border:"none",cursor:"pointer",color:"var(--doc-link)",padding:0},onClick:Ie,children:h("dialogs.findReplace.toggleReplace")})]})]})]})})}var rt=Qe;export{le as a,Ue as b,Qe as c,rt as d};
