<?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 StatusDisplayLabel extends Display\Label\AbstractLabel {

	protected function _displayLabelInfo( Bundle $bundle ) {
		if ( $bundle->entitytype_name !== 'post'
			|| empty( $bundle->info['public'] )
		) {
			return false;
		}

		return array(
			'label'            => __( 'Content status label', 'directories-pro' ),
			'default_settings' => array(),
			'labellable'       => false,
			'colorable'        => false,
		);
	}

	public function displayLabelText( Bundle $bundle, IEntity $entity, array $settings ) {
		if ( ( ! $status = $entity->getStatus() )
			|| ( ! $label = $this->_application->Entity_Types_impl( $entity->getType() )->entityTypeEntityStatusLabel( $status ) )
		) {
			return;
		}

		if ( $entity->isPublished() ) {
			$color = 'success';
		} elseif ( $entity->isPending() ) {
			$color = 'warning';
		} else {
			$color = 'secondary';
		}

		return array(
			'label' => $label,
			'color' => array( 'name' => $color ),
		);
	}
}
