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

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

class CustomIcon extends AbstractIcon {

	protected function _displayIconInfo( Bundle $bundle ) {
		$info = array(
			'label'            => __( 'Custom icon', 'directories-pro' ),
			'default_settings' => array(
				'conditions' => array(),
			),
		);
		foreach ( $this->_application->Filter( 'entity_icon_custom_icon_num', range( 1, 3 ), array( $bundle ) ) as $num ) {
			$info['multiple'][ $num ] = array(
				'default_checked' => $num === 1,
				'label'           => sprintf( __( 'Custom icon #%d', 'directories-pro' ), $num ),
			);
		}
		return $info;
	}

	public function displayIconSettingsForm( Bundle $bundle, array $settings, Display $display, array $parents = array() ) {
		$form = array(
			'conditions' => $this->_application->Entity_Field_conditionSettingsForm(
				$bundle->name,
				empty( $settings['conditions'] ) ? array() : $settings['conditions'],
				array_merge( $parents, array( 'conditions' ) ),
				true
			),
		);

		return $form;
	}

	public function displayIconOutput( Bundle $bundle, IEntity $entity, array $settings ) {
		if ( ! empty( $settings['conditions'] )
			&& ! $this->_application->Entity_Field_checkConditions( $settings['conditions'], $entity )
		) {
			return;
		}

		return ! empty( $settings['_icon'] );
	}
}
