'use strict';

import React from 'react';
import PropTypes from 'prop-types';
import {KeyDownable} from '../KeyDownable';

export class ListRow extends React.Component {
    static defaultProps = {
        children: null,
        testAutomationId: 'row',
        onClick: null,
        keyDownableProps: {
            preventDefaultKeyDown: false,
            preventDefaultMouseDown: false
        }
    };

    static propTypes = {
        children: PropTypes.node,
        testAutomationId: PropTypes.string,
        onClick: PropTypes.func,
        keyDownableProps: PropTypes.shape({
            preventDefaultKeyDown: PropTypes.bool,
            preventDefaultMouseDown: PropTypes.bool
        })
    };

    render() {
        let {children, testAutomationId, keyDownableProps, onClick, ...props} = this.props;

        return (
            <KeyDownable {...keyDownableProps} onClick={onClick}>
                {({onClick: onRowClick, onKeyDown}) => (
                    <tr
                        data-test-automation-id={testAutomationId}
                        {...props}
                        onClick={onRowClick}
                        onKeyDown={onKeyDown}>
                        {children}
                    </tr>
                )}
            </KeyDownable>
        );
    }
}
