{"version":3,"file":"useRowSelection.cjs","sources":["../../../../../src/lib/DataTable/tableFeatures/useRowSelection.ts"],"sourcesContent":["import {useCallback, useEffect, useMemo, useState} from 'react';\nimport type {RowSelectionState, Updater} from '@tanstack/react-table';\n\nimport {ProcessingModes} from './../types.ts';\n\nexport type Props = {\n    onRowSelect: (selectionState: RowSelectionState) => void;\n    rowSelectionProp: RowSelectionState;\n    processingMode: keyof typeof ProcessingModes;\n};\n\nexport const useRowSelection = ({rowSelectionProp, onRowSelect, processingMode}: Props) => {\n    const isClient = processingMode === ProcessingModes.internal;\n    const [rowSelection, setRowSelection] = useState<RowSelectionState>(rowSelectionProp);\n    useEffect(() => {\n        setRowSelection(rowSelectionProp);\n    }, [rowSelectionProp]);\n\n    useEffect(() => {\n        onRowSelect(rowSelection);\n    }, [onRowSelect, rowSelection]);\n\n    const clearSelection = useCallback(() => {\n        processingMode === ProcessingModes.internal && setRowSelection({});\n        onRowSelect({});\n    }, [onRowSelect, processingMode]);\n\n    const handleRowSelection = useMemo(() => {\n        if (isClient) {\n            return setRowSelection;\n        } else {\n            return (updater: Updater<RowSelectionState>) => {\n                if (typeof updater === 'function') {\n                    onRowSelect(updater(rowSelection) as RowSelectionState);\n                } else {\n                    onRowSelect(updater);\n                }\n            };\n        }\n    }, [isClient, onRowSelect, rowSelection]);\n\n    return {rowSelection, setRowSelection: handleRowSelection, clearSelection};\n};\n"],"names":["useRowSelection","rowSelectionProp","onRowSelect","processingMode","isClient","ProcessingModes","rowSelection","setRowSelection","useState","useEffect","clearSelection","useCallback","handleRowSelection","useMemo","updater"],"mappings":"gJAWaA,EAAkB,CAAC,CAAC,iBAAAC,EAAkB,YAAAC,EAAa,eAAAC,KAA2B,CACvF,MAAMC,EAAWD,IAAmBE,EAAAA,gBAAgB,SAC9C,CAACC,EAAcC,CAAe,EAAIC,EAAAA,SAA4BP,CAAgB,EACpFQ,EAAAA,UAAU,IAAM,CACZF,EAAgBN,CAAgB,CACpC,EAAG,CAACA,CAAgB,CAAC,EAErBQ,EAAAA,UAAU,IAAM,CACZP,EAAYI,CAAY,CAC5B,EAAG,CAACJ,EAAaI,CAAY,CAAC,EAE9B,MAAMI,EAAiBC,EAAAA,YAAY,IAAM,CACrCR,IAAmBE,EAAAA,gBAAgB,UAAYE,EAAgB,CAAA,CAAE,EACjEL,EAAY,CAAA,CAAE,CAClB,EAAG,CAACA,EAAaC,CAAc,CAAC,EAE1BS,EAAqBC,EAAAA,QAAQ,IAC3BT,EACOG,EAECO,GAAwC,CAExCZ,EADA,OAAOY,GAAY,WACPA,EAAQR,CAAY,EAEpBQ,CAF0C,CAI9D,EAEL,CAACV,EAAUF,EAAaI,CAAY,CAAC,EAExC,MAAO,CAAC,aAAAA,EAAc,gBAAiBM,EAAoB,eAAAF,CAAA,CAC/D"}