/** * WordPress dependencies */ import { Button, Dashicon } from '@safe-wordpress/components'; import { useSelect } from '@safe-wordpress/data'; import { createInterpolateElement } from '@safe-wordpress/element'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import type { PostQualityStatus } from '@nelio-content/types'; /** * Internal dependencies */ import './style.scss'; import { store as NC_EDIT_POST } from '../../../store'; export type QualityAnalysisSummaryProps = { readonly label?: string; readonly onClick?: () => void; }; export const QualityAnalysisSummary = ( { onClick, label: proposedLabel, }: QualityAnalysisSummaryProps ): JSX.Element => { const status = useSelect( ( select ) => select( NC_EDIT_POST ).getOverallPostQualityStatus(), [] ); const label = proposedLabel || getDefaultLabel( status ); return (
{ 'perfect' === status && } { 'good' === status && } { 'improvable' === status && ( ) } { 'bad' === status && }
{ onClick ? ( ) : ( { label } ) }
); }; // ======= // HELPERS // ======= function getDefaultLabel( status: PostQualityStatus ) { switch ( status ) { case 'perfect': return createInterpolateElement( _x( 'The post looks awesome!', 'text', 'nelio-content' ), { strong: , } ); case 'good': return createInterpolateElement( _x( 'The post looks good!', 'text', 'nelio-content' ), { strong: , } ); case 'improvable': return createInterpolateElement( _x( 'The post is improvable', 'text', 'nelio-content' ), { strong: , } ); case 'bad': return createInterpolateElement( _x( 'The post is poor', 'text', 'nelio-content' ), { strong: , } ); default: return _x( 'Post can’t be evaluated', 'text', 'nelio-content' ); } }