<?php
namespace SabaiApps\Directories\Component\Voting\Type;

class RatingType extends AbstractType {

	protected function _votingTypeInfo() {
		return array(
			'label'                   => __( 'Ratings', 'directories-pro' ),
			'label_field'             => __( 'Rating', 'directories-pro' ),
			'label_sort'              => __( 'Rating', 'directories-pro' ),
			'label_action'            => _x( 'Rate', 'action', 'directories-pro' ),
			'label_unaction'          => _x( 'Unstar', 'action', 'directories-pro' ),
			'label_statistic'         => __( 'Rating count', 'directories-pro' ),
			'icon'                    => 'far fa-star',
			'icon_active'             => 'fas fa-star',
			'min'                     => 1,
			'max'                     => 5,
			'step'                    => 0.1,
			'allow_empty'             => false,
			'allow_anonymous'         => true,
			'require_permission'      => true,
			'require_down_permission' => false,
			'require_own_permission'  => true,
			'permission_label'        => __( 'Rate %s', 'directories-pro' ),
			'own_permission_label'    => __( 'Rate own %s', 'directories-pro' ),
			'entity_statistic'        => true,
			'vote_table_headers'      => array(
				'author'  => __( 'User', 'directories-pro' ),
				'created' => __( 'Date', 'directories-pro' ),
				'value'   => __( 'Rating', 'directories-pro' ),
			),
		);
	}

	public function votingTypeFormat( array $value, $format = null ) {
		switch ( $format ) {
			case 'num':
				return $value['count'];
			case 'column':
				return sprintf( '%d (%04.2f)', $value['count'], $value['average'] );
			default:
				return $this->_application->H( _n( '%d rating', '%d ratings', $value['count'], 'directories-pro' ) );
		}
	}
}
