import{aI as l,fM as T,b2 as S,bc as R,fx as W,L as w,ao as c}from"./app-k0jcl5PQ.js";import{I as k}from"./DXJ2-V8v.chunk.js";import{W as A,a as j}from"./DIZMv7tu.chunk.js";import{h as b}from"./DIAJ896Y.chunk.js";import{u as M}from"./CnmbO5oy.chunk.js";function P(e){const s=l.useMemo(()=>new T,[]);l.useEffect(()=>{!e||!e.length||e.forEach(i=>s.useSync(i))},[]);function m(i){s&&s.useSync(i)}function g(i){if(s)return s.goSync(i)}return{push:m,execute:g}}const N="shared.useInfiniteWidgetFetch",V=w.encloseNamespace(N);function v(e){const s=S(),m=R(),{ref:g,inView:i}=W(),x=P(e.resultsTransformers??[]),F=P(e.widgetItemTransformers??[]);function d(n){return s(e.getRequest(n))}function L(n,r){if(n===1)return b(r);m.error(V("error"))}function f(n){return[n]}const a=M(i&&e.getRequest,i&&d,L,f,e.infiniteFetch&&e.getCursor);function h(n){var y;if(!n||!n.length)return;const r=x.execute(n);return(y=e.widgetItemTransformers)!=null&&y.length?r.map(E=>F.execute(E)):r}const t=h(a.items);l.useEffect(()=>{var n;!a.hasFirstPageCompleted||!t||!((n=e.onLoadWidgetsTriggers)!=null&&n.length)||!t.length||e.onLoadWidgetsTriggers.forEach(r=>r(t))},[a.hasFirstPageCompleted,t]),l.useEffect(()=>{var n,r,u;if(a.hasFirstPageCompleted){if(!t){(n=e.setIsEmpty)==null||n.call(e,!0);return}if(Array.isArray(t)&&!t.length){(r=e.setIsEmpty)==null||r.call(e,!0);return}e.isEmptyPredicate&&((u=e.setIsEmpty)==null||u.call(e,e.isEmptyPredicate(t)))}},[a.hasFirstPageCompleted,e.isEmptyPredicate]);const I=!(t!=null&&t.length),C=!a.hasFirstPageCompleted,o=e.infiniteFetch&&(a.hasMore||a.isFetching);return{widgets:t,isEmpty:I,showLoading:C,showInfiniteScrollFooter:o,isFetching:a.isFetching,nextCursor:a.nextCursor,fetchNext:d,partialLoadingRef:g}}function U(e){var h;const{isEmpty:s,widgets:m,partialLoadingRef:g,showLoading:i,fetchNext:x,isFetching:F,nextCursor:d,showInfiniteScrollFooter:L}=v({getRequest:e.getRequest,getCursor:e.getCursor,setIsEmpty:e.setIsEmpty,isEmptyPredicate:e.isEmptyPredicate,item:e.item,infiniteFetch:e.infiniteFetch,resultsTransformers:e.resultsTransformers,onLoadWidgetsTriggers:e.onLoadWidgetsTriggers,widgetItemTransformers:e.widgetItemTransformers}),f=A[e.item.templateId],a=f.partialLoading;return!f||!i&&s?c.jsx(c.Fragment,{}):i?c.jsx("div",{ref:g,className:"py-2",children:c.jsx(a,{name:e.item.name,description:(h=e.item)==null?void 0:h.description,predicate:e==null?void 0:e.getPartialLoadingPredicate})}):c.jsx(c.Fragment,{children:m.map((t,I)=>{var o,n,r,u;const C=I===m.length-1;return c.jsxs(l.Fragment,{children:[c.jsx(j,{id:t.index.toString(),widgetIndex:e.item.index,dashboardTarget:e.dashboardTarget,appLinks:e.appLinks,appLinkOptions:e.appLinkOptions,audiences:e.audiences,content:((o=e.getContent)==null?void 0:o.call(e,t))??t.content.data,templateId:t.templateId,widgetTypeId:t.widgetId,currentUser:e.currentUser,commonVideoProps:e.commonVideoProps,availablePresentations:e.availablePresentations,name:e.getName(t),hasPermissions:e.hasPermissions,getSelectedItems:e.getSelectedItems,metadata:e.getWidgetMetadata(t),seeMoreLink:(n=e.getSeeMoreAppLink)==null?void 0:n.call(e,t),badgeComponent:(r=e.getBadgeComponent)==null?void 0:r.call(e,t),getAnalyticsData:e.getAnalyticsData&&(y=>e.getAnalyticsData(t,e.index,y)),className:(u=e.getWidgetClassName)==null?void 0:u.call(e,t),settings:null,settingsHash:e.settingsHash,description:null,isPreviewing:!1,onClickRemoveItem:null,onClickSearchAllVideos:e.onClickSearchAllVideos}),L&&C&&c.jsx(k,{isFetching:F,fetchNext:x,fetchOnScroll:!0,nextCursor:d})]},`${t.widgetId}-${t.templateId}-${I}`)})})}export{U as I};
//# sourceMappingURL=DYZmg-Vl.chunk.js.map
