"use strict";var core=require("@gem-sdk/core"),React=require("react");const useProductSetting=e=>{let{setting:t}=e,{productSetting:r,quantity:a,readOnly:o,isSyncProduct:c}=t??{},u=core.usePageType(),d=core.usePageStore(e=>e.dynamicProduct),i=core.usePageStore(e=>e.publicStoreFrontData),{isEditMode:s,isPreviewSharePageMode:n}=core.useRenderMode(),P=r?.productId??"latest",S=r?.productStatus=="dynamic"?{...r,...d}:r,l=S?.initialVariantId,g=S?.initialVariantBaseId,R=React.useMemo(()=>core.hasPublicStoreFrontData(i)?core.createStoreFrontFetcher(i):void 0,[i]),h=s||n,{data:m,isLoading:p,error:y}=core.useProductQuery(P,{revalidateOnMount:h},R),[F,M]=React.useState(!0),v=(y||!m&&!p)&&s,D="PRODUCT"===u,I=React.useMemo(()=>({product:m,initialVariantId:l,initialVariantBaseId:g,quantity:a,readOnly:o,isSyncProduct:c,key:`uid-${m?.id}-${l??""}`,hasPreSelected:r?.hasPreSelected}),[g,l,c,m,r?.hasPreSelected,a,o]);return{forceProductSetting:S,isProductPage:D,isProductNotFound:v,showProductNotFound:F,isLoading:p,product:m,errorLoadProduct:y,isEditor:s,productProviderData:I,setShowProductNotFound:M}};exports.useProductSetting=useProductSetting;
