import React from 'react';
import PropTypes from 'prop-types';

import {CommonListHighlight} from './common/CommonListHighlight';
import {getHighlightRegExp, searchStringToRegExp} from '../../utils/regexp';

export class PureListHighlight extends React.Component {
    static propTypes = {
        ...CommonListHighlight.propTypes,
        highlightedText: PropTypes.string
    };

    static defaultProps = {
        ...CommonListHighlight.defaultProps,
        highlightedText: ''
    };

    static HIGHLIGHT_TYPE_BACKGROUND = CommonListHighlight.HIGHLIGHT_TYPE_BACKGROUND;
    static HIGHLIGHT_TYPE_BOLD = CommonListHighlight.HIGHLIGHT_TYPE_BOLD;

    getTextHighlightPattern() {
        const {textHighlightPattern, highlightedText} = this.props;

        return textHighlightPattern || getHighlightRegExp(highlightedText);
    }

    getTextFilterPattern() {
        const {textFilterPattern, highlightedText} = this.props;

        return textFilterPattern || searchStringToRegExp(highlightedText);
    }

    render() {
        return (
            <CommonListHighlight
                {...this.props}
                textHighlightPattern={this.getTextHighlightPattern()}
                textFilterPattern={this.getTextFilterPattern()}
            />
        );
    }
}
