(()=>{"use strict";const e=window.wp.blocks,t=window.React,i=window.wp.blockEditor,a=window.wp.components,r=window.wp.compose,n=window.wp.data,s=window.wp.element,c=window.wp.i18n,o=window.bp.blockData,l=(0,r.compose)([(0,n.withSelect)(((e,t)=>{const{url:i}=t.attributes,{getEmbedPreview:a,isRequestingEmbedPreview:r}=e("core");return{preview:!!i&&a(i),fetching:!!i&&r(i)}}))])((({attributes:e,setAttributes:r,isSelected:n,preview:l,fetching:d})=>{const p=(0,i.useBlockProps)(),{url:m,caption:u}=e,b=(0,c.__)("BuddyPress Activity URL","buddypress"),[y,w]=(0,s.useState)(m),[v,E]=(0,s.useState)(!m),h=(0,t.createElement)(i.BlockControls,null,(0,t.createElement)(a.ToolbarGroup,null,(0,t.createElement)(a.ToolbarButton,{icon:"edit",title:(0,c.__)("Edit URL","buddypress"),onClick:e=>{e&&e.preventDefault(),E(!0)}})));return v?(0,t.createElement)("div",{...p},(0,t.createElement)(a.Placeholder,{icon:"buddicons-activity",label:b,className:"wp-block-embed",instructions:(0,c.__)("Paste the link to the activity content you want to display on your site.","buddypress")},(0,t.createElement)("form",{onSubmit:e=>{e&&e.preventDefault(),E(!1),r({url:y})}},(0,t.createElement)("input",{type:"url",value:y||"",className:"components-placeholder__input","aria-label":b,placeholder:(0,c.__)("Enter URL to embed here…","buddypress"),onChange:e=>w(e.target.value)}),(0,t.createElement)(a.Button,{variant:"primary",type:"submit"},(0,c.__)("Embed","buddypress"))),(0,t.createElement)("div",{className:"components-placeholder__learn-more"},(0,t.createElement)(a.ExternalLink,{href:(0,c.__)("https://codex.buddypress.org/activity-embeds/","buddypress")},(0,c.__)("Learn more about activity embeds","buddypress"))))):d?(0,t.createElement)("div",{className:"wp-block-embed is-loading"},(0,t.createElement)(a.Spinner,null),(0,t.createElement)("p",null,(0,c.__)("Embedding…","buddypress"))):l&&l.x_buddypress&&"activity"===l.x_buddypress?(0,t.createElement)("div",{...p},!v&&h,(0,t.createElement)("figure",{className:"wp-block-embed is-type-bp-activity"},(0,t.createElement)("div",{className:"wp-block-embed__wrapper"},(0,t.createElement)(a.Disabled,null,(0,t.createElement)(a.SandBox,{html:l&&l.html?l.html:"",scripts:[o.embedScriptURL]}))),(!i.RichText.isEmpty(u)||n)&&(0,t.createElement)(i.RichText,{tagName:"figcaption",placeholder:(0,c.__)("Write caption…","buddypress"),value:u,onChange:e=>r({caption:e}),inlineToolbar:!0}))):(0,t.createElement)("div",{...p},h,(0,t.createElement)(a.Placeholder,{icon:"buddicons-activity",label:b},(0,t.createElement)("p",{className:"components-placeholder__error"},(0,c.__)("The URL you provided is not a permalink to a public BuddyPress Activity. Please use another URL.","buddypress"))))})),d=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"bp/embed-activity","title":"Embed an activity","category":"embed","icon":"buddicons-activity","description":"Add a block that displays the activity content pulled from this or other community sites.","keywords":["BuddyPress","activity","community"],"textdomain":"buddypress","attributes":{"url":{"type":"string"},"caption":{"type":"string","source":"html","selector":"figcaption"}},"supports":{"align":true},"editorScript":"file:index.js","style":"file:index.css"}');(0,e.registerBlockType)(d,{icon:{background:"#fff",foreground:"#d84800",src:"buddicons-activity"},edit:l,save:({attributes:e})=>{const a=i.useBlockProps.save({className:"wp-block-embed is-type-bp-activity"}),{url:r,caption:n}=e;return r?(0,t.createElement)("figure",{...a},(0,t.createElement)("div",{className:"wp-block-embed__wrapper"},`\n${r}\n`),!i.RichText.isEmpty(n)&&(0,t.createElement)(i.RichText.Content,{tagName:"figcaption",value:n})):null}})})();