(()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var s in a)e.o(a,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:a[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,a=window.React,s=window.wp.apiFetch;var r=e.n(s);const n=window.wp.blockEditor,l=window.wp.components,i=window.wp.element,o=window.wp.i18n,d=window.wp.url,m=window.bp.blockComponents,u=window.bp.blockData,c=[{label:(0,o.__)("None","buddypress"),value:"none"},{label:(0,o.__)("Thumb","buddypress"),value:"thumb"},{label:(0,o.__)("Full","buddypress"),value:"full"}],p=[{label:(0,o.__)("None","buddypress"),value:"none"},{label:(0,o.__)("Last time the user was active","buddypress"),value:"last_activity"},{label:(0,o.__)("Latest activity the user posted","buddypress"),value:"latest_update"}],b=window.lodash,y=e=>e&&e.mention_name?e.mention_name:null,_=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"bp/members","title":"Members","category":"widgets","icon":"groups","description":"BuddyPress Members.","keywords":["BuddyPress","members","community"],"textdomain":"buddypress","attributes":{"itemIDs":{"type":"array","items":{"type":"integer"},"default":[]},"avatarSize":{"type":"string","default":"full"},"displayMentionSlug":{"type":"boolean","default":true},"displayUserName":{"type":"boolean","default":true},"extraData":{"type":"string","default":"none"},"layoutPreference":{"type":"string","default":"list"},"columns":{"type":"number","default":2}},"supports":{"align":true},"editorScript":"file:index.js","style":"file:index.css"}');(0,t.registerBlockType)(_,{icon:{background:"#fff",foreground:"#d84800",src:"groups"},edit:({attributes:e,setAttributes:t,isSelected:s})=>{const _=(0,n.useBlockProps)(),g=(0,u.isActive)("members","avatar"),v=(0,u.isActive)("activity","mentions"),{itemIDs:h,avatarSize:w,displayMentionSlug:f,displayUserName:E,extraData:k,layoutPreference:C,columns:S}=e,N=0!==h.length,[x,P]=(0,i.useState)([]),D=[{icon:"text",title:(0,o.__)("List view","buddypress"),onClick:()=>t({layoutPreference:"list"}),isActive:"list"===C},{icon:"screenoptions",title:(0,o.__)("Grid view","buddypress"),onClick:()=>t({layoutPreference:"grid"}),isActive:"grid"===C}];let A,I="bp-block-members avatar-"+w,M=p;return"grid"===C&&(I+=" is-grid columns-"+S,M=p.filter((e=>"latest_update"!==e.value))),N&&h.length!==x.length&&r()({path:(0,d.addQueryArgs)("/buddypress/v1/members",{populate_extras:!0,include:h})}).then((e=>{P((0,b.sortBy)(e,[e=>h.indexOf(e.id)]))})),x.length&&(A=x.map((e=>{let r=!1,n="member-content";return"list"===C&&"latest_update"===k&&e.latest_update&&e.latest_update.rendered&&(r=!0,n="member-content has-activity"),(0,a.createElement)("div",{key:"bp-member-"+e.id,className:n},s&&(0,a.createElement)(l.Tooltip,{text:(0,o.__)("Remove member","buddypress")},(0,a.createElement)(l.Button,{className:"is-right",onClick:()=>{var a;(a=e.id)&&-1!==h.indexOf(a)&&(P((0,b.reject)(x,["id",a])),t({itemIDs:(0,b.remove)(h,(e=>e!==a))}))},label:(0,o.__)("Remove member","buddypress")},(0,a.createElement)(l.Dashicon,{icon:"no"}))),g&&"none"!==w&&(0,a.createElement)("div",{className:"item-header-avatar"},(0,a.createElement)("a",{href:e.link,target:"_blank"},(0,a.createElement)("img",{key:"avatar-"+e.id,className:"avatar",alt:(0,o.sprintf)((0,o.__)("Profile photo of %s","buddypress"),e.name),src:e.avatar_urls[w]}))),(0,a.createElement)("div",{className:"member-description"},r&&(0,a.createElement)("blockquote",{className:"wp-block-quote"},(0,a.createElement)("div",{dangerouslySetInnerHTML:{__html:e.latest_update.rendered}}),(0,a.createElement)("cite",null,E&&(0,a.createElement)("span",null,e.name)," ",v&&f&&(0,a.createElement)("a",{href:e.link,target:"_blank"},"(@",e.mention_name,")"))),!r&&E&&(0,a.createElement)("strong",null,(0,a.createElement)("a",{href:e.link,target:"_blank"},e.name)),!r&&v&&f&&(0,a.createElement)("span",{className:"user-nicename"},"@",e.mention_name),"last_activity"===k&&e.last_activity&&e.last_activity.date&&(0,a.createElement)("time",{dateTime:e.last_activity.date},(0,o.sprintf)(/* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */
(0,o.__)("Active %s","buddypress"),e.last_activity.timediff))))}))),(0,a.createElement)("div",{..._},(0,a.createElement)(n.InspectorControls,null,(0,a.createElement)(l.PanelBody,{title:(0,o.__)("Settings","buddypress"),initialOpen:!0},(0,a.createElement)(l.ToggleControl,{label:(0,o.__)("Display the user name","buddypress"),checked:!!E,onChange:()=>{t({displayUserName:!E})},help:E?(0,o.__)("Include the user's display name.","buddypress"):(0,o.__)("Toggle to include user's display name.","buddypress")}),v&&(0,a.createElement)(l.ToggleControl,{label:(0,o.__)("Display Mention slug","buddypress"),checked:!!f,onChange:()=>{t({displayMentionSlug:!f})},help:f?(0,o.__)("Include the user's mention name under their display name.","buddypress"):(0,o.__)("Toggle to display the user's mention name under their display name.","buddypress")}),g&&(0,a.createElement)(l.SelectControl,{label:(0,o.__)("Avatar size","buddypress"),value:w,options:c,help:(0,o.__)('Select "None" to disable the avatar.',"buddypress"),onChange:e=>{t({avatarSize:e})}}),(0,a.createElement)(l.SelectControl,{label:(0,o.__)("BuddyPress extra information","buddypress"),value:k,options:M,help:(0,o.__)('Select "None" to show no extra information.',"buddypress"),onChange:e=>{t({extraData:e})}}),"grid"===C&&(0,a.createElement)(l.RangeControl,{label:(0,o.__)("Columns","buddypress"),value:S,onChange:e=>t({columns:e}),min:2,max:4,required:!0}))),(0,a.createElement)(n.BlockControls,null,(0,a.createElement)(l.ToolbarGroup,{controls:D})),N&&(0,a.createElement)("div",{className:I},A),(s||0===h.length)&&(0,a.createElement)(l.Placeholder,{icon:N?"":"groups",label:N?"":(0,o.__)("BuddyPress Members","buddypress"),instructions:(0,o.__)("Start typing the name of the member you want to add to the members list.","buddypress"),className:0!==h.length?"is-appender":"is-large"},(0,a.createElement)(m.AutoCompleter,{component:"members",objectQueryArgs:{exclude:h},slugValue:y,ariaLabel:(0,o.__)("Member's username","buddypress"),placeholder:(0,o.__)("Enter Member's username here…","buddypress"),onSelectItem:({itemID:e})=>{e&&-1===h.indexOf(e)&&t({itemIDs:[...h,parseInt(e,10)]})},useAvatar:g})))}})})();