<?php
namespace SabaiApps\Directories\Component\Entity\DisplayLabel;

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

class NewEntityDisplayLabel extends Display\Label\AbstractLabel {

	protected function _displayLabelInfo( Bundle $bundle ) {
		return array(
			'label'            => __( 'New item label', 'directories-pro' ),
			'default_settings' => array(
				'days'   => 1,
				'_label' => __( 'New', 'directories-pro' ),
				'_color' => array( 'type' => 'danger' ),
			),
		);
	}

	public function displayLabelSettingsForm( Bundle $bundle, array $settings, array $parents = array() ) {
		return array(
			'days' => array(
				'#type'          => 'slider',
				'#title'         => __( 'Show if publish date is within last X days', 'directories-pro' ),
				'#default_value' => $settings['days'],
				'#min_value'     => 1,
				'#max_value'     => 100,
				'#horizontal'    => true,
			),
		);
	}

	public function displayLabelText( Bundle $bundle, IEntity $entity, array $settings ) {
		$days = ( ! $settings['days'] = (int) $settings['days'] ) ? 1 : $settings['days'];
		if ( ( ! $ts = $entity->getTimestamp() )
			|| ( time() - $ts >= $days * 86400 )
		) {
			return;
		}

		return array(
			'label' => $settings['_label'],
			'color' => $settings['_color'],
		);
	}
}
