(()=>{"use strict";var e,t={6755(e,t,i){const r=window.wp.blocks,s=window.wp.i18n,l=window.wp.blockEditor,n=window.wp.components,a=window.wp.dom,o=window.wp.data,c=window.wp.element,d=window.wp.apiFetch;var u=i.n(d);function p(){return window._activityPubOptions||{}}const h=window.ReactJSXRuntime,v=JSON.parse('{"UU":"activitypub/extra-fields"}');(0,r.registerBlockType)(v.UU,{edit:function({attributes:e,setAttributes:t,context:i}){const{selectedUser:r,maxFields:d}=e,{postId:v,postType:b}=null!=i?i:{},[y,f]=(0,c.useState)([]),[x,g]=(0,c.useState)(!1),[w,m]=(0,c.useState)(null),_=(0,o.useSelect)(e=>{if(v&&b){const r=e("core");if(r){var t,i;const e=null!==(t=r.getEditedEntityRecord?.("postType",b,v))&&void 0!==t?t:null;if(e?.author)return e.author;const s=null!==(i=r.getEntityRecord?.("postType",b,v))&&void 0!==i?i:null;if(s?.author)return s.author}}const r=e("core/editor");return r&&r.getCurrentPostAttribute?r.getCurrentPostAttribute("author"):null},[v,b]),j="blog"===r?0:"inherit"===r?_||null:r,{namespace:k="activitypub/1.0",profileUrls:U={}}=p(),F="blog"===r?U.blog:U.user,C=(0,l.useBlockProps)({className:"activitypub-extra-fields-block-wrapper"}),O=function({withInherit:e=!1}){const{enabled:t,namespace:i}=p(),[r,l]=(0,c.useState)(!1),{fetchedUsers:n,isLoadingUsers:a}=(0,o.useSelect)(e=>{const{getUsers:i,getIsResolving:r}=e("core");return{fetchedUsers:t?.users?i({capabilities:"activitypub"}):null,isLoadingUsers:!!t?.users&&r("getUsers",[{capabilities:"activitypub"}])}},[t?.users]),d=(0,o.useSelect)(e=>n||a?null:e("core").getCurrentUser(),[n,a]);(0,c.useEffect)(()=>{n||a||!d||u()({path:`/${i}/actors/${d.id}`,method:"HEAD",headers:{Accept:"application/activity+json"},parse:!1}).then(()=>l(!0)).catch(()=>l(!1))},[n,a,d,i]);const h=(0,c.useMemo)(()=>n||(d&&r?[{id:d.id,name:d.name}]:[]),[n,d,r]);return(0,c.useMemo)(()=>{if(!h.length)return[];const i=[];return t?.blog&&n&&i.push({label:(0,s.__)("Blog","activitypub"),value:"blog"}),e&&t?.users&&n&&i.push({label:(0,s.__)("Dynamic User","activitypub"),value:"inherit"}),h.reduce((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e),i)},[h,t?.blog,t?.users,n,e])}({withInherit:!0});(0,c.useEffect)(()=>{null!==j?(g(!0),m(null),u()({path:`/${k}/actors/${j}`,headers:{Accept:"application/activity+json"}}).then(e=>{const t=(e.attachment||[]).filter(e=>"PropertyValue"===e.type);f(t),g(!1)}).catch(e=>{m(e.message),g(!1)})):f([])},[j,k]);const E=d>0?y.slice(0,d):y,S=(()=>{const t=e.className?.includes("is-style-cards");if(!t)return{};const i=e.style||{},r=e.backgroundColor,s=i.color?.background;return r?{backgroundColor:`var(--wp--preset--color--${r})`}:s?{backgroundColor:s}:{}})(),P=(0,h.jsx)(l.InspectorControls,{children:(0,h.jsxs)(n.PanelBody,{title:(0,s.__)("Settings","activitypub"),initialOpen:!0,children:[(0,h.jsx)(n.SelectControl,{label:(0,s.__)("User","activitypub"),value:r,options:O,onChange:e=>t({selectedUser:e})}),(0,h.jsx)(n.RangeControl,{label:(0,s.__)("Maximum Fields","activitypub"),value:d,onChange:e=>t({maxFields:e}),min:0,max:20,help:(0,s.__)("Limit the number of fields displayed. 0 = show all.","activitypub")})]})});return"inherit"!==r||_?x?(0,h.jsx)("div",{...C,children:(0,h.jsx)(n.Placeholder,{label:(0,s.__)("Fediverse Extra Fields","activitypub"),children:(0,h.jsx)(n.Spinner,{})})}):w?(0,h.jsx)("div",{...C,children:(0,h.jsx)(n.Placeholder,{label:(0,s.__)("Fediverse Extra Fields","activitypub"),children:(0,h.jsx)("p",{children:(0,s.sprintf)(/* translators: %s: Error message */ /* translators: %s: Error message */
(0,s.__)("Error loading extra fields: %s","activitypub"),w)})})}):0===E.length?(0,h.jsxs)(h.Fragment,{children:[P,(0,h.jsx)("div",{...C,children:(0,h.jsx)(n.Placeholder,{label:(0,s.__)("Fediverse Extra Fields","activitypub"),children:(0,h.jsxs)("p",{children:[(0,s.__)("No extra fields found.","activitypub")," ",F&&(0,h.jsx)(n.Button,{variant:"link",onClick:()=>{window.location.href=F},children:(0,s.__)("Add fields in your profile settings","activitypub")})]})})})]}):(0,h.jsxs)(h.Fragment,{children:[P,(0,h.jsx)("div",{...C,children:(0,h.jsx)("dl",{className:"activitypub-extra-fields",children:E.map(e=>(0,h.jsxs)("div",{className:"activitypub-extra-field",style:S,children:[(0,h.jsx)("dt",{children:e.name}),(0,h.jsx)("dd",{dangerouslySetInnerHTML:{__html:(0,a.safeHTML)(e.value)}})]},`${e.name}-${e.value}`))})})]}):(0,h.jsxs)(h.Fragment,{children:[P,(0,h.jsx)("div",{...C,children:(0,h.jsx)(n.Placeholder,{label:(0,s.__)("Fediverse Extra Fields","activitypub"),children:(0,h.jsx)("p",{children:(0,s.__)("This block will display extra fields based on the post author when published.","activitypub")})})})]})},save:()=>null})}},i={};function r(e){var s=i[e];if(void 0!==s)return s.exports;var l=i[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=(t,i,s,l)=>{if(!i){var n=1/0;for(d=0;d<e.length;d++){for(var[i,s,l]=e[d],a=!0,o=0;o<i.length;o++)(!1&l||n>=l)&&Object.keys(r.O).every(e=>r.O[e](i[o]))?i.splice(o--,1):(a=!1,l<n&&(n=l));if(a){e.splice(d--,1);var c=s();void 0!==c&&(t=c)}}return t}l=l||0;for(var d=e.length;d>0&&e[d-1][2]>l;d--)e[d]=e[d-1];e[d]=[i,s,l]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={914:0,678:0};r.O.j=t=>0===e[t];var t=(t,i)=>{var s,l,[n,a,o]=i,c=0;if(n.some(t=>0!==e[t])){for(s in a)r.o(a,s)&&(r.m[s]=a[s]);if(o)var d=o(r)}for(t&&t(i);c<n.length;c++)l=n[c],r.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return r.O(d)},i=globalThis.webpackChunkwordpress_activitypub=globalThis.webpackChunkwordpress_activitypub||[];i.forEach(t.bind(null,0)),i.push=t.bind(null,i.push.bind(i))})();var s=r.O(void 0,[678],()=>r(6755));s=r.O(s)})();