Loading
function(e,t,n){n.d(t,{Ay:()=>p,Ur:()=>m,mk:()=>h});var l=n(143236),i=n(721768),r=n(612394),s=n(820066),a=n(649079),o=n(778747),u=n(885386),c=n(38405),d=n(597184);let h=["gameMentionInput","timestampMentionInput"];function m(){return{query:null,selectedIndex:null,isVisible:!1,didInitialQuery:!1,hadInitialResults:!1,isInitialAfterError:!1}}class p extends l.EventEmitter{props;state;nextUpdateQueryChanged=!1;nextUpdateContextChanged=!1;updateTimeout;constructor(e){super(),this.props=e,this.state=m()}updateProps(e){let t=this.props.focused!==e.focused,n=this.props.channel.id!==e.channel.id||this.props.activeCommandOption!==e.activeCommandOption||this.props.activeInlineAutocompleteInput!==e.activeInlineAutocompleteInput,l=!this.state.didInitialQuery||this.props.currentWord!==e.currentWord||this.props.currentWordIsAtStart!==e.currentWordIsAtStart||this.props.textValue!==e.textValue||this.props.optionText!==e.optionText;if(this.props=e,n||l)this.updateResultsDebounced(l,n),this.state.didInitialQuery||(this.state={...this.state,didInitialQuery:!0});else if(t){let e=this.state.query;this.setState({isVisible:null!=e&&this.shouldShow(e.resultCount,e.isLoading,e.typeInfo)})}}setSelectedIndex(e){this.setState({selectedIndex:e})}onTabOrEnter(e){if(!this.state.isVisible)return!1;if(null==this.state.selectedIndex){let t=this.state.query?.typeInfo.focusMode;return!e&&(t===d.e.MANUAL||t===d.e.AUTO_WHEN_FILTERED)&&(this.setSelectedIndex(0),!0)}return this.selectResult(this.state.selectedIndex,e,!0)}onSpace(){if(!this.state.isVisible)return!1;let e=this.state.query;if(null==e)return!1;let t=e.typeInfo.getSpaceSelectIndex?.({results:e.results,queryText:e.queryText});return null!=t&&this.selectResult(t,!1)}onMoveSelection(e){if(!this.state.isVisible)return!1;if(e<0?this.props.navigator.focusPreviousItem():e>0&&this.props.navigator.focusNextItem(),null!=this.state.selectedIndex&&this.state.query?.type===d.DB.COMMANDS){let e=this.state.query.results.commands?.[this.state.selectedIndex];null!=e&&i.e0(this.props.channel.id,e.id)}return!0}onMaybeShowAutocomplete(){this.emit("update")}onHideAutocomplete(){null!=this.state.query&&this.setState({isVisible:!1})}onResultHover(e){this.props.navigator.setFocus(null),this.setSelectedIndex(null)}onResultClick(e){this.selectResult(e,!0)}clearQuery(){this.endGameSearchSessionIfLeaving(null),this.setState({query:null,isVisible:!1,selectedIndex:null,hadInitialResults:!1,isInitialAfterError:!1})}queryResults(){this.updateResultsDebounced()}unmount(){this.endGameSearchSessionIfLeaving(null)}isVisible(){return this.state.isVisible}updateResultsDebounced(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];null!=this.updateTimeout&&clearTimeout(this.updateTimeout),this.nextUpdateQueryChanged=this.nextUpdateQueryChanged||e,this.nextUpdateContextChanged=this.nextUpdateContextChanged||t,this.updateTimeout=setTimeout(()=>{let e=this.nextUpdateQueryChanged,t=this.nextUpdateContextChanged;this.nextUpdateQueryChanged=!1,this.nextUpdateContextChanged=!1,this.updateTimeout=void 0,this.updateResults(e,t).catch(e=>c.A.captureException(e))},0)}async updateResults(){let e,t,l=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],{findCommandOptionAutocompleteType:a,findMatchingAutocompleteType:o,getOptions:c}=await Promise.all([n.e("435751"),n.e("423798"),n.e("753149")]).then(n.bind(n,778572));if(null==this.props.editorRef.current)return;let m=c(this.props),p=this.props.editorRef.current.getSlateEditor();null!=p&&(t=null!=(e=s.VW.getSelectedParentOfType(p,h))?s.VW.getTextFromRange(p,s.VW.range(p,e[1])):null);let f=o({channel:this.props.channel,guild:this.props.guild,options:m,currentWord:this.props.currentWord,currentWordIsAtStart:this.props.currentWordIsAtStart,textValue:this.props.textValue,optionText:this.props.optionText,parentAutocompleteInputType:e?.[0].type,parentAutocompleteInputValue:t}),g=m.commands!==d.Ze.DISABLED?a(this.props.activeCommandOption,this.props.currentWord):null;if(null==f&&null!=g)f=g;else if(null==f||null!=g&&f.type!==g.type)return void this.clearQuery();let{type:x,typeInfo:E,query:S}=f,y=i||l&&(this.state.query?.queryText!==S||this.state.query?.typeInfo!==E),C=u.ML.getSetting();m.allowStickers=m.allowStickers?C:m.allowStickers;let A=u.eK.getSetting();m.allowSoundmoji=m.allowSoundmoji?A:m.allowSoundmoji;let{results:b,metadata:I}=E.queryResults(this.props.channel,this.props.guild,S,m,y),N=0;for(let e of Object.values(b))Array.isArray(e)&&(N+=e.length);l&&S.length>0&&S!==this.state.query?.queryText&&(0,r.AR)(x,m);let v=!0===b.isLoading,T=this.shouldShow(N,v,E),j=this.state.selectedIndex;!T||v?j=null:null!=j&&j>=N&&(j=N-1),T&&!this.state.isVisible&&(0,r.uA)(x,this.props.channel,I),this.endGameSearchSessionIfLeaving(x),this.setState({query:{type:x,typeInfo:E,queryText:S,results:b,resultCount:N,options:m,isLoading:v},isVisible:T,selectedIndex:j,hadInitialResults:!0,isInitialAfterError:!0!==this.state.hadInitialResults&&(e?.[0].error??!1)})}endGameSearchSessionIfLeaving(e){this.state.query?.type===d.DB.GAME&&e!==d.DB.GAME&&(0,a.$g)(o.K.CHAT_MENTION).end()}shouldShow(e,t,n){return this.props.focused&&null==this.props.expressionPickerView&&(e>0||t||n.showEmpty)}selectResult(e,t,n){if(!this.state.isVisible)return!1;let{type:l,typeInfo:i,results:s,resultCount:a,options:o}=this.state.query;if(e>=a)return!1;let u=i.onSelect?.({results:s,index:e,type:t?d.lg.SEND:d.lg.INSERT,options:o,channel:this.props.channel,guild:this.props.guild,tabOrEnter:n,queryText:this.state.query?.queryText});return null!=u&&(0,r.So)(l,u.type??null,this.props.channel,u.metadata),!0}setState(e){for(let t in e)if(e[t]!==this.state[t]){this.state={...this.state,...e},this.emit("change",this.state);return}}}}