import{r,b as J}from"./index-D3uELfdo.js";import{V as R,E as Q,m as U,G as Z,c as ee,k as te,a as re}from"./index-GLEJ4uEg-Df22L041.js";import"./withFullScreenWrapper-WW0e_nhm-CAjrnrPK.js";import"./Toolbar-Ba82LOXi-C-TMlOex.js";import"./FormClearHelper-Dgu5Halt-BxICjxpW.js";import"./sprintf-D5E86llw-6tzWM3a-.js";import"./checkbox-i_07yegq-B7N8fYE1.js";import"./createDownloadLinkElement-CbRjLJ8e-NbV49OP9.js";import"./slicedToArray-DCtO1hP1-DNgLFFIn.js";import"./inherits-Rx5YJbse-DVYurFFp.js";import"./createSuper-Bj1hzAgo-DTBN9Cdm.js";import"./FileDownload.esm-BP6Yw6Mo-BauI2spi.js";const ie=()=>t=>t.targetX,ae=()=>t=>t.targetY,oe=()=>t=>t.targetWidth,ne=()=>t=>t.targetHeight,se=()=>t=>t.targetY+10,le=()=>t=>Math.max(0,(t.targetHeight-28)/2),de=re("div")({name:"DataGridOverlayEditorStyle",class:"gdg-d19meir1",propsAsIs:!1,vars:{"d19meir1-0":[ae(),"px"],"d19meir1-1":[ie(),"px"],"d19meir1-2":[oe(),"px"],"d19meir1-3":[ne(),"px"],"d19meir1-4":[se(),"px"],"d19meir1-5":[le(),"px"]}});function ce(){const[t,o]=r.useState();return[t??void 0,o]}function ue(){const[t,o]=ce(),[a,f]=r.useState(0),[m,b]=r.useState(!0);r.useLayoutEffect(()=>{if(t===void 0||!("IntersectionObserver"in window))return;const n=new IntersectionObserver(s=>{s.length!==0&&b(s[0].isIntersecting)},{threshold:1});return n.observe(t),()=>n.disconnect()},[t]),r.useEffect(()=>{if(m||t===void 0)return;let n;const s=()=>{const{right:k}=t.getBoundingClientRect();f(g=>Math.min(g+window.innerWidth-k-10,0)),n=requestAnimationFrame(s)};return n=requestAnimationFrame(s),()=>{n!==void 0&&cancelAnimationFrame(n)}},[t,m]);const C=r.useMemo(()=>({transform:`translateX(${a}px)`}),[a]);return{ref:o,style:C}}const we=t=>{const{target:o,content:a,onFinishEditing:f,forceEditMode:m,initialValue:b,imageEditorOverride:C,markdownDivCreateNode:n,highlight:s,className:k,theme:g,id:K,cell:p,bloom:S,portalElementRef:P,validateCell:v,getCellRenderer:M,provideEditor:N,isOutsideClick:W,customEventTarget:X,activation:x}=t,[l,Y]=r.useState(m?a:void 0),w=r.useRef(l??a);w.current=l??a;const[h,F]=r.useState(()=>v===void 0?!0:!(R(a)&&v?.(p,a,w.current)===!1)),c=r.useCallback((e,i)=>{f(h?e:void 0,i)},[h,f]),q=r.useCallback(e=>{if(v!==void 0&&e!==void 0&&R(e)){const i=v(p,e,w.current);i===!1?F(!1):(typeof i=="object"&&(e=i),F(!0))}Y(e)},[p,v]),E=r.useRef(!1),u=r.useRef(void 0),B=r.useCallback(()=>{c(l,[0,0]),E.current=!0},[l,c]),j=r.useCallback((e,i)=>{c(e,i??u.current??[0,0]),E.current=!0},[c]),L=r.useCallback(async e=>{let i=!1;e.key==="Escape"?(e.stopPropagation(),e.preventDefault(),u.current=[0,0]):e.key==="Enter"&&!e.shiftKey?(e.stopPropagation(),e.preventDefault(),u.current=[0,1],i=!0):e.key==="Tab"&&(e.stopPropagation(),e.preventDefault(),u.current=[e.shiftKey?-1:1,0],i=!0),window.setTimeout(()=>{!E.current&&u.current!==void 0&&(c(i?l:void 0,u.current),E.current=!0)},0)},[c,l]),O=l??a,[d,$]=r.useMemo(()=>{if(Q(a))return[];const e={...a,location:p,activation:x},i=N?.(e);return i!==void 0?[i,!1]:[M(a)?.provideEditor?.(e),!1]},[p,a,M,N,x]),{ref:z,style:_}=ue();let I=!0,V,A=!0,y;if(d!==void 0){I=d.disablePadding!==!0,A=d.disableStyling!==!0;const e=U(d);e&&(y=d.styleOverride);const i=e?d.editor:d;V=r.createElement(i,{portalElementRef:P,isHighlighted:s,activation:x,onChange:q,value:O,initialValue:b,onFinishedEditing:j,validatedSelection:R(O)?O.selectionRange:void 0,forceEditMode:m,target:o,imageEditorOverride:C,markdownDivCreateNode:n,isValid:h,theme:g})}y={...y,..._};const G=P?.current??document.getElementById("portal");if(G===null)return console.error('Cannot open Data Grid overlay editor, because portal not found. Please, either provide a portalElementRef or add `<div id="portal" />` as the last child of your `<body>`.'),null;let D=A?"gdg-style":"gdg-unstyle";h||(D+=" gdg-invalid"),I&&(D+=" gdg-pad");const H=S?.[0]??1,T=S?.[1]??1;return J.createPortal(r.createElement(Z.Provider,{value:g},r.createElement(ee,{style:te(g),className:k,onClickOutside:B,isOutsideClick:W,customEventTarget:X},r.createElement(de,{ref:z,id:K,className:D,style:y,as:$===!0?"label":void 0,targetX:o.x-H,targetY:o.y-T,targetWidth:o.width+H*2,targetHeight:o.height+T*2},r.createElement("div",{className:"gdg-clip-region",onKeyDown:L},V)))),G)};export{we as default};
