const e=require("../../_util/classNames.js"),t=require("../../_util/omit.js"),n=require("../../_util/props-util/initDefaultProps.js"),r=require("../../_util/KeyCode.js"),i=require("../../_util/BaseInput.js"),a=require("./MentionsContext.js"),o=require("./KeywordTrigger.js"),s=require("./util.js"),c=require("./mentionsProps.js");let l=require("vue");function u(){}var d=(0,l.defineComponent)({compatConfig:{MODE:3},name:`Mentions`,inheritAttrs:!1,props:n.default(c.vcMentionsProps,c.defaultProps),emits:[`change`,`select`,`search`,`focus`,`blur`,`pressenter`],setup(n,{emit:c,attrs:d,expose:f,slots:p}){let m=(0,l.ref)(null),h=(0,l.ref)(null),g=(0,l.ref)(),_=(0,l.reactive)({value:n.value||``,measuring:!1,measureLocation:0,measureText:null,measurePrefix:``,activeIndex:0,isFocus:!1});(0,l.watchEffect)(()=>{_.value=n.value});let v=e=>{c(`change`,e)},y=({target:{value:e}})=>{v(e)},b=(e,t,n)=>{Object.assign(_,{measuring:!0,measureText:e,measurePrefix:t,measureLocation:n,activeIndex:0})},x=e=>{Object.assign(_,{measuring:!1,measureLocation:0,measureText:null}),e?.()},S=e=>{let{which:t}=e;if(_.measuring){if(t===r.default.UP||t===r.default.DOWN){let n=M.value.length,i=t===r.default.UP?-1:1,a=(_.activeIndex+i+n)%n;_.activeIndex=a,e.preventDefault()}else if(t===r.default.ESC)x();else if(t===r.default.ENTER){if(e.preventDefault(),!M.value.length){x();return}let t=M.value[_.activeIndex];k(t)}}},C=e=>{let{key:t,which:i}=e,{measureText:a,measuring:o}=_,{prefix:l,validateSearch:u}=n,d=e.target;if(d.composing)return;let f=s.getBeforeSelectionText(d),{location:p,prefix:m}=s.getLastMeasureIndex(f,l);if(![r.default.ESC,r.default.UP,r.default.DOWN,r.default.ENTER].includes(i))if(p!==-1){let e=f.slice(p+m.length),r=u(e,n),i=!!j(e).length;r?(t===m||t===`Shift`||o||e!==a&&i)&&b(e,m,p):o&&x(),r&&c(`search`,e,m)}else o&&x()},w=e=>{_.measuring||c(`pressenter`,e)},T=e=>{D(e)},E=e=>{O(e)},D=e=>{clearTimeout(g.value);let{isFocus:t}=_;!t&&e&&c(`focus`,e),_.isFocus=!0},O=e=>{g.value=setTimeout(()=>{_.isFocus=!1,x(),c(`blur`,e)},100)},k=e=>{let{split:t}=n,{value:r=``}=e,{text:i,selectionLocation:a}=s.replaceWithMeasure(_.value,{measureLocation:_.measureLocation,targetText:r,prefix:_.measurePrefix,selectionStart:h.value.getSelectionStart(),split:t});v(i),x(()=>{s.setInputSelection(h.value.input,a)}),c(`select`,e,_.measurePrefix)},A=e=>{_.activeIndex=e},j=e=>{let t=e||_.measureText||``,{filterOption:r}=n;return n.options.filter(e=>!r||r(t,e))},M=(0,l.computed)(()=>j());return f({blur:()=>{h.value.blur()},focus:()=>{h.value.focus()}}),(0,l.provide)(a.default,{activeIndex:(0,l.toRef)(_,`activeIndex`),setActiveIndex:A,selectOption:k,onFocus:D,onBlur:O,loading:(0,l.toRef)(n,`loading`)}),(0,l.onUpdated)(()=>{(0,l.nextTick)(()=>{_.measuring&&(m.value.scrollTop=h.value.getScrollTop())})}),()=>{let{measureLocation:r,measurePrefix:a,measuring:s}=_,{prefixCls:c,placement:f,transitionName:g,getPopupContainer:v,direction:b,...x}=n,{class:D,style:O,...k}=d,A={...t.default(x,[`value`,`prefix`,`split`,`validateSearch`,`filterOption`,`options`,`loading`]),...k,onChange:u,onSelect:u,value:_.value,onInput:y,onBlur:E,onKeydown:S,onKeyup:C,onFocus:T,onPressenter:w};return(0,l.createVNode)(`div`,{class:e.default(c,D),style:O},[(0,l.createVNode)(i.default,{...A,ref:h,tag:`textarea`},null),s&&(0,l.createVNode)(`div`,{ref:m,class:`${c}-measure`},[_.value.slice(0,r),(0,l.createVNode)(o.default,{prefixCls:c,transitionName:g,dropdownClassName:n.dropdownClassName,placement:f,options:s?M.value:[],visible:!0,direction:b,getPopupContainer:v},{default:()=>[(0,l.createVNode)(`span`,null,[a])],notFoundContent:p.notFoundContent,option:p.option}),_.value.slice(r+a.length)])])}}});exports.default=d;