(()=>{"use strict";var e={868(e,t,n){const r=window.wp.blocks,i=window.wp.serverSideRender;var s=n.n(i);const a=window.wp.components,o=window.wp.blockEditor,l=window.wp.i18n,c=window.wp.element,u=window.wp.apiFetch;var p=n.n(u);const d=window.wp.data;const b=window.ReactJSXRuntime,v=(new Date).getFullYear();function h(){const e=[];for(let t=v;t>=v-5;t--)e.push({label:String(t),value:String(t)});return e}const g=JSON.parse('{"UU":"activitypub/stats"}');(0,r.registerBlockType)(g.UU,{edit:function({attributes:e,setAttributes:t}){const{selectedUser:n,year:r}=e,i=(0,o.useBlockProps)(),u=function({withInherit:e=!1}){const{enabled:t,namespace:n}=window._activityPubOptions||{},[r,i]=(0,c.useState)(!1),{fetchedUsers:s,isLoadingUsers:a}=(0,d.useSelect)(e=>{const{getUsers:n,getIsResolving:r}=e("core");return{fetchedUsers:t?.users?n({capabilities:"activitypub"}):null,isLoadingUsers:!!t?.users&&r("getUsers",[{capabilities:"activitypub"}])}},[t?.users]),o=(0,d.useSelect)(e=>s||a?null:e("core").getCurrentUser(),[s,a]);(0,c.useEffect)(()=>{!s&&!a&&o&&n&&p()({path:`/${n}/actors/${o.id}`,method:"HEAD",headers:{Accept:"application/activity+json"},parse:!1}).then(()=>i(!0)).catch(()=>i(!1))},[s,a,o,n]);const u=(0,c.useMemo)(()=>s||(o&&r?[{id:o.id,name:o.name}]:[]),[s,o,r]);return(0,c.useMemo)(()=>{if(!u.length)return[];const n=[];return t?.blog&&s&&n.push({label:(0,l.__)("Blog","activitypub"),value:"blog"}),e&&t?.users&&s&&n.push({label:(0,l.__)("Dynamic User","activitypub"),value:"inherit"}),u.reduce((e,t)=>(e.push({label:t.name,value:`${t.id}`}),e),n)},[u,t?.blog,t?.users,s,e])}({}),[g,y]=(0,c.useState)(!1);(0,c.useEffect)(()=>{!n&&u.length&&t({selectedUser:u[0].value})},[u]);const f=r||v-1,[w,_]=(0,c.useState)(""),m=(0,c.useCallback)(()=>{if(!n)return;const e=function(e,t){const n=window._activityPubOptions?.statsImageUrlEndpoint||"";if(!n)return"";const r=e&&"blog"!==e?e:0;return n.replace("{user_id}",r).replace("{year}",t)}(n,f);e&&p()({url:e}).then(e=>_(e.url||"")).catch(()=>_(""))},[n,f]);return(0,c.useEffect)(()=>{m()},[m]),(0,b.jsxs)("div",{...i,children:[(0,b.jsxs)(o.InspectorControls,{children:[(0,b.jsxs)(a.PanelBody,{title:(0,l.__)("Settings","activitypub"),children:[u.length>1&&(0,b.jsx)(a.SelectControl,{label:(0,l.__)("Select User","activitypub"),value:n,options:u,onChange:e=>t({selectedUser:e})}),(0,b.jsx)(a.SelectControl,{label:(0,l.__)("Year","activitypub"),value:String(f),options:h(),onChange:e=>t({year:parseInt(e,10)})})]}),w&&(0,b.jsxs)(a.PanelBody,{title:(0,l.__)("Share Image","activitypub"),initialOpen:!1,children:[(0,b.jsx)("p",{className:"description",children:(0,l.__)("Use this URL to share your stats as an image on social media.","activitypub")}),(0,b.jsx)(a.TextControl,{label:(0,l.__)("Share image URL","activitypub"),hideLabelFromVision:!0,__nextHasNoMarginBottom:!0,value:w,readOnly:!0,onClick:e=>e.target.select()}),(0,b.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[(0,b.jsx)(a.Button,{variant:"secondary",onClick:()=>{navigator.clipboard.writeText(w).then(()=>{y(!0),setTimeout(()=>y(!1),2e3)})},children:g?(0,l.__)("Copied!","activitypub"):(0,l.__)("Copy URL","activitypub")}),(0,b.jsx)(a.ExternalLink,{href:w,rel:"external noreferrer noopener",children:(0,l.__)("Preview","activitypub")})]})]})]}),(0,b.jsx)(a.Disabled,{children:(0,b.jsx)(s(),{block:"activitypub/stats",attributes:{...e,year:f}})})]})}})}};const t={};function n(r){const i=t[r];if(void 0!==i)return i.exports;const s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.m=e,(()=>{const e=[];n.O=(t,r,i,s)=>{if(r){s=s||0;for(var a=e.length;a>0&&e[a-1][2]>s;a--)e[a]=e[a-1];return void(e[a]=[r,i,s])}let o=1/0;for(a=0;a=s)&&Object.keys(n.O).every(e=>n.O[e](r[l]))?r.splice(l--,1):(c=!1,s{const t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{if(Array.isArray(t))for(var r=0;rObject.hasOwn(e,t),(()=>{const e={85:0,721:0};n.O.j=t=>0===e[t];const t=(t,r)=>{let[i,s,a]=r;var o,l,c=0;if(i.some(t=>0!==e[t])){for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(a)var u=a(n)}for(t&&t(r);cn(868));r=n.O(r)})();