<?php
namespace SabaiApps\Directories\Component\Display\Statistic;

use SabaiApps\Directories\Application;
use SabaiApps\Directories\Component\Entity\Model\Bundle;

abstract class AbstractStatistic implements IStatistic {

	protected $_application, $_name, $_info;

	public function __construct( Application $application, $name ) {
		$this->_application = $application;
		$this->_name        = $name;
	}

	public function displayStatisticInfo( Bundle $bundle, $key = null ) {
		if ( ! isset( $this->_info ) ) {
			if ( ! $info = $this->_displayStatisticInfo( $bundle ) ) {
				return;
			}

			$this->_info = (array) $info;
		}

		return isset( $key ) ? ( isset( $this->_info[ $key ] ) ? $this->_info[ $key ] : null ) : $this->_info;
	}

	public function displayStatisticSettingsForm( Bundle $bundle, array $settings, array $parents = array(), $type = 'icon' ) {}

	abstract protected function _displayStatisticInfo( Bundle $bundle );

	public function displayStatisticIsPreRenderable( Bundle $bundle, array $settings ) {
		return false;
	}

	public function displayStatisticPreRender( Bundle $bundle, array $settings, array $entities = array() ) {}
}
