"use strict";var core=require("@gem-sdk/core"),useDynamicProduct=require("../../../hooks/useDynamicProduct.js"),React=require("react"),index=require("../../../helpers/index.js"),ProductOfferPlaceholder=require("../../../constants/ProductOfferPlaceholder.js");const useProductOfferData=()=>{let e=core.usePageStore(e=>e.productOffers),o=core.usePageStore(e=>e.publicStoreFrontData),{isDynamicProduct:r}=useDynamicProduct.useDynamicProduct(),t=core.usePageStore(e=>e.dynamicDiscountOffer),c=React.useMemo(()=>r?t?.appliedProductCount:e?.length,[t?.appliedProductCount,r,e?.length]),u=React.useMemo(()=>e?.sort((e,o)=>e?.node?.position&&o?.node?.position?e.node.position-o.node.position:0).map(e=>e?.node?.objectBaseID).filter(Boolean),[e]),{isLoading:a,isValidating:d,data:n}=core.useProductsQuery(u||[],{revalidateOnMount:!0},{allStatus:!0,fetcher:index.hasPublicStoreFrontData(o)?index.createStoreFrontFetcher(o):void 0}),s=React.useMemo(()=>a||d,[a,d]),i=React.useMemo(()=>core.flattenConnection(n?.products),[n?.products]),l=React.useMemo(()=>r&&t?.appliedProductCount?Array(t.appliedProductCount).fill(ProductOfferPlaceholder.productOfferPlaceholder):u?.map(e=>i?.find(o=>o?.baseID===e)).filter(Boolean),[r,t?.appliedProductCount,u,i]);return{isLoading:s,productSortedById:l,totalProduct:c}};exports.useProductOfferData=useProductOfferData;
