import{K as w,u as N}from"./OdysseyThemeProvider-Bh0Bu-2o.js";import{r as p}from"./index-NdkWRN8K.js";/*!
 * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */const U=({currentData:r,rowId:e,newRowIndex:n})=>{const o=[...r],l=o.findIndex(u=>u.id===e);if(l===-1||n<0||n>=o.length)return console.warn("Invalid row ID or newIndex; cannot reorder rows."),o;const[t]=o.splice(l,1);return o.splice(n,0,t),o};/*!
 * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */const j=({totalRows:r,onReorderRows:e,data:n,setData:o,draggingRow:l,setDraggingRow:t,resultsPerPage:u,page:D})=>{const{t:d}=w(),f=({rowId:s,newRowIndex:i})=>{if(i<0||r&&i>r)return;const c=U({currentData:n,rowId:s,newRowIndex:i});o(c),e==null||e({rowId:s,newRowIndex:i})},a=N(),y={padding:a.Spacing1,borderRadius:a.BorderRadiusMain,"&:focus-visible":{boxShadow:`0 0 0 2px ${a.HueNeutralWhite}, 0 0 0 4px ${a.PalettePrimaryMain}`,outline:"2px solid transparent",outlineOffset:"1px"}},v={title:d("table.draghandle.tooltip"),"aria-label":d("table.draghandle.arialabel")},T=({currentRowId:s,draggingRowId:i,hoveredRowId:c})=>{if(i===s&&c!==s)return"isDragging";if(c===s&&i!==s)return"isDragTarget";if(i===s&&c===s)return"isDragging isDragTarget"},S=(s,i)=>{if(i){const c=s.getRow(i);c&&s.setHoveredRow(c)}},z=({table:s,row:i,event:c})=>{var K,M;const{hoveredRow:g}=s.getState(),{key:m}=c,P=m===" ",F=m==="Enter",O=m==="Escape",h=m==="ArrowDown",W=m==="ArrowUp",A=P||F,k=D-1,$=i.index+k*u;if(O){H(s);return}if(A&&(c.preventDefault(),c.stopPropagation()),l){if(typeof(g==null?void 0:g.index)=="number"){const{index:x}=g;if(A){const E=x+k*u;if(E!==$){f({rowId:i.id,newRowIndex:E}),setTimeout(()=>{H(s)},a.TransitionDurationMainAsNumber);return}}if(h||W){const E=h?x+1:x-1;S(s,(K=n[E])==null?void 0:K.id)}}else if(h||W){const x=h?i.index+1:i.index-1;S(s,(M=n[x])==null?void 0:M.id)}}else A&&t(i)},B=s=>{s.getAllColumns()[0].toggleVisibility();const{draggingRow:c,hoveredRow:g}=s.getState();c&&f({newRowIndex:g.index,rowId:c.id}),t(null)},L=s=>{var i;!l&&((i=s.getState().draggingRow)!=null&&i.id)&&t(s.getState().draggingRow)},H=s=>{t(null),s.setHoveredRow(null)};return{dragHandleStyles:y,dragHandleText:v,draggableTableBodyRowClassName:T,handleDragHandleKeyDown:z,handleDragHandleOnDragCapture:L,handleDragHandleOnDragEnd:B,resetDraggingAndHoveredRow:H,updateRowOrder:f}};/*!
 * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */const G=({tableOuterContainer:r,tableInnerContainer:e,setIsTableContainerScrolledToStart:n,setIsTableContainerScrolledToEnd:o,setTableInnerContainerWidth:l})=>{const t=p.useRef(null),u=p.useRef(null),D=N(),d=p.useCallback(()=>{if(!r||!e)return;const f=r.clientWidth,a=e.scrollWidth,y=e.scrollLeft,v=y+f;n(y<=16),o(v>=a-16)},[e,r,o,n]);p.useEffect(()=>{if(typeof ResizeObserver>"u"||u.current)return;let f;return u.current=new ResizeObserver(()=>{clearTimeout(f),f=setTimeout(()=>{t.current||(t.current=requestAnimationFrame(()=>{d(),t.current=null})),l(e!=null&&e.clientWidth?`${e.clientWidth-Number(D.BorderWidthMain)*2}px`:"100%")},100)}),r&&r.parentElement&&u.current.observe(r.parentElement),()=>{u.current&&(u.current.disconnect(),u.current=null),clearTimeout(f),t.current&&(cancelAnimationFrame(t.current),t.current=null)}},[d,l,r,e,n,o,D.BorderWidthMain]),p.useEffect(()=>(e==null||e.addEventListener("scroll",d),()=>e==null?void 0:e.removeEventListener("scroll",d)),[e,d]),p.useEffect(()=>{d()},[])};export{j as a,G as u};
