(()=>{"use strict";var e={755(e,t,i){const r=window.wp.blocks,s=window.wp.i18n,n=window.wp.blockEditor,l=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,b=JSON.parse('{"UU":"activitypub/extra-fields"}');(0,r.registerBlockType)(b.UU,{edit:function({attributes:e,setAttributes:t,context:i}){const{selectedUser:r,maxFields:d}=e,{postId:b,postType:v}=i??{},[f,y]=(0,c.useState)([]),[x,g]=(0,c.useState)(!1),[m,w]=(0,c.useState)(null),_=(0,o.useSelect)(e=>{if(b&&v){const t=e("core");if(t){const e=t.getEditedEntityRecord?.("postType",v,b)??null;if(e?.author)return e.author;const i=t.getEntityRecord?.("postType",v,b)??null;if(i?.author)return i.author}}const t=e("core/editor");return t&&t.getCurrentPostAttribute?t.getCurrentPostAttribute("author"):null},[b,v]),j="blog"===r?0:"inherit"===r?_||null:r,{namespace:O="activitypub/1.0",profileUrls:U={}}=p(),k="blog"===r?U.blog:U.user,F=(0,n.useBlockProps)({className:"activitypub-extra-fields-block-wrapper"}),C=function({withInherit:e=!1}){const{enabled:t,namespace:i}=p(),[r,n]=(0,c.useState)(!1),{fetchedUsers:l,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=>l||a?null:e("core").getCurrentUser(),[l,a]);(0,c.useEffect)(()=>{!l&&!a&&d&&i&&u()({path:`/${i}/actors/${d.id}`,method:"HEAD",headers:{Accept:"application/activity+json"},parse:!1}).then(()=>n(!0)).catch(()=>n(!1))},[l,a,d,i]);const h=(0,c.useMemo)(()=>l||(d&&r?[{id:d.id,name:d.name}]:[]),[l,d,r]);return(0,c.useMemo)(()=>{if(!h.length)return[];const i=[];return t?.blog&&l&&i.push({label:(0,s.__)("Blog","activitypub"),value:"blog"}),e&&t?.users&&l&&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,l,e])}({withInherit:!0});(0,c.useEffect)(()=>{null!==j?(g(!0),w(null),u()({path:`/${O}/actors/${j}`,headers:{Accept:"application/activity+json"}}).then(e=>{const t=(e.attachment||[]).filter(e=>"PropertyValue"===e.type);y(t),g(!1)}).catch(e=>{w(e.message),g(!1)})):y([])},[j,O]);const E=d>0?f.slice(0,d):f,P=(()=>{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}:{}})(),S=(0,h.jsx)(n.InspectorControls,{children:(0,h.jsxs)(l.PanelBody,{title:(0,s.__)("Settings","activitypub"),initialOpen:!0,children:[(0,h.jsx)(l.SelectControl,{label:(0,s.__)("User","activitypub"),value:r,options:C,onChange:e=>t({selectedUser:e})}),(0,h.jsx)(l.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",{...F,children:(0,h.jsx)(l.Placeholder,{label:(0,s.__)("Fediverse Extra Fields","activitypub"),children:(0,h.jsx)(l.Spinner,{})})}):m?(0,h.jsx)("div",{...F,children:(0,h.jsx)(l.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"),m)})})}):0===E.length?(0,h.jsxs)(h.Fragment,{children:[S,(0,h.jsx)("div",{...F,children:(0,h.jsx)(l.Placeholder,{label:(0,s.__)("Fediverse Extra Fields","activitypub"),children:(0,h.jsxs)("p",{children:[(0,s.__)("No extra fields found.","activitypub")," ",k&&(0,h.jsx)(l.Button,{variant:"link",onClick:()=>{window.location.href=k},children:(0,s.__)("Add fields in your profile settings","activitypub")})]})})})]}):(0,h.jsxs)(h.Fragment,{children:[S,(0,h.jsx)("div",{...F,children:(0,h.jsx)("dl",{className:"activitypub-extra-fields",children:E.map(e=>(0,h.jsxs)("div",{className:"activitypub-extra-field",style:P,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:[S,(0,h.jsx)("div",{...F,children:(0,h.jsx)(l.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})}};const t={};function i(r){const s=t[r];if(void 0!==s)return s.exports;const n=t[r]={exports:{}};return e[r](n,n.exports,i),n.exports}i.m=e,(()=>{const e=[];i.O=(t,r,s,n)=>{if(r){n=n||0;for(var l=e.length;l>0&&e[l-1][2]>n;l--)e[l]=e[l-1];return void(e[l]=[r,s,n])}let a=1/0;for(l=0;l=n)&&Object.keys(i.O).every(e=>i.O[e](r[o]))?r.splice(o--,1):(c=!1,n{const t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{if(Array.isArray(t))for(var r=0;rObject.hasOwn(e,t),(()=>{const e={914:0,678:0};i.O.j=t=>0===e[t];const t=(t,r)=>{let[s,n,l]=r;var a,o,c=0;if(s.some(t=>0!==e[t])){for(a in n)i.o(n,a)&&(i.m[a]=n[a]);if(l)var d=l(i)}for(t&&t(r);ci(755));r=i.O(r)})();