import{getConfig as e,getContext as t,store as a}from"@wordpress/interactivity";const{apiFetch:r,url:s}=window.wp;!function(){const{actions:n}=a("activitypub/followers",{state:{get paginationText(){const{page:e,pages:a}=t();return`${e} / ${a}`},get disablePreviousLink(){const{page:e}=t();return e<=1},get disableNextLink(){const{page:e,pages:a}=t();return e>=a}},actions:{async fetchItems(){const a=t(),{userId:n,page:o,perPage:i,order:c,endpoint:g}=a;a.isLoading=!0;try{const{namespace:t}=e(),p=s.addQueryArgs(`/${t}/actors/${n}/${g}`,{context:"full",per_page:i,order:c,page:o}),{orderedItems:l,totalItems:d}=await r({path:p});a.items=l.map(e=>({handle:"@"+e.webfinger,icon:e.icon,name:e.name||e.preferredUsername,url:e.url||e.id})),a.total=d,a.pages=Math.ceil(d/i)}catch(e){console.error(`Error fetching ${g}:`,e)}finally{a.isLoading=!1}},previousPage(e){e.preventDefault();const a=t();a.page>1&&(a.page--,n.fetchItems())},nextPage(e){e.preventDefault();const a=t();a.page<a.pages&&(a.page++,n.fetchItems())}},callbacks:{setDefaultAvatar(t){t.target.src=e().defaultAvatarUrl}}})}();