import { useBlockProps } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; import { __, sprintf, _n } from '@wordpress/i18n'; import { store as coreStore } from '@wordpress/core-data'; import type { Post, Updatable } from '@wordpress/core-data'; import { usePostCommentsCount } from '../utils/hooks'; import type { PostCommentsLinkBlockContext } from './types'; function PostCommentsLinkEdit( { context, }: { context: PostCommentsLinkBlockContext; } ) { const { postType, postId } = context; const { totalItems: commentsCount } = usePostCommentsCount( postId ); const blockProps = useBlockProps(); const post = useSelect( ( select ) => select( coreStore ).getEditedEntityRecord( 'postType', postType!, postId! ) as Updatable< Post > | undefined, [ postType, postId ] ); let commentsText: string | undefined; if ( commentsCount !== null ) { const commentsNumber = parseInt( String( commentsCount ) ); if ( commentsNumber === 0 ) { commentsText = __( 'No comments' ); } else { commentsText = sprintf( /* translators: %s: Number of comments */ _n( '%s comment', '%s comments', commentsNumber ), commentsNumber.toLocaleString() ); } } return (