import React from 'react';
import PropTypes from 'prop-types';
import {Button} from './Button';
import BSMenuItem from 'react-bootstrap/lib/MenuItem';

export class CTAControl extends React.Component {
    static propTypes = {
        ...Button.propTypes,
        ...BSMenuItem.propTypes
    };

    static defaultProps = {
        testAutomationId: 'CATControl'
    };

    static contextTypes = {
        isCTADropdown: PropTypes.bool
    };

    isInsideDropdown() {
        return this.context.isCTADropdown;
    }

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

        if (this.isInsideDropdown()) {
            return (
                <BSMenuItem data-test-automation-id={testAutomationId} {...props}>
                    {children}
                </BSMenuItem>
            );
        } else {
            return (
                <Button testAutomationId={testAutomationId} {...props}>
                    {children}
                </Button>
            );
        }
    }
}
