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