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