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 useProductSetting=u=>{let{setting:n}=u,{productSetting:l,quantity:s,readOnly:P,isSyncProduct:m}=n??{},S=t(),p=e(t=>t.dynamicProduct),g=e(t=>t.publicStoreFrontData),{isEditMode:h,isPreviewSharePageMode:y}=r(),I=l?.productId??"latest",f=l?.productStatus=="dynamic"?{...l,...p}:l,k=f?.initialVariantId,v=f?.initialVariantBaseId,D=o(()=>a(g)?d(g):void 0,[g]),O=h||y,{data:V,isLoading:$,error:b}=i(I,{revalidateOnMount:O},D),[x,B]=c(!0),C=(b||!V&&!$)&&h,E="PRODUCT"===S,F=o(()=>({product:V,initialVariantId:k,initialVariantBaseId:v,quantity:s,readOnly:P,isSyncProduct:m,key:`uid-${V?.id}-${k??""}`,hasPreSelected:l?.hasPreSelected}),[v,k,m,V,l?.hasPreSelected,s,P]);return{forceProductSetting:f,isProductPage:E,isProductNotFound:C,showProductNotFound:x,isLoading:$,product:V,errorLoadProduct:b,isEditor:h,productProviderData:F,setShowProductNotFound:B}};export{useProductSetting};
