import e from"@babel/runtime/helpers/defineProperty";import{useEffect as o,useCallback as n}from"react";import{debounce as r}from"lodash";import t from"prop-types";import{withStyles as s}from"@material-ui/core/styles";import{MentionsInput as i,Mention as a}from"react-mentions";import l from"@material-ui/core/colors/blue";import{handleFetchUsers as u}from"./utils/index.js";import{USER_MARKUP as c}from"./constants.js";import p from"./style.css.js";import{AvatarComponent as m}from"../Avatar/index.js";import"../../permissions/PermissionsContext.js";import{PERMISSIONS as f}from"../../permissions/constants/index.js";import"@babel/runtime/helpers/slicedToArray";import{withPermissionsHOC as g}from"../../permissions/withPermissionsHOC.js";import"@babel/runtime/helpers/asyncToGenerator";import"@babel/runtime/regenerator";import"../../clients/jsonApi/index.js";import"../../permissions/ProvidePermissions.js";import{jsx as d,jsxs as b}from"react/jsx-runtime";function y(e,o){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);o&&(r=r.filter((function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable}))),n.push.apply(n,r)}return n}function h(o){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?y(Object(r),!0).forEach((function(n){e(o,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(r)):y(Object(r)).forEach((function(e){Object.defineProperty(o,e,Object.getOwnPropertyDescriptor(r,e))}))}return o}var v={backgroundColor:l[100]},j={color:"#00bcd4"},_={suggestions:{item:{"&focused":{backgroundColor:"rgba(0, 0, 0, 0.08)"}}}},w=h(h({},_),{},{input:{color:"#fff",caretColor:"#fff",zIndex:1},highlighter:{color:"#fff"}}),O=h(h({},_),{},{input:{color:"#000"}}),P=function(e){var t=e.onChange,s=e.singleLine,l=e.suggestionsPortalHost,f=e.value,g=e.inputRef,y=e.classes,_=e.style,P=e.withLightTheme,C=e.placeholder,S=e.onMount,x=e.onKeyDown,R=e.onKeyUp,A=e.onFocus,D=e.onBlur,F=e.autoFocus,K=e.disabled,L=e.companyId,N=e.currentUser,T=e.isCompanySelectVisible,k=e.mentionProps,U=e.allowSuggestionsAboveCursor;o(S,[]);var q=n(r((function(e,o){var n=T&&N&&N.company_id!==L?[N.company_id,L]:null;u(e,o,n)}),400),[L]),H=Object.assign(P?O:w,_);return d(i,{value:f,onChange:function(e,o){t(o)},singleLine:s,allowSpaceInQuery:!0,classNames:p,placeholder:C,suggestionsPortalHost:l,inputRef:g,style:H,onKeyDown:x,onKeyUp:R,autoFocus:F,onFocus:A,onBlur:D,disabled:K,allowSuggestionsAboveCursor:U,children:d(a,h({markup:c,renderSuggestion:function(e){return function(e,o){return b("div",{className:p.mention__suggestion,children:[d(m,{alt:e.display,displayName:e.display,className:o.avatar,imgSrc:e.photo}),b("div",{className:p.mention__suggestion__info,children:[d("span",{"data-testid":"".concat("userMention","_name_").concat(e.display),className:p.mention__suggestion__info__name,children:e.display}),e.title&&d("span",{className:p.mention__suggestion__info__group,children:e.title})]})]})}(e,y)},trigger:"@",data:q,displayTransform:function(e,o){return"@".concat(o)},style:P?v:j,appendSpaceOnAdd:!0},k))})};P.propTypes={onChange:t.func,singleLine:t.bool,suggestionsPortalHost:t.shape({current:t.instanceOf(Element)}),value:t.string,inputRef:t.shape({}),classes:t.shape({avatar:t.string.isRequired}).isRequired,withLightTheme:t.bool,placeholder:t.string,style:t.shape({}),mentionProps:t.shape({}),onMount:t.func,onKeyDown:t.func,onKeyUp:t.func,onFocus:t.func,onBlur:t.func,autoFocus:t.bool,disabled:t.bool,currentUser:t.shape({company_id:t.number.isRequired}).isRequired,companyId:t.number,isCompanySelectVisible:t.bool.isRequired,allowSuggestionsAboveCursor:t.bool},P.defaultProps={onChange:function(){},singleLine:!1,suggestionsPortalHost:null,value:"",inputRef:null,withLightTheme:!1,placeholder:"Mention people using '@'",style:{suggestions:{list:{background:"#414141"},item:{color:"white",height:30,"&focused":{backgroundColor:"rgba(255, 255, 255, 0.08)"}}}},mentionProps:{},onMount:function(){},onKeyDown:function(){},onKeyUp:function(){},onFocus:function(){},onBlur:function(){},autoFocus:!0,disabled:!1,allowSuggestionsAboveCursor:!1,companyId:null};var C=g({isCompanySelectVisible:f.companySelectorView})(s({avatar:{height:45,width:45,border:"1.5px solid #fff"}})(P));export{C as default};
