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