import { jsx } from "react/jsx-runtime";
import "react";
import { isArr, isValid, observer, useField } from "@tachybase/schema";
import { TableVoid } from "./Table.Void.mjs";
const toArr = (value)=>isArr(value) ? value : isValid(value) ? [
        value
    ] : [];
const TableRowSelection = observer((props)=>{
    const { rowKey = 'id', objectValue } = props;
    const field = useField();
    const rowSelection = {
        type: 'checkbox',
        ...props.rowSelection,
        selectedRowKeys: toArr(field.value).map((val)=>'object' == typeof val ? val[rowKey] : val),
        onChange (selectedRowKeys, selectedRows) {
            if ('checkbox' === rowSelection.type) props.onChange(objectValue ? selectedRows : selectedRowKeys);
            else props.onChange([
                ...objectValue ? selectedRows : selectedRowKeys
            ].shift());
        }
    };
    return /*#__PURE__*/ jsx(TableVoid, {
        ...props,
        rowSelection: rowSelection
    });
}, {
    displayName: 'TableRowSelection'
});
export { TableRowSelection };
