{"version":3,"file":"RowActions.cjs","names":["_react","require","_MenuItem","_i18n","_index","_jsxRuntime","RowActions","isRowReorderingDisabled","row","incomingRow","rowActionMenuItems","rowIndex","totalRows","updateRowOrder","t","useTranslation","original","handleToFrontClick","useCallback","rowId","id","newRowIndex","handleForwardClick","Math","max","handleBackwardClick","handleToBackClick","jsxs","Fragment","children","jsx","MenuItem","isDisabled","onClick","ArrowTopIcon","ArrowUpIcon","ArrowDownIcon","ArrowBottomIcon","MemoizedRowActions","exports","memo","displayName"],"sources":["../../../../src/labs/DataView/RowActions.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_Row, MRT_RowData } from \"material-react-table\";\nimport { Fragment, memo, ReactElement, useCallback } from \"react\";\n\nimport { Button } from \"../../Buttons/Button.js\";\nimport { type MenuButtonProps } from \"../../Buttons/MenuButton.js\";\nimport { MenuItem } from \"../../Buttons/MenuItem.js\";\nimport { useTranslation } from \"../../i18n.generated/i18n.js\";\nimport {\n  ArrowBottomIcon,\n  ArrowDownIcon,\n  ArrowTopIcon,\n  ArrowUpIcon,\n} from \"../../icons.generated/index.js\";\nimport { DataTableProps } from \"./DataTable.js\";\n\n// Rows coming from TableLayoutContent will be in the MRT-expected row format, while rows coming from CardLayoutContent will be pure data\ntype RowOrTableRow<TData extends MRT_RowData> = MRT_Row<TData> | TData;\n\nexport type RowActionsProps<TData extends MRT_RowData> = {\n  isRowReorderingDisabled?: boolean;\n  row: RowOrTableRow<TData>;\n  rowActionButtons?: (\n    row?: TData,\n  ) => ReactElement<typeof Button> | ReactElement<typeof Fragment>;\n  rowActionMenuItems?: (row: TData) => MenuButtonProps[\"children\"];\n  rowIndex: number;\n  totalRows?: DataTableProps<TData>[\"totalRows\"];\n  updateRowOrder?: ({\n    newRowIndex,\n    rowId,\n  }: {\n    newRowIndex: number;\n    rowId: string;\n  }) => void;\n};\n\nconst RowActions = <TData extends MRT_RowData>({\n  isRowReorderingDisabled,\n  row: incomingRow,\n  rowActionMenuItems,\n  rowIndex,\n  totalRows,\n  updateRowOrder,\n}: RowActionsProps<TData>) => {\n  const { t } = useTranslation();\n\n  const row = (\n    incomingRow.original ? incomingRow.original : incomingRow\n  ) as TData & { id: string };\n\n  const handleToFrontClick = useCallback(() => {\n    if (updateRowOrder) {\n      updateRowOrder({ rowId: row.id, newRowIndex: 0 });\n    }\n  }, [row.id, updateRowOrder]);\n\n  const handleForwardClick = useCallback(() => {\n    if (updateRowOrder) {\n      updateRowOrder({ rowId: row.id, newRowIndex: Math.max(0, rowIndex - 1) });\n    }\n  }, [row.id, rowIndex, updateRowOrder]);\n\n  const handleBackwardClick = useCallback(() => {\n    if (updateRowOrder) {\n      updateRowOrder({ rowId: row.id, newRowIndex: rowIndex + 1 });\n    }\n  }, [row.id, rowIndex, updateRowOrder]);\n\n  const handleToBackClick = useCallback(() => {\n    if (updateRowOrder) {\n      updateRowOrder({\n        rowId: row.id,\n        newRowIndex: totalRows ? totalRows - 1 : rowIndex,\n      });\n    }\n  }, [row.id, rowIndex, totalRows, updateRowOrder]);\n\n  return (\n    <>\n      {rowActionMenuItems && rowActionMenuItems(row)}\n      {rowActionMenuItems && updateRowOrder && <hr />}\n      {updateRowOrder && (\n        <>\n          <MenuItem\n            isDisabled={rowIndex <= 0 || isRowReorderingDisabled}\n            onClick={handleToFrontClick}\n          >\n            <ArrowTopIcon /> {t(\"table.reorder.tofront\")}\n          </MenuItem>\n          <MenuItem\n            isDisabled={rowIndex <= 0 || isRowReorderingDisabled}\n            onClick={handleForwardClick}\n          >\n            <ArrowUpIcon /> {t(\"table.reorder.forward\")}\n          </MenuItem>\n          <MenuItem\n            isDisabled={\n              (totalRows ? rowIndex >= totalRows - 1 : false) ||\n              isRowReorderingDisabled\n            }\n            onClick={handleBackwardClick}\n          >\n            <ArrowDownIcon /> {t(\"table.reorder.backward\")}\n          </MenuItem>\n          {totalRows && (\n            <MenuItem\n              isDisabled={rowIndex >= totalRows - 1 || isRowReorderingDisabled}\n              onClick={handleToBackClick}\n            >\n              <ArrowBottomIcon /> {t(\"table.reorder.toback\")}\n            </MenuItem>\n          )}\n        </>\n      )}\n    </>\n  );\n};\n\nconst MemoizedRowActions = memo(RowActions);\nMemoizedRowActions.displayName = \"RowActions\";\n\nexport { MemoizedRowActions as RowActions };\n"],"mappings":";;;;;;AAaA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAKwC,IAAAI,WAAA,GAAAJ,OAAA;AAxBxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAsCA,MAAMK,UAAU,GAAGA,CAA4B;EAC7CC,uBAAuB;EACvBC,GAAG,EAAEC,WAAW;EAChBC,kBAAkB;EAClBC,QAAQ;EACRC,SAAS;EACTC;AACsB,CAAC,KAAK;EAC5B,MAAM;IAAEC;EAAE,CAAC,GAAG,IAAAC,oBAAc,EAAC,CAAC;EAE9B,MAAMP,GAAG,GACPC,WAAW,CAACO,QAAQ,GAAGP,WAAW,CAACO,QAAQ,GAAGP,WACrB;EAE3B,MAAMQ,kBAAkB,GAAG,IAAAC,kBAAW,EAAC,MAAM;IAC3C,IAAIL,cAAc,EAAE;MAClBA,cAAc,CAAC;QAAEM,KAAK,EAAEX,GAAG,CAACY,EAAE;QAAEC,WAAW,EAAE;MAAE,CAAC,CAAC;IACnD;EACF,CAAC,EAAE,CAACb,GAAG,CAACY,EAAE,EAAEP,cAAc,CAAC,CA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