(()=>{"use strict";var e={n:t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},d:(t,s)=>{for(var a in s)e.o(s,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:s[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r: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,{AutoCompleter:()=>i});const s=window.React,a=window.wp.apiFetch;var o=e.n(a);const r=window.wp.components,n=window.wp.element,l=window.wp.i18n,m=window.wp.url;class c extends n.Component{constructor(){super(...arguments),this.state={search:"",items:[],error:""},this.searchItemName=this.searchItemName.bind(this),this.selectItemName=this.selectItemName.bind(this)}searchItemName(e){const{search:t}=this.state,{component:s,objectQueryArgs:a}=this.props;this.setState({search:e}),e.length<t.length&&this.setState({items:[]});let r="/buddypress/v1/"+s,n={};e&&(n.search=encodeURIComponent(e)),a&&(n=Object.assign(n,a)),o()({path:(0,m.addQueryArgs)(r,n)}).then((e=>{this.setState({items:e})}),(e=>{this.setState({error:e.message})}))}selectItemName(e,t){const{onSelectItem:s}=this.props;return e.preventDefault(),this.setState({search:"",items:[],error:""}),s({itemID:t})}render(){const{search:e,items:t}=this.state;let a,{ariaLabel:o,placeholder:m,useAvatar:c,slugValue:i}=this.props;return o||(o=(0,l.__)("Item's name","buddypress")),m||(m=(0,l.__)("Enter Item's name here…","buddypress")),t.length&&(a=t.map((e=>(0,s.createElement)("button",{type:"button",key:"editor-autocompleters__item-item-"+e.id,role:"option","aria-selected":"true",className:"components-button components-autocomplete__result editor-autocompleters__user",onClick:t=>this.selectItemName(t,e.id)},c&&(0,s.createElement)("img",{key:"avatar",className:"editor-autocompleters__user-avatar",alt:"",src:e.avatar_urls.thumb.replaceAll("&#038;","&")}),(0,s.createElement)("span",{key:"name",className:"editor-autocompleters__user-name"},e.name),i&&null!==i(e)&&(0,s.createElement)("span",{key:"slug",className:"editor-autocompleters__user-slug"},i(e)))))),(0,s.createElement)(n.Fragment,null,(0,s.createElement)("input",{type:"text",value:e,className:"components-placeholder__input","aria-label":o,placeholder:m,onChange:e=>this.searchItemName(e.target.value)}),0!==t.length&&(0,s.createElement)(r.Popover,{className:"components-autocomplete__popover",focusOnMount:!1,position:"bottom left"},(0,s.createElement)("div",{className:"components-autocomplete__results"},a)))}}const i=c;(window.bp=window.bp||{}).blockComponents=t})();