(()=>{"use strict";var e,t={17:(e,t,o)=>{const r=window.wp.blocks,n=window.wp.primitives;var i=o(848);const l=(0,i.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(n.Path,{d:"M15.5 9.5a1 1 0 100-2 1 1 0 000 2zm0 1.5a2.5 2.5 0 100-5 2.5 2.5 0 000 5zm-2.25 6v-2a2.75 2.75 0 00-2.75-2.75h-4A2.75 2.75 0 003.75 15v2h1.5v-2c0-.69.56-1.25 1.25-1.25h4c.69 0 1.25.56 1.25 1.25v2h1.5zm7-2v2h-1.5v-2c0-.69-.56-1.25-1.25-1.25H15v-1.5h2.5A2.75 2.75 0 0120.25 15zM9.5 8.5a1 1 0 11-2 0 1 1 0 012 0zm1.5 0a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z",fillRule:"evenodd"})}),a=window.wp.blockEditor,c=window.wp.i18n,s=window.wp.components,u=window.wp.data,p=window.wp.element,d=window._activityPubOptions?.enabled,v=window.wp.apiFetch;var f=o.n(v);function m(e){return`var(--wp--preset--color--${e})`}function y(e){if("string"!=typeof e)return null;if(e.match(/^#/))return e.substring(0,7);const[,,t]=e.split("|");return m(t)}function b(e,t,o=null,r=""){return o?`${e}${r} { ${t}: ${o}; }\n`:""}function _(e,t,o,r){return b(e,"background-color",t)+b(e,"color",o)+b(e,"background-color",r,":hover")+b(e,"background-color",r,":focus")}function h({selector:e,style:t,backgroundColor:o}){const r=function(e,t,o){const r=`${e} .components-button`,n=("string"==typeof(i=o)?m(i):i?.color?.background||null)||t?.color?.background;var i;return _(r,y(t?.elements?.link?.color?.text),n,y(t?.elements?.link?.[":hover"]?.color?.text))}(e,t,o);return(0,i.jsx)("style",{children:r})}var w=o(609);const g=(0,i.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(n.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M5 4.5h11a.5.5 0 0 1 .5.5v11a.5.5 0 0 1-.5.5H5a.5.5 0 0 1-.5-.5V5a.5.5 0 0 1 .5-.5ZM3 5a2 2 0 0 1 2-2h11a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5Zm17 3v10.75c0 .69-.56 1.25-1.25 1.25H6v1.5h12.75a2.75 2.75 0 0 0 2.75-2.75V8H20Z"})}),x=(0,i.jsx)(n.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,i.jsx)(n.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})}),j=(0,p.forwardRef)((function({icon:e,size:t=24,...o},r){return(0,p.cloneElement)(e,{width:t,height:t,...o,ref:r})})),k=window.wp.compose,E="fediverse-remote-user";function S(e){try{return new URL(e),!0}catch(e){return!1}}function O({actionText:e,copyDescription:t,handle:o,resourceUrl:r,myProfile:n=!1,rememberProfile:i=!1}){const a=(0,c.__)("Loading...","activitypub"),u=(0,c.__)("Opening...","activitypub"),d=(0,c.__)("Error","activitypub"),v=(0,c.__)("Invalid","activitypub"),m=n||(0,c.__)("My Profile","activitypub"),[y,b]=(0,p.useState)(e),[_,h]=(0,p.useState)(g),O=(0,k.useCopyToClipboard)(o,(()=>{h(x),setTimeout((()=>h(g)),1e3)})),[C,N]=(0,p.useState)(""),[R,U]=(0,p.useState)(!0),{setRemoteUser:P}=function(){const[e,t]=(0,p.useState)(function(){const e=localStorage.getItem(E);return e?JSON.parse(e):{}}()),o=(0,p.useCallback)((e=>{!function(e){localStorage.setItem(E,JSON.stringify(e))}(e),t(e)}),[]),r=(0,p.useCallback)((()=>{localStorage.removeItem(E),t({})}),[]);return{template:e?.template||!1,profileURL:e?.profileURL||!1,setRemoteUser:o,deleteRemoteUser:r}}(),I=(0,p.useCallback)((()=>{let t;if(!S(C)&&!function(e){const t=e.replace(/^@/,"").split("@");return 2===t.length&&S(`https://${t[1]}`)}(C))return b(v),t=setTimeout((()=>b(e)),2e3),()=>clearTimeout(t);const o=r+C;b(a),f()({path:o}).then((({url:t,template:o})=>{R&&P({profileURL:C,template:o}),b(u),setTimeout((()=>{window.open(t,"_blank"),b(e)}),200)})).catch((()=>{b(d),setTimeout((()=>b(e)),2e3)}))}),[C]);return(0,w.createElement)("div",{className:"activitypub__dialog"},(0,w.createElement)("div",{className:"activitypub-dialog__section"},(0,w.createElement)("h4",null,m),(0,w.createElement)("div",{className:"activitypub-dialog__description"},t),(0,w.createElement)("div",{className:"activitypub-dialog__button-group"},(0,w.createElement)("input",{type:"text",value:o,readOnly:!0}),(0,w.createElement)(s.Button,{ref:O},(0,w.createElement)(j,{icon:_}),(0,c.__)("Copy","activitypub")))),(0,w.createElement)("div",{className:"activitypub-dialog__section"},(0,w.createElement)("h4",null,(0,c.__)("Your Profile","activitypub")),(0,w.createElement)("div",{className:"activitypub-dialog__description"},(0,p.createInterpolateElement)((0,c.__)("Or, if you know your own profile, we can start things that way! (eg yourusername@example.com)","activitypub"),{code:(0,w.createElement)("code",null)})),(0,w.createElement)("div",{className:"activitypub-dialog__button-group"},(0,w.createElement)("input",{type:"text",value:C,onKeyDown:e=>{"Enter"===e?.code&&I()},onChange:e=>N(e.target.value)}),(0,w.createElement)(s.Button,{onClick:I},(0,w.createElement)(j,{icon:l}),y)),i&&(0,w.createElement)("div",{className:"activitypub-dialog__remember"},(0,w.createElement)(s.CheckboxControl,{checked:R,label:(0,c.__)("Remember me for easier comments","activitypub"),onChange:()=>{U(!R)}}))))}const{namespace:C}=window._activityPubOptions,N={avatar:"",webfinger:"@well@hello.dolly",name:(0,c.__)("Hello Dolly Fan Account","activitypub"),url:"#"};function R(e){if(!e)return N;const t={...N,...e};return t.avatar=t?.icon?.url,t}function U({profile:e,popupStyles:t,userId:o}){const{avatar:r,name:n,webfinger:l}=e;return(0,i.jsxs)("div",{className:"activitypub-profile",children:[(0,i.jsx)("img",{className:"activitypub-profile__avatar",src:r,alt:n}),(0,i.jsxs)("div",{className:"activitypub-profile__content",children:[(0,i.jsx)("div",{className:"activitypub-profile__name",children:n}),(0,i.jsx)("div",{className:"activitypub-profile__handle",title:l,children:l})]}),(0,i.jsx)(P,{profile:e,popupStyles:t,userId:o})]})}function P({profile:e,popupStyles:t,userId:o}){const[r,n]=(0,p.useState)(!1),l=(0,c.sprintf)((0,c.__)("Follow %s","activitypub"),e?.name);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.Button,{className:"activitypub-profile__follow",onClick:()=>n(!0),children:(0,c.__)("Follow","activitypub")}),r&&(0,i.jsxs)(s.Modal,{className:"activitypub-profile__confirm activitypub__modal",onRequestClose:()=>n(!1),title:l,children:[(0,i.jsx)(I,{profile:e,userId:o}),(0,i.jsx)("style",{children:t})]})]})}function I({profile:e,userId:t}){const{webfinger:o}=e,r=(0,c.__)("Follow","activitypub"),n=`/${C}/actors/${t}/remote-follow?resource=`,l=(0,c.__)("Copy and paste my profile into the search field of your favorite fediverse app or server.","activitypub");return(0,i.jsx)(O,{actionText:r,copyDescription:l,handle:o,resourceUrl:n})}function $({selectedUser:e,style:t,backgroundColor:o,id:r,useId:n=!1,profileData:l=!1}){const[a,c]=(0,p.useState)(R()),s="site"===e?0:e,u=function(e){return _(".apfmd__button-group .components-button",y(e?.elements?.link?.color?.text)||"#111","#fff",y(e?.elements?.link?.[":hover"]?.color?.text)||"#333")}(t),d=n?{id:r}:{};function v(e){c(R(e))}return(0,p.useEffect)((()=>{if(l)return v(l);(function(e){const t={headers:{Accept:"application/activity+json"},path:`/${C}/actors/${e}`};return f()(t)})(s).then(v)}),[s,l]),(0,i.jsxs)("div",{...d,children:[(0,i.jsx)(h,{selector:`#${r}`,style:t,backgroundColor:o}),(0,i.jsx)(U,{profile:a,userId:s,popupStyles:u})]})}(0,r.registerBlockType)("activitypub/follow-me",{edit:function({attributes:e,setAttributes:t}){const o=(0,a.useBlockProps)({className:"activitypub-follow-me-block-wrapper"}),r=function(){const e=d?.users?(0,u.useSelect)((e=>e("core").getUsers({who:"authors"}))):[];return(0,p.useMemo)((()=>{if(!e)return[];const t=d?.site?[{label:(0,c.__)("Whole Site","activitypub"),value:"site"}]:[];return e.reduce(((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e)),t)}),[e])}(),{selectedUser:n}=e;return(0,p.useEffect)((()=>{r.length&&(r.find((({value:e})=>e===n))||t({selectedUser:r[0].value}))}),[n,r]),(0,i.jsxs)("div",{...o,children:[r.length>1&&(0,i.jsx)(a.InspectorControls,{children:(0,i.jsx)(s.PanelBody,{title:(0,c.__)("Followers Options","activitypub"),children:(0,i.jsx)(s.SelectControl,{label:(0,c.__)("Select User","activitypub"),value:e.selectedUser,options:r,onChange:e=>t({selectedUser:e})})})},"setting"),(0,i.jsx)($,{...e,id:o.id})]})},save:()=>null,icon:l})},20:(e,t,o)=>{var r=o(609),n=Symbol.for("react.element"),i=Symbol.for("react.fragment"),l=Object.prototype.hasOwnProperty,a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,o){var r,i={},s=null,u=null;for(r in void 0!==o&&(s=""+o),void 0!==t.key&&(s=""+t.key),void 0!==t.ref&&(u=t.ref),t)l.call(t,r)&&!c.hasOwnProperty(r)&&(i[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===i[r]&&(i[r]=t[r]);return{$$typeof:n,type:e,key:s,ref:u,props:i,_owner:a.current}}t.Fragment=i,t.jsx=s,t.jsxs=s},848:(e,t,o)=>{e.exports=o(20)},609:e=>{e.exports=window.React}},o={};function r(e){var n=o[e];if(void 0!==n)return n.exports;var i=o[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.m=t,e=[],r.O=(t,o,n,i)=>{if(!o){var l=1/0;for(u=0;u=i)&&Object.keys(r.O).every((e=>r.O[e](o[c])))?o.splice(c--,1):(a=!1,i0&&e[u-1][2]>i;u--)e[u]=e[u-1];e[u]=[o,n,i]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={338:0,301:0};r.O.j=t=>0===e[t];var t=(t,o)=>{var n,i,[l,a,c]=o,s=0;if(l.some((t=>0!==e[t]))){for(n in a)r.o(a,n)&&(r.m[n]=a[n]);if(c)var u=c(r)}for(t&&t(o);sr(17)));n=r.O(n)})();