<?php
namespace SabaiApps\Directories\Component\WordPressContent\DisplayStatistic;

use SabaiApps\Directories\Component\Display;
use SabaiApps\Directories\Component\Entity;
use SabaiApps\Directories\Component\Entity\Model\Bundle;
use SabaiApps\Directories\Component\Entity\Type\IEntity;

class CommentsDisplayStatistic extends Display\Statistic\AbstractStatistic {

	protected function _displayStatisticInfo( Bundle $bundle ) {
		return array(
			'label'            => __( 'Comment count', 'directories-pro' ),
			'default_settings' => array(
				'_icon' => 'far fa-comment',
			),
			'iconable'         => true,
		);
	}

	public function displayStatisticRender( Bundle $bundle, IEntity $entity, array $settings ) {
		return array(
			'number' => $count = ( $_count = wp_count_comments( $entity->getId() ) ) ? $_count->approved : 0,
			'format' => _n( '%d comment', '%d comments', $count, 'directories-pro' ),
		);
	}
}
