import{a as e,c as t,i as n,l as r,o as i,r as a,s as o}from"./DataFrame.Dqn1eUs1.js";import{Ga as s,Qa as c,io as l}from"./index.dkY5s53S.js";var u=l(c(),1),ee=l(s(),1),d=i(`div`)({name:`DataGridOverlayEditorStyle`,class:`gdg-d19meir1`,propsAsIs:!1,vars:{"d19meir1-0":[e=>e.targetY,`px`],"d19meir1-1":[e=>e.targetX,`px`],"d19meir1-2":[e=>e.targetWidth,`px`],"d19meir1-3":[e=>e.targetHeight,`px`],"d19meir1-4":[e=>e.targetY+10,`px`],"d19meir1-5":[e=>Math.max(0,(e.targetHeight-28)/2),`px`]}});function f(){let[e,t]=u.useState();return[e??void 0,t]}function p(){let[e,t]=f(),[n,r]=u.useState(0),[i,a]=u.useState(!0);return u.useLayoutEffect(()=>{if(e===void 0||!(`IntersectionObserver`in window))return;let t=new IntersectionObserver(e=>{e.length!==0&&a(e[0].isIntersecting)},{threshold:1});return t.observe(e),()=>t.disconnect()},[e]),u.useEffect(()=>{if(i||e===void 0)return;let t,n=()=>{let{right:i}=e.getBoundingClientRect();r(e=>Math.min(e+window.innerWidth-i-10,0)),t=requestAnimationFrame(n)};return t=requestAnimationFrame(n),()=>{t!==void 0&&cancelAnimationFrame(t)}},[e,i]),{ref:t,style:u.useMemo(()=>({transform:`translateX(${n}px)`}),[n])}}var m=i=>{let{target:s,content:c,onFinishEditing:l,forceEditMode:f,initialValue:m,imageEditorOverride:h,markdownDivCreateNode:g,highlight:_,className:v,theme:y,id:b,cell:x,bloom:S,portalElementRef:C,validateCell:w,getCellRenderer:T,provideEditor:E,isOutsideClick:D,customEventTarget:O,activation:k}=i,[A,j]=u.useState(f?c:void 0),M=u.useRef(A??c);M.current=A??c;let[N,P]=u.useState(()=>w===void 0?!0:!(o(c)&&w?.(x,c,M.current)===!1)),F=u.useCallback((e,t)=>{l(N?e:void 0,t)},[N,l]),I=u.useCallback(e=>{if(w!==void 0&&e!==void 0&&o(e)){let t=w(x,e,M.current);t===!1?P(!1):(typeof t==`object`&&(e=t),P(!0))}j(e)},[x,w]),L=u.useRef(!1),R=u.useRef(void 0),z=u.useCallback(()=>{F(A,[0,0]),L.current=!0},[A,F]),B=u.useCallback((e,t)=>{F(e,t??R.current??[0,0]),L.current=!0},[F]),V=u.useCallback(async e=>{let t=!1;e.key===`Escape`?(e.stopPropagation(),e.preventDefault(),R.current=[0,0]):e.key===`Enter`&&!e.shiftKey?(e.stopPropagation(),e.preventDefault(),R.current=[0,1],t=!0):e.key===`Tab`&&(e.stopPropagation(),e.preventDefault(),R.current=[e.shiftKey?-1:1,0],t=!0),window.setTimeout(()=>{!L.current&&R.current!==void 0&&(F(t?A:void 0,R.current),L.current=!0)},0)},[F,A]),H=A??c,[U,W]=u.useMemo(()=>{if(t(c))return[];let e={...c,location:x,activation:k},n=E?.(e);return n===void 0?[T(c)?.provideEditor?.(e),!1]:[n,!1]},[x,c,T,E,k]),{ref:G,style:te}=p(),K=!0,q,J=!0,Y;if(U!==void 0){K=U.disablePadding!==!0,J=U.disableStyling!==!0;let e=r(U);e&&(Y=U.styleOverride);let t=e?U.editor:U;q=u.createElement(t,{portalElementRef:C,isHighlighted:_,activation:k,onChange:I,value:H,initialValue:m,onFinishedEditing:B,validatedSelection:o(H)?H.selectionRange:void 0,forceEditMode:f,target:s,imageEditorOverride:h,markdownDivCreateNode:g,isValid:N,theme:y})}Y={...Y,...te};let X=C?.current??document.getElementById(`portal`);if(X===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 Z=J?`gdg-style`:`gdg-unstyle`;N||(Z+=` gdg-invalid`),K&&(Z+=` gdg-pad`);let Q=S?.[0]??1,$=S?.[1]??1;return(0,ee.createPortal)(u.createElement(n.Provider,{value:y},u.createElement(a,{style:e(y),className:v,onClickOutside:z,isOutsideClick:D,customEventTarget:O},u.createElement(d,{ref:G,id:b,className:Z,style:Y,as:W===!0?`label`:void 0,targetX:s.x-Q,targetY:s.y-$,targetWidth:s.width+Q*2,targetHeight:s.height+$*2},u.createElement(`div`,{className:`gdg-clip-region`,onKeyDown:V},q)))),X)};export{m as default};