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