<?php
namespace SabaiApps\Directories\Component\View\Mode;

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

class TableMode extends AbstractMode {

	protected function _viewModeInfo() {
		return array(
			'label'            => _x( 'Table', 'view mode label', 'directories-pro' ),
			'default_settings' => array(
				'template'    => 'view_entities_table',
				'display'     => 'row',
				'table_color' => 'primary',
			),
			'default_display'  => 'row',
			'displays'         => array(
				'row' => array(
					'label'  => _x( 'Table Row', 'display name', 'directories-pro' ),
					'weight' => 2,
				),
			),
			'mapable'          => true,
		);
	}

	public function viewModeSupports( Bundle $bundle ) {
		return parent::viewModeSupports( $bundle ) && ! empty( $bundle->info['public'] );
	}

	public function viewModeSettingsForm( Bundle $bundle, array $settings, array $parents = array() ) {
		return array(
			'table_color' => array(
				'#type'             => 'radios',
				'#title'            => __( 'Table color', 'directories-pro' ),
				'#options'          => array( '' => __( 'None', 'directories-pro' ) ) + $this->_application->System_Color_options( array( 'as_background' => true ) ),
				'#option_no_escape' => true,
				'#horizontal'       => true,
				'#default_value'    => $settings['table_color'],
				'#columns'          => 3,
			),
		);
	}

	public function viewModeNav( Bundle $bundle, array $settings ) {
		return array(
			array(
				'margin' => 0,
				'color'  => $color = empty( $settings['table_color'] ) ? null : $settings['table_color'],
				array( array( 'search', 'filter' ), array(), array( 'sort', 'add' ) ),
				array( array( 'filters' ) ),
			), // header
			array(
				'margin' => 0,
				'color'  => $color,
				array( array(), array(), array() ),
				array( array( 'num' ), array(), array( 'perpages', 'pagination' ) ),
			), // footer
		);
	}
}
