"use strict";(globalThis.webpackChunk_plex_client_qt=globalThis.webpackChunk_plex_client_qt||[]).push([["packages_app_screens_friends_FriendsOfFriendScreen_tsx"],{54251:(e,t,i)=>{i.r(t),i.d(t,{default:()=>N});var s=i(3493),n=i(36725),a=i(82357),r=i(87429),o=i(95794),h=i(11381),l=i(12367),c=i(99346),d=i(68482),u=i(80038),_=i(50709),m=i(58944),g=i(86384);const p={hasNextPage:!1,items:[],cursor:""};class f{constructor(e,t){this.isStale=!1,this.totalSize=0,this._items=[],this._needsToLoad=!0,this._hasNextPage=!1,this._name="",this._uuid="",this._fetchFriends=async e=>{var t;const{data:i}=await(0,u.JT)(u.Td,{first:15,uuid:this._uuid,after:e,sort:u.Du.DisplayName},"cache-and-network"),{pageInfo:s,nodes:n}=(null==i?void 0:i.user.friends)||{nodes:[]};return{hasNextPage:!(null==s||!s.hasNextPage),cursor:null!==(t=null==s?void 0:s.endCursor)&&void 0!==t?t:"",items:n.map((e=>({user:e})))}},this.refresh=()=>{if(!this.isStale&&!this._needsToLoad)return(0,_.Zq)();let e;this._hasNextPage=!0,this._cursor=void 0;return{promise:new Promise((async(t,i)=>{e=i;try{const e=Math.ceil(this._items.length/15)||1;for(let t=0;t<e;t++)if(this._hasNextPage||this._needsToLoad||this.isStale){const{items:e,cursor:i,hasNextPage:s}=await this._fetchFriends(this._cursor);this._items.splice(15*t,this._items.length,...e),this._hasNextPage=s,this._cursor=i}this.totalSize=this._items.length}catch(e){return void i(e)}finally{this._needsToLoad=!1,this.isStale=!1}t()})),cancel:()=>{e(new g.Z)}}},this.page=e=>{let t;if(e===m.T.Append&&this._hasNextPage){return{promise:new Promise((async(e,i)=>{t=i;const s={...p};try{const{items:e,cursor:t,hasNextPage:i}=await this._fetchFriends(this._cursor);s.items=e,s.hasNextPage=i,this._cursor=t,this._hasNextPage=i}catch(e){return void i(e)}this._items.push(...s.items),e(s)})),cancel:()=>{t(new g.Z)},startIndex:this._items.length,size:this._items.length}}if(e!==m.T.Append||this._hasNextPage)return(0,_.Zq)();{const e={...p};return{promise:Promise.resolve(e),cancel:()=>{t(new g.Z)},startIndex:0,size:0}}},this._name=e,this._uuid=t}getRefreshWindow(){return{index:0,size:this._items.length}}get items(){return this._items}get allowsPaging(){return this._hasNextPage}get title(){return this._name?(0,n.ZP)("{name}'s Friends",{name:this._name}):""}}var v=i(81190),y=function(e,t,i,s){var n,a=arguments.length,r=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var o=e.length-1;o>=0;o--)(n=e[o])&&(r=(a<3?n(r):a>3?n(t,i,r):n(t,i))||r);return a>3&&r&&Object.defineProperty(t,i,r),r},x=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};const{screenHeight:P,screenWidth:w}=c.default;class N extends h.Z{constructor(){super(...arguments),this._screenType=l.Z.Community}static _template(){return{y:100,BusyIndicator:{type:s.$j,mount:.5,x:w/2,y:(P-200)/2,zIndex:d.Z.busyStatus,visible:!0},Container:{type:s.sg,x:c.default.sidebarCollapsedWidth,gap:"m",Title:{type:s.ij,fontName:"heading2",colorName:"primaryForeground80"},FriendsItemList:{type:v.Z}}}}_getFocused(){return this._friendsItemList}async _init(){var e,t,i,s;const{name:a,uuid:o}=null!==(e=this.initialData)&&void 0!==e?e:{name:"",uuid:""};this._viewModel=new f(a,o),await Promise.all([this._viewModel.refresh().promise,this._profileManager.updatePeopleData()]),this._title.content=null!==(t=this.initialData)&&void 0!==t&&t.name?(0,n.ZP)("{name}'s Friends",{name:this.initialData.name}):"",this._container.patch({FriendsItemList:{type:v.Z,model:this._viewModel,parentUuid:null===(i=this.initialData)||void 0===i?void 0:i.uuid}}),this._spinner.visible=!1,(0,r.Z)({page:this.metricsPage,context:null===(s=this.initialData)||void 0===s?void 0:s.metricsContext})}get metricsPage(){return a.GJ.Friends}get _spinner(){var e;return null!==(e=this._spinnerElement)&&void 0!==e?e:this._spinnerElement=this.tag("BusyIndicator")}get _container(){return this.tag("Container")}get _title(){return this._container.tag("Title")}get _friendsItemList(){var e;return null!==(e=this._friendsListElement)&&void 0!==e?e:this._friendsListElement=this._container.tag("FriendsItemList")}}y([(0,o.Z)("profileManager"),x("design:type",Object)],N.prototype,"_profileManager",void 0)}}]);