import{useRef as e,useState as t,useCallback as r,useEffect as i}from"react";import{useProduct as l,useCurrentDevice as o,getResponsiveValueByScreen as n,useProductShopifyEditLink as m,useEditorMode as p,isSafari as s}from"@gem-sdk/core";let useGpDescription=c=>{let u=e(null),[a,h]=t(!1),[g,d]=t(!1),H=l(),y=o(),x=n(c?.hasLineClamp,y),f=n(c?.lineClamp,y),{redirectProductShopifyLink:C}=m(),w=p(),D=r(()=>`calc(${f} * 1lh)`,[f]),G=r(e=>x&&f&&e||"auto",[x,f]),k=r(()=>{u.current&&(u.current.style.maxHeight=a?D():"none",h(e=>!e))},[a,D]);return i(()=>{G(D())},[c?.typo?.custom,G,D]),i(()=>{let e=u.current;if(h(!1),!e)return;let t=x&&H?.descriptionHtml;t?setTimeout(()=>{let t=e?.scrollHeight??0,r=e?.clientHeight??0,i=r<t,l=window.getComputedStyle(e).getPropertyValue("line-height"),o=parseInt(l,10)||1,n=Math.round((t??0)/o),m=void 0!==f&&f<n,p=s()?m:i;e.style.maxHeight=D(),f&&p?d(()=>!0):d(()=>!1)},100):e.style.maxHeight="none"},[x,f,H?.descriptionHtml,D]),{ref:u,open:a,isShowViewMore:g,handleToggleShowMore:k,mode:w,redirectProductShopifyLink:C}};export{useGpDescription};
