import{getConfig as e,getContext as t,store as a}from"@wordpress/interactivity";const{apiFetch:r,url:n}=window.wp;!function(){const{actions:s}=a("activitypub/following",{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:s,page:o,perPage:i,order:c,endpoint:g}=a;a.isLoading=!0;try{const{namespace:t}=e(),p=n.addQueryArgs(`/${t}/actors/${s}/${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--,s.fetchItems())},nextPage(e){e.preventDefault();const a=t();a.page<a.pages&&(a.page++,s.fetchItems())}},callbacks:{setDefaultAvatar(t){t.target.src=e().defaultAvatarUrl}}})}();