import React from 'react';
import PropTypes from 'prop-types';
import IDUtil from '../../../../util/IDUtil';
import classNames from 'classnames';

export default class Link extends React.Component {
    constructor(props) {
        super(props);
    }

    delete = e => {
        e.preventDefault();
        if (confirm('Are you sure you want to delete this link?')) {
            this.props.delete(this.props.link);
        }
    };

    render() {
        const link = this.props.link;
        return (
            <a
                href={link.url}
                target="_blank"
                title={link.url}
                className={classNames(IDUtil.cssClassName('link-type'))}
            >
                <div className="delete" title="Delete" onClick={this.delete} />
                {link.label}
            </a>
        );
    }
}

Link.propTypes = {
    link: PropTypes.object,
    delete: PropTypes.func.isRequired
};
