{"version":3,"file":"reorderDataRowsLocally.cjs","names":["reorderDataRowsLocally","currentData","rowId","newRowIndex","updatedData","rowIndex","findIndex","row","id","length","console","warn","removedRow","splice","exports"],"sources":["../../../src/DataTable/reorderDataRowsLocally.tsx"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { MRT_RowData } from \"material-react-table\";\n\n/**\n * Reorders data rows locally.\n *\n * @param currentData - The current array of data rows.\n * @param rowId - The ID of the row to move.\n * @param newIndex - The new index to move the row to.\n * @returns A new array of data with the row moved to the specified index.\n */\nexport const reorderDataRowsLocally = <TData extends MRT_RowData>({\n  currentData,\n  rowId,\n  newRowIndex,\n}: {\n  currentData: TData[];\n  newRowIndex: number;\n  rowId: string;\n}): TData[] => {\n  const updatedData = [...currentData];\n  const rowIndex = updatedData.findIndex((row) => row.id === rowId);\n\n  // Ensure the row exists and the new index is within bounds\n  if (rowIndex === -1 || newRowIndex < 0 || newRowIndex >= updatedData.length) {\n    console.warn(\"Invalid row ID or newIndex; cannot reorder rows.\");\n    return updatedData; // Return the original data if conditions aren't met\n  }\n\n  // Remove the row from its current position\n  const [removedRow] = updatedData.splice(rowIndex, 1);\n\n  // Insert the row at the new index\n  updatedData.splice(newRowIndex, 0, removedRow);\n\n  return updatedData;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAYO,MAAMA,sBAAsB,GAAGA,CAA4B;EAChEC,WAAW;EACXC,KAAK;EACLC;AAKF,CAAC,KAAc;EACb,MAAMC,WAAW,GAAG,CAAC,GAAGH,WAAW,CAAC;EACpC,MAAMI,QAAQ,GAAGD,WAAW,CAACE,SAAS,CAAEC,GAAG,IAAKA,GAAG,CAACC,EAAE,KAAKN,KAAK,CAAC;EAGjE,IAAIG,QAAQ,KAAK,CAAC,CAAC,IAAIF,WAAW,GAAG,CAAC,IAAIA,WAAW,IAAIC,WAAW,CAACK,MAAM,EAAE;IAC3EC,OAAO,CAACC,IAAI,CAAC,kDAAkD,CAAC;IAChE,OAAOP,WAAW;EACpB;EAGA,MAAM,CAACQ,UAAU,CAAC,GAAGR,WAAW,CAACS,MAAM,CAACR,QAAQ,EAAE,CAAC,CAAC;EAGpDD,WAAW,CAACS,MAAM,CAACV,WAAW,EAAE,CAAC,EAAES,UAAU,CAAC;EAE9C,OAAOR,WAAW;AACpB,CAAC;AAACU,OAAA,CAAAd,sBAAA,GAAAA,sBAAA","ignoreList":[]}