import{useMemo as e,useEffect as r}from"react";import{useProduct as t,useProductStore as o,usePageStore as n}from"@gem-sdk/core";import{extractProductID as s}from"../../../helpers.js";import{DEFAULT_BUYER_CONSENT_CHECKED_VALUE as m}from"../common/constants.js";let useBuyerConsentChecked=()=>{let u=t(),c=o(e=>e.uid),C=!!u?.requiresSellingPlan,l=n(e=>e.buyerConsentChecked),d=n(e=>e.setBuyerConsentChecked),i=n(e=>e.getBuyerConsentChecked),h=s(u?.baseID??""),k=l?.[h],p=e(()=>{let e=C?h:`${h}_${c}`;return e},[C,h,c]),y=l?.[p]??m,a=e=>{let r=i();d({...r,[p]:e})};return r(()=>{void 0!==k&&a(k)},[k]),r(()=>{0===Object.keys(l??{}).length&&a(m)},[l]),{checked:y,setChecked:a}};export{useBuyerConsentChecked};
