!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:function(){return N}});var n={};e.r(n),e.d(n,{showFormats:function(){return v}});var o={};function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}e.r(o),e.d(o,{showFormats:function(){return y}});var a=window.wp.element,s=window.lodash,i=window.React,c=window.wp.richText,l=window.wp.components,u=window.wp.i18n,d=window.wp.data,m=window.nisje.format,w=window.nisje.icons,p=window.nisje.track,f=window.wp.dataControls,h=window.nisje.settings;const g={showFormats:(0,h.getOption)("showRichTextFormat",!1)};function*v(e){yield{type:"SHOW_FORMATS",show:e},yield(0,f.apiFetch)({path:"/wp/v2/users/me",method:"POST",data:{meta:{richtext_show_formats:e}}})}function y(e){return e.showFormats}(0,d.registerStore)("nisje/rich-text",{reducer:(e=g,t)=>{switch(t.type){case"SHOW_FORMATS":return{...e,showFormats:t.show};default:return e}},controls:f.controls,actions:n,selectors:o});var _=window.wp.apiFetch,b=e.n(_),E=window.nisje.url,F=window.nisje.avatar,x=e.n(F);function S(e){return{name:e?`nisje-group-users-${e}`:"nisje-users",triggerPrefix:"@",options(t){const n={context:"embed",type:"active",per_page:100};t&&(n.search=encodeURIComponent(t)),e&&(n.exclude_admins=!1);const o=e?`/buddypress/v1/groups/${e}/members`:"/buddypress/v1/members",r=(0,E.addQueryArgs)(o,n);return b()({path:r})},isDebounced:!0,getOptionKeywords:e=>[e.mention_name,e.name],getOptionLabel:e=>(0,a.createElement)(i.Fragment,{key:e.id},(0,a.createElement)(x(),{id:e.id,size:20}),(0,a.createElement)("span",{className:"nisje-richtext__autocomplete-user"},e.name)),getOptionCompletion(e){const t=`${(0,h.getOption)("base","/")}members/${e.id}/`;return(0,a.createElement)(i.Fragment,null,(0,a.createElement)("a",{className:"mention",href:t,"data-user-id":e.id},"@",e.name)," ")}}}const j=["bold","italic","link","strikethrough"];function O({children:e}){return(0,a.createElement)("div",{className:"nisje-richtext__toolbar"},e)}function T(){return(0,a.createElement)(O,null,j.map((e=>(0,a.createElement)(l.Slot,{name:`RichText.ToolbarControls.${e}`,key:e}))))}function C({allowedFormats:e}){const t=(0,d.useSelect)((e=>e("core/rich-text").getFormatTypes()),[]);return(0,a.createElement)(O,null,j.map((n=>{const o=`nisje/${n}`;if(!e.includes(o))return null;const r=(0,s.find)(t,(({name:e})=>e===o));return(0,s.has)(r,"inActive")?(0,a.createElement)(r.inActive,{key:n}):null})))}var R=window.nisje.components;const k=(0,window.nisje.styled.styled)(R.ExperimentalButton)`
	margin-left: auto;
	${({isSelected:e})=>e?"color: #555d66;":"color: rgba(0, 0, 0, 0.2);"}
`;var N=(0,i.forwardRef)((function({allowedFormats:e=[],autoFocus:t,className:n,group:o,hasBorder:f,onChange:h,placeholder:g,value:v,wrapperClassName:y},_){let b;const E=(0,i.useRef)(),F=(0,i.useRef)(),x=_||E,[j,O]=(0,i.useState)({start:void 0,end:void 0}),[R,N]=(0,i.useState)(!1),[P,$]=(0,i.useState)(!1),A=(0,d.useSelect)((e=>e("nisje/rich-text").showFormats())),{showFormats:D}=(0,d.useDispatch)("nisje/rich-text");function I(e){const t=document.querySelector(".components-popover");let n=!0;F.current&&(n=F.current.contains&&!F.current.contains(e.target)),n&&t&&(n=t.contains&&!t.contains(e.target)),n&&N(!1)}function M(){clearTimeout(b)}return(0,i.useEffect)((()=>(R&&document.addEventListener("click",I,!0),()=>{document.removeEventListener("click",I,!0)})),[R]),(0,i.useEffect)((()=>(t&&x.current&&x.current.focus(),()=>{M()})),[]),(0,a.createElement)("div",{className:(0,m.classnames)("rich-text-wrapper",y,{"is-selected":R,"has-border":f,"formats-is-visible":A}),ref:F,onFocus:M,onBlur:function(e){e.persist(),b=setTimeout((()=>{document.hasFocus()?N(!1):e.preventDefault()}),0)}},(0,a.createElement)(c.__experimentalRichText,{__unstableIsCaretWithinFormattedText:P,__unstableIsSelected:R,__unstableOnCreateUndoLevel:s.noop,__unstableOnEnterFormattedText:()=>$(!0),__unstableOnExitFormattedText:()=>$(!1),allowedFormats:e,onChange:h,onEnter:({value:e,onChange:t})=>{t((0,c.insert)(e,"\n"))},onPaste:({plainText:e,files:t,onChange:n,value:o})=>{t&&t.length||(0,s.isEmpty)(e)||n((0,c.insert)(o,e))},onSelectionChange:(e,t)=>O({start:e,end:t}),placeholder:g,ref:x,selectionEnd:j.end,selectionStart:j.start,unstableOnFocus:()=>N(!0),value:v},(({value:t,onChange:i,onFocus:c,isSelected:d,editableProps:f,editableTagName:h})=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)(l.Autocomplete,{completers:[S(o)],record:t,onChange:e=>{i(e),x.current.focus()},isSelected:d,contentRef:x},(({listBoxId:e,activeId:t,onKeyDown:o})=>(0,a.createElement)(h,r({},f,{className:(0,m.classnames)("nisje-richtext",n),"aria-autocomplete":e?"list":void 0,"aria-owns":e,"aria-activedescendant":t,onKeyDown:e=>{o(e),f.onKeyDown(e)}})))),!(0,s.isEmpty)(e)&&(0,a.createElement)("div",{className:"rich-text__actions"},A&&d&&(0,a.createElement)(T,null),A&&!d&&(0,a.createElement)(C,{allowedFormats:e}),(0,a.createElement)(k,{isSelected:d,icon:w.typography,onClick:()=>{(0,p.trackEvent)("view_richtext_formats","engagement",A?"off":"on"),D(!A),c()},label:A?(0,u.__)("Hide formatting"):(0,u.__)("Show formatting")}))))))}));(window.nisje=window.nisje||{}).richText=t}();