import PropTypes from 'prop-types';
const {decodeEntities} = wp.htmlEntities;
const {__} = wp.i18n;

import {getDataFontForTypography} from 'components/typography-select/utils';

function Title(props) {
	const {post, attributes} = props;

	const {postTitleTypography} = attributes;

	if (undefined === post.title) {
		return null;
	}

	return (
		<div className={'flo-block-post-list__title'}>
			<a
				href={post.link}
				data-font={getDataFontForTypography(postTitleTypography)}
			>
				{decodeEntities(post.title.rendered.trim()) || __('(Untitled)')}
			</a>
		</div>
	);
}

export default Title;

Title.propTypes = {
	post: PropTypes.object,
	attributes: PropTypes.object,
};
