import{r,d as J}from"./index-DCNLpqIv.js";import{s as Q,i as R,a as U,b as Z,T as _,C as ee,m as te}from"./index-DhqQeff3.js";import"./withFullScreenWrapper-C3PKUCi4.js";import"./Toolbar-DiWCQxr5.js";import"./FormClearHelper-fvwQICEk.js";import"./mergeWith-fWFIuGgc.js";import"./sprintf-D7DtBTRn.js";import"./checkbox-BNaalk8J.js";import"./createDownloadLinkElement-ZaXNnPK4.js";import"./slicedToArray-CgI3PJi3.js";import"./inherits-BWX75f6B.js";import"./createSuper-CQM18OGw.js";import"./FileDownload.esm-kSzyJagP.js";const re=()=>t=>t.targetX,ie=()=>t=>t.targetY,oe=()=>t=>t.targetWidth,ae=()=>t=>t.targetHeight,ne=()=>t=>t.targetY+10,se=()=>t=>Math.max(0,(t.targetHeight-28)/2),de=Q("div")({name:"DataGridOverlayEditorStyle",class:"gdg-d19meir1",propsAsIs:!1,vars:{"d19meir1-0":[ie(),"px"],"d19meir1-1":[re(),"px"],"d19meir1-2":[oe(),"px"],"d19meir1-3":[ae(),"px"],"d19meir1-4":[ne(),"px"],"d19meir1-5":[se(),"px"]}});function le(){const[t,a]=r.useState();return[t??void 0,a]}function ce(){const[t,a]=le(),[o,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(${o}px)`}),[o]);return{ref:a,style:C}}const ue=t=>{const{target:a,content:o,onFinishEditing:f,forceEditMode:m,initialValue:b,imageEditorOverride:C,markdownDivCreateNode:n,highlight:s,className:k,theme:g,id:V,cell:p,bloom:S,portalElementRef:D,validateCell:v,getCellRenderer:P,provideEditor:M,isOutsideClick:W,customEventTarget:X}=t,[d,Y]=r.useState(m?o:void 0),w=r.useRef(d??o);w.current=d??o;const[h,N]=r.useState(()=>v===void 0?!0:!(R(o)&&v?.(p,o,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?N(!1):(typeof i=="object"&&(e=i),N(!0))}Y(e)},[p,v]),y=r.useRef(!1),u=r.useRef(void 0),B=r.useCallback(()=>{c(d,[0,0]),y.current=!0},[d,c]),G=r.useCallback((e,i)=>{c(e,i??u.current??[0,0]),y.current=!0},[c]),j=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(()=>{!y.current&&u.current!==void 0&&(c(i?d:void 0,u.current),y.current=!0)},0)},[c,d]),x=d??o,[l,L]=r.useMemo(()=>{if(U(o))return[];const e={...o,location:p},i=M?.(e);return i!==void 0?[i,!1]:[P(o)?.provideEditor?.(e),!1]},[p,o,P,M]),{ref:$,style:z}=ce();let F=!0,I,T=!0,E;if(l!==void 0){F=l.disablePadding!==!0,T=l.disableStyling!==!0;const e=Z(l);e&&(E=l.styleOverride);const i=e?l.editor:l;I=r.createElement(i,{portalElementRef:D,isHighlighted:s,onChange:q,value:x,initialValue:b,onFinishedEditing:G,validatedSelection:R(x)?x.selectionRange:void 0,forceEditMode:m,target:a,imageEditorOverride:C,markdownDivCreateNode:n,isValid:h,theme:g})}E={...E,...z};const A=D?.current??document.getElementById("portal");if(A===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 O=T?"gdg-style":"gdg-unstyle";h||(O+=" gdg-invalid"),F&&(O+=" gdg-pad");const H=S?.[0]??1,K=S?.[1]??1;return J.createPortal(r.createElement(_.Provider,{value:g},r.createElement(ee,{style:te(g),className:k,onClickOutside:B,isOutsideClick:W,customEventTarget:X},r.createElement(de,{ref:$,id:V,className:O,style:E,as:L===!0?"label":void 0,targetX:a.x-H,targetY:a.y-K,targetWidth:a.width+H*2,targetHeight:a.height+K*2},r.createElement("div",{className:"gdg-clip-region",onKeyDown:j},I)))),A)};export{ue as default};
