/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/@univerjs/find-replace@0.20.1/lib/es/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{CommandType as e,Disposable as t,DisposableCollection as n,EDITOR_ACTIVATED as r,FOCUSING_SHEET as i,ICommandService as a,IConfigService as o,IConfirmService as s,IContextService as c,IUniverInstanceService as l,Inject as u,Injector as d,LocaleService as f,Plugin as p,RxDisposable as ee,UniverInstanceType as te,createIdentifier as ne,merge as re,toDisposable as m}from"@univerjs/core";import{Button as ie,Checkbox as ae,FormDualColumnLayout as oe,FormLayout as h,Input as se,MessageType as g,Pager as ce,Select as _}from"@univerjs/design";import{ComponentManager as v,IDialogService as le,ILayoutService as y,IMenuManagerService as ue,IMessageService as de,IShortcutService as fe,KeyCode as b,MenuItemType as pe,MetaKeys as x,RibbonDataGroup as me,getMenuHiddenObservable as he,useDebounceFn as ge,useDependency as S,useObservable as C}from"@univerjs/ui";import{RENDER_RAW_FORMULA_KEY as _e}from"@univerjs/engine-render";import{BehaviorSubject as w,Subject as T,combineLatest as ve,debounceTime as ye,fromEvent as be,map as xe,takeUntil as Se,throttleTime as Ce}from"rxjs";import{SearchIcon as we}from"@univerjs/icons";import{forwardRef as Te,useCallback as E,useEffect as D,useImperativeHandle as Ee,useMemo as O,useRef as De,useState as Oe}from"react";import{Fragment as k,jsx as A,jsxs as j}from"react/jsx-runtime";const ke=`FIND_REPLACE_INPUT_FOCUS`,Ae=`FIND_REPLACE_DIALOG_FOCUS`,je=`FIND_REPLACE_REPLACE_REVEALED`;function M(e){"@babel/helpers - typeof";return M=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},M(e)}function Me(e,t){if(M(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(M(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ne(e){var t=Me(e,`string`);return M(t)==`symbol`?t:t+``}function N(e,t,n){return(t=Ne(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function P(e,t){return function(n,r){t(n,r,e)}}function F(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var Pe=class extends t{};const I=ne(`find-replace.service`);function Fe(e){return e.findString!==void 0||e.inputtingFindString!==void 0||e.findDirection!==void 0||e.matchesTheWholeCell!==void 0||e.caseSensitive!==void 0||e.findScope!==void 0||e.findBy!==void 0}let L=class extends t{get searched(){return this._findModels.length>0}constructor(e,t,n,r){super(),this._state=e,this._providers=t,this._univerInstanceService=n,this._commandService=r,N(this,`currentMatch$`,new w(null)),N(this,`replaceables$`,new w([])),N(this,`_findModels`,[]),N(this,`_matchingModel`,null),N(this,`_matches`,[]),N(this,`_currentSearchingDisposables`,null),this.disposeWithMe(this._state.stateUpdates$.pipe(Ce(200,void 0,{leading:!0,trailing:!0})).subscribe(async e=>{let t=this._state.state;Fe(e)&&(t.findString!==``&&!t.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):e.replaceRevealed!==!0&&this._stopSearching())}))}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...V(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};let e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}focusSelection(){var e;(e=this._matchingModel)==null||e.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};let e=Array.from(this._providers),t=this._findModels=(await Promise.all(e.map(e=>e.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(t);let n=this._matches=t.map(e=>e.getMatches()).flat();return this.replaceables$.next(n.filter(e=>e.replaceable)),n.length?(this._moveToInitialMatch(t),this._state.changeState({matchesCount:n.length}),{results:n}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(e=>e.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){let t=this._currentSearchingDisposables=new n,r=ve(e.map(e=>e.matchesUpdate$)).pipe(ye(220)).subscribe(([...e])=>{let t=this._matches=e.flat();t.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:t.length}),this.replaceables$.next(t.filter(e=>e.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});e.forEach(e=>t.add(m(e.activelyChangingMatch$.subscribe(e=>{let t=this._matches.findIndex(t=>t===e);this._state.changeState({matchesPosition:t+1})})))),t.add(m(r))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){let e=await Promise.all(this._findModels.map(e=>e.replaceAll(this._state.replaceString))).then(e=>e.reduce((e,t)=>(e.success+=t.success,e.failure+=t.failure,e),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){let t=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:t+1})}moveToNextMatch(){if(!this._matchingModel)return;let e=this._findModels.length===1,t=this._matchingModel.moveToNextMatch({loop:e});if(t)return this._markMatch(t),t;{let e=this._findModels.findIndex(e=>e===this._matchingModel);return this._moveToNextUnitMatch(e)}}_moveToNextUnitMatch(e){let t=this._findModels.length;for(let n=(e+1)%t;n!==e;){let e=this._findModels[n],r=e.moveToNextMatch({ignoreSelection:!0});if(r)return this._matchingModel=e,this._markMatch(r),r;n=(n+1)%t}if(this._matchingModel){let e=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return e&&this._markMatch(e),e}}moveToPreviousMatch(){if(!this._matchingModel)return;let e=this._findModels.length===1,t=this._matchingModel.moveToPreviousMatch({loop:e});if(t){let e=this._matches.findIndex(e=>e===t);return this.currentMatch$.next(t),this._state.changeState({matchesPosition:e+1}),t}else{let e=this._findModels.length,t=this._findModels.findIndex(e=>e===this._matchingModel);for(let n=(t-1+e)%e;n!==t;){let t=this._findModels[n],r=t.moveToPreviousMatch({ignoreSelection:!0});if(r)return this._matchingModel=t,this._markMatch(r),r;n=(n-1)%e}let n=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return n&&this._markMatch(n),n}}_moveToInitialMatch(e,t=!1){var n;let r=(n=this._univerInstanceService.getFocusedUnit())==null?void 0:n.getUnitId();if(!r)return-1;let i=e.findIndex(e=>e.unitId===r);if(i!==-1){this._matchingModel=e[i];let n=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:t});if(n)return this._markMatch(n),i}return this._moveToNextUnitMatch(i),0}};L=F([P(2,l),P(3,a)],L);let R=function(e){return e.ROW=`row`,e.COLUMN=`column`,e}({}),z=function(e){return e.VALUE=`value`,e.FORMULA=`formula`,e}({}),B=function(e){return e.SUBUNIT=`subunit`,e.UNIT=`unit`,e}({});function V(){return{caseSensitive:!1,findBy:z.VALUE,findCompleted:!1,findDirection:R.ROW,findScope:B.SUBUNIT,findString:``,inputtingFindString:``,matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:``,revealed:!0}}var Ie=class{constructor(){N(this,`_stateUpdates$`,new T),N(this,`stateUpdates$`,this._stateUpdates$.asObservable()),N(this,`_state$`,new w(V())),N(this,`state$`,this._state$.asObservable()),N(this,`_findString`,``),N(this,`_inputtingFindString`,``),N(this,`_replaceString`,``),N(this,`_revealed`,!1),N(this,`_replaceRevealed`,!1),N(this,`_matchesPosition`,0),N(this,`_matchesCount`,0),N(this,`_caseSensitive`,!0),N(this,`_matchesTheWholeCell`,!1),N(this,`_findDirection`,R.ROW),N(this,`_findScope`,B.SUBUNIT),N(this,`_findBy`,z.VALUE),N(this,`_findCompleted`,!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let t=!1,n={};e.findString!==void 0&&e.findString!==this._findString&&(this._findString=e.findString,n.findString=this._findString,t=!0),e.revealed!==void 0&&e.revealed!==this._revealed&&(this._revealed=e.revealed,n.revealed=e.revealed,t=!0),e.replaceRevealed!==void 0&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,n.replaceRevealed=e.replaceRevealed,t=!0),e.replaceString!==void 0&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,n.replaceString=e.replaceString,t=!0),e.matchesCount!==void 0&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,n.matchesCount=e.matchesCount,t=!0),e.matchesPosition!==void 0&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,n.matchesPosition=e.matchesPosition,t=!0),e.findBy!==void 0&&e.findBy!==this._findBy&&(this._findBy=e.findBy,n.findBy=e.findBy,t=!0),e.findScope!==void 0&&e.findScope!==this._findScope&&(this._findScope=e.findScope,n.findScope=e.findScope,t=!0),e.findDirection!==void 0&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,n.findDirection=e.findDirection,t=!0),e.caseSensitive!==void 0&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,n.caseSensitive=e.caseSensitive,t=!0),e.matchesTheWholeCell!==void 0&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,n.matchesTheWholeCell=e.matchesTheWholeCell,t=!0),e.inputtingFindString!==void 0&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,n.inputtingFindString=e.inputtingFindString,t=!0),e.findCompleted!==void 0&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,n.findCompleted=e.findCompleted,t=!0),t&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(n))}};let H=class extends t{get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}constructor(e,t){super(),this._injector=e,this._contextService=t,N(this,`_providers`,new Set),N(this,`_state`,new Ie),N(this,`_model`,void 0),N(this,`_currentMatch$`,new w(null)),N(this,`currentMatch$`,this._currentMatch$.asObservable()),N(this,`_replaceables$`,new w([])),N(this,`replaceables$`,this._replaceables$.asObservable()),N(this,`_focusSignal$`,new T),N(this,`focusSignal$`,this._focusSignal$.asObservable())}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getProviders(){return this._providers}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:``,findString:``})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e===z.FORMULA)}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw Error(`[FindReplaceService] replaceAll: model is not initialized!`);return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}focusSelection(){var e;(e=this._model)==null||e.focusSelection()}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(L,this._state,this._providers),this._model.currentMatch$.subscribe(e=>this._currentMatch$.next(e)),this._model.replaceables$.subscribe(e=>this._replaceables$.next(e));let t=V();return e&&(t.replaceRevealed=!0),this._state.changeState(t),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),m(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(je,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(_e,e)}};H=F([P(0,u(d)),P(1,c)],H);const U={id:`ui.command.replace-current-match`,type:e.COMMAND,handler:e=>e.get(I).replace()},W={id:`ui.command.replace-all-matches`,type:e.COMMAND,handler:async e=>{let t=e.get(s),n=e.get(f),r=e.get(de);if(!await t.confirm({id:`CONFIRM_REPLACE_ALL`,title:{title:n.t(`find-replace.replace.confirm.title`)},cancelText:n.t(`button.cancel`),confirmText:n.t(`button.confirm`)}))return!1;let{success:i,failure:a}=await e.get(I).replaceAll();return a>0?(i===0?r.show({type:g.Error,content:n.t(`find-replace.replace.all-failure`)}):r.show({type:g.Warning,content:n.t(`find-replace.replace.partial-success`,`${i}`,`${a}`)}),!1):(r.show({type:g.Success,content:n.t(`find-replace.replace.all-success`,`${i}`)}),!0)}},G={id:`ui.operation.open-find-dialog`,type:e.OPERATION,handler:e=>{let t=e.get(I);return t.revealed?t.focusFindInput():t.start(),!0}},K={id:`ui.operation.open-replace-dialog`,type:e.OPERATION,handler:e=>{let t=e.get(I);return t.revealed?t.replaceRevealed?t.focusFindInput():t.revealReplace():t.start(!0),!0}},q={type:e.OPERATION,id:`ui.operation.go-to-next-match`,handler:e=>(e.get(I).moveToNextMatch(),!0)},J={type:e.OPERATION,id:`ui.operation.go-to-previous-match`,handler:e=>(e.get(I).moveToPreviousMatch(),!0)},Le={type:e.OPERATION,id:`ui.operation.focus-selection`,handler:e=>(e.get(I).focusSelection(),!0)};function Re(e){let t=e.get(c);return{id:G.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:pe.BUTTON,hidden$:he(e,te.UNIVER_SHEET),disabled$:ve([t.subscribeContextValue$(r),t.subscribeContextValue$(i)]).pipe(xe(([e,t])=>e||!t))}}const ze={[me.ORGANIZATION]:{[G.id]:{order:2,menuItemFactory:Re}}};function Be(e){let{findCompleted:t,localeService:n,matchesCount:r,matchesPosition:i,initialFindString:a,findReplaceService:o,onChange:s,...c}=e,[l,u]=Oe(a),d=t&&r===0?n.t(`find-replace.dialog.no-result`):r===0?` `:void 0;function f(e){i===r&&e===1?o.moveToNextMatch():i===1&&e===r||e<i?o.moveToPreviousMatch():o.moveToNextMatch()}return A(`div`,{className:`univer-relative univer-flex univer-items-center univer-gap-2`,onDrag:e=>e.stopPropagation(),children:A(se,{"data-u-comp":`search-input`,autoFocus:!0,placeholder:n.t(`find-replace.dialog.find-placeholder`),value:l,onChange:e=>{u(e),s==null||s(e)},slot:A(ce,{loop:!0,text:d,value:i,total:r,onChange:f}),...c})})}function Ve(e,t){let n=E(()=>{var e;(e=document.querySelector(`.univer-find-input input`))==null||e.focus()},[]),r=E(()=>{let e=document.querySelectorAll(`[data-u-comp=find-replace-dialog] [data-u-comp=search-input]`);return Array.from(e).some(e=>e===document.activeElement)},[]);return Ee(t,()=>({focus:n,selectHasFocus:r})),D(()=>{let t=e.focusSignal$.subscribe(()=>n());return()=>t.unsubscribe()},[e,n]),{focus:n,selectHasFocus:r}}const He=Te(function(e,t){let n=S(f),r=S(I),i=S(a),{findCompleted:o,findString:s,matchesCount:c,matchesPosition:l}=C(r.state$,void 0,!0),u=E(()=>{i.executeCommand(K.id)},[i]),d=ge(e=>r.changeFindString(e),500);return Ve(r,t),j(k,{children:[A(Be,{findCompleted:o,matchesCount:c,matchesPosition:l,findReplaceService:r,localeService:n,initialFindString:s,onChange:d}),A(`div`,{className:`univer-mt-4 univer-text-center`,children:A(`a`,{className:`hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors`,onClick:u,children:n.t(`find-replace.dialog.advanced-finding`)})})]})}),Ue=Te(function(e,t){let n=S(I),r=S(f),i=S(a),o=S(de),s=C(n.currentMatch$,void 0,!0),c=C(n.replaceables$,void 0,!0),{matchesCount:l,matchesPosition:u,findString:d,inputtingFindString:p,replaceString:ee,caseSensitive:te,matchesTheWholeCell:ne,findDirection:re,findScope:m,findBy:ce,findCompleted:v}=C(n.state$,void 0,!0),le=p.length===0,y=l===0||!(s!=null&&s.replaceable),ue=c.length===0,fe=E(e=>n.changeInputtingFindString(e),[n]),b=E(e=>n.changeReplaceString(e),[n]),{focus:pe}=Ve(n,t),x=E(()=>{d===p?n.moveToNextMatch():(n.changeFindString(p),n.find())},[d,p,n]),me=E(()=>i.executeCommand(U.id),[i]),he=E(async()=>{await i.executeCommand(W.id),pe()},[i]),ge=E(e=>{n.changeFindDirection(e)},[n]),_e=E(e=>{n.changeFindScope(e)},[n]),w=E(e=>{n.changeFindBy(e)},[n]),T=Ge(r),ve=Ke(r),ye=qe(r);return D(()=>{v&&l===0&&o.show({content:r.t(`find-replace.dialog.no-match`),type:g.Warning,duration:5e3})},[v,l,o,r]),j(`div`,{children:[A(h,{label:r.t(`find-replace.dialog.find`),children:A(Be,{findCompleted:v,className:`univer-find-input`,matchesCount:l,matchesPosition:u,findReplaceService:n,localeService:r,initialFindString:p,onChange:fe})}),A(h,{label:r.t(`find-replace.dialog.replace`),children:A(se,{placeholder:r.t(`find-replace.dialog.replace-placeholder`),value:ee,onChange:e=>b(e)})}),A(h,{label:r.t(`find-replace.dialog.find-direction.title`),children:A(_,{value:re,options:ve,onChange:ge})}),A(oe,{children:j(k,{children:[A(h,{label:r.t(`find-replace.dialog.find-scope.title`),children:A(_,{value:m,options:T,onChange:_e})}),A(h,{label:r.t(`find-replace.dialog.find-by.title`),children:A(_,{value:ce,options:ye,onChange:w})})]})}),A(oe,{children:j(k,{children:[A(h,{children:A(ae,{checked:te,onChange:e=>{n.changeCaseSensitive(e)},children:r.t(`find-replace.dialog.case-sensitive`)})}),A(h,{children:A(ae,{checked:ne,onChange:e=>{n.changeMatchesTheWholeCell(e)},children:r.t(`find-replace.dialog.match-the-whole-cell`)})})]})}),j(`div`,{className:`univer-mt-6 univer-flex univer-justify-between`,children:[A(ie,{variant:`primary`,onClick:x,disabled:le,children:r.t(`find-replace.dialog.find`)}),j(`span`,{className:`univer-inline-flex univer-gap-2`,children:[A(ie,{disabled:y,onClick:me,children:r.t(`find-replace.dialog.replace`)}),A(ie,{disabled:ue,onClick:he,children:r.t(`find-replace.dialog.replace-all`)})]})]})]})});function We(){let e=S(I),t=S(y),n=S(c),r=C(e.state$,void 0,!0),i=De(null);D(()=>{let e;return i.current&&(e=t.registerContainerElement(i.current)),()=>e==null?void 0:e.dispose()},[t]);let a=De(null),o=E(e=>n.setContextValue(Ae,e),[n]),s=E(e=>n.setContextValue(ke,e),[n]);return D(()=>{var e;let t=be(document,`focusin`).subscribe(e=>{var t;e.target&&(t=i.current)!=null&&t.contains(e.target)?o(!0):o(!1),!a.current||!a.current.selectHasFocus()?s(!1):s(!0)});return(e=a.current)==null||e.focus(),o(!0),s(!0),()=>{t.unsubscribe(),o(!1)}},[o,s]),A(`div`,{ref:i,"data-u-comp":`find-replace-dialog`,children:r.replaceRevealed?A(Ue,{ref:a}):A(He,{ref:a})})}function Ge(e){return O(()=>[{label:e.t(`find-replace.dialog.find-scope.current-sheet`),value:B.SUBUNIT},{label:e.t(`find-replace.dialog.find-scope.workbook`),value:B.UNIT}],[e.getCurrentLocale()])}function Ke(e){return O(()=>[{label:e.t(`find-replace.dialog.find-direction.row`),value:R.ROW},{label:e.t(`find-replace.dialog.find-direction.column`),value:R.COLUMN}],[e.getCurrentLocale()])}function qe(e){return O(()=>[{label:e.t(`find-replace.dialog.find-by.value`),value:z.VALUE},{label:e.t(`find-replace.dialog.find-by.formula`),value:z.FORMULA}],[e.getCurrentLocale()])}function Y(e){return e.getContextValue(Ae)}function Je(e){return e.getContextValue(je)}function Ye(e){return e.getContextValue(ke)}const X=`7_find-replace-shortcuts`;function Z(e){return e.getContextValue(i)}function Xe(e){return!e.getContextValue(r)}const Ze={id:G.id,description:`find-replace.shortcut.open-find-dialog`,binding:b.F|x.CTRL_COMMAND,group:X,preconditions(e){return!Y(e)&&Z(e)&&Xe(e)}},Qe={id:G.id,description:`find-replace.shortcut.open-find-dialog`,binding:b.F|x.CTRL_COMMAND,mac:b.F|x.MAC_CTRL,preconditions(e){return!Y(e)&&Z(e)&&Xe(e)}},$e={id:K.id,description:`find-replace.shortcut.open-replace-dialog`,binding:b.H|x.CTRL_COMMAND,mac:b.H|x.MAC_CTRL,group:X,preconditions(e){return Z(e)&&Xe(e)&&(!Y(e)||!Je(e))}},et={id:q.id,description:`find-replace.shortcut.go-to-next-match`,binding:b.ENTER,group:X,priority:1e3,preconditions(e){return Ye(e)&&Y(e)}},tt={id:J.id,description:`find-replace.shortcut.go-to-previous-match`,binding:b.ENTER|x.SHIFT,group:X,priority:1e3,preconditions(e){return Ye(e)&&Y(e)}},nt={id:Le.id,description:`find-replace.shortcut.focus-selection`,binding:b.ESC,group:X,priority:1e3,preconditions(e){return Y(e)}},rt=`DESKTOP_FIND_REPLACE_DIALOG`;let Q=class extends ee{constructor(e,t,n,r,i,a,o,s,c){super(),this._univerInstanceService=e,this._menuManagerService=t,this._shortcutService=n,this._commandService=r,this._findReplaceService=i,this._dialogService=a,this._layoutService=o,this._localeService=s,this._componentManager=c,N(this,`_closingListenerDisposable`,void 0),this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var e;super.dispose(),(e=this._closingListenerDisposable)==null||e.dispose(),this._closingListenerDisposable=null}_initCommands(){[G,K,q,J,W,U,Le].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[$e,Ze,Qe,tt,et,nt].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){[[`FindReplaceDialog`,We],[`SearchIcon`,we]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this._menuManagerService.mergeMenu(ze),this._findReplaceService.stateUpdates$.pipe(Se(this.dispose$)).subscribe(e=>{e.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:rt,draggable:!0,width:350,title:{title:this._localeService.t(`find-replace.dialog.title`)},children:{label:`FindReplaceDialog`},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:it(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=m(this._univerInstanceService.focused$.pipe(Se(this.dispose$)).subscribe(e=>{(!e||!this._univerInstanceService.getUniverSheetInstance(e))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(rt),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};Q=F([P(0,l),P(1,ue),P(2,fe),P(3,a),P(4,I),P(5,le),P(6,y),P(7,u(f)),P(8,u(v))],Q);function it(){let{innerWidth:e}=window;return{x:e-350-20,y:64}}var at=`@univerjs/find-replace`,ot=`0.20.1`;const st=`find-replace.config`;Symbol(st);const ct={};let $=class extends p{constructor(e=ct,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=re({},ct,this._config);this._configService.setConfig(st,r)}onStarting(){[[Q],[I,{useClass:H}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(Q)}};N($,`pluginName`,`UNIVER_FIND_REPLACE_PLUGIN`),N($,`packageName`,at),N($,`version`,ot),$=F([P(1,u(d)),P(2,o)],$);export{z as FindBy,R as FindDirection,Pe as FindModel,Q as FindReplaceController,L as FindReplaceModel,Ie as FindReplaceState,B as FindScope,q as GoToNextMatchOperation,J as GoToPreviousMatchOperation,I as IFindReplaceService,G as OpenFindDialogOperation,K as OpenReplaceDialogOperation,W as ReplaceAllMatchesCommand,U as ReplaceCurrentMatchCommand,$ as UniverFindReplacePlugin,V as createInitFindReplaceState};