<?php
namespace Hecate\Controls\Sections\TabSection;

use Hecate\Components\ComponentBase;
use Hecate\Controls\Components\BaseControl;

/**
 * The tab contains a list of accordions. The controls are found inside the accordions.
 */
abstract class BaseTabSection {
	protected $type;

	/**
	 * @var ComponentBase
	 */
	protected $component;

	/**
	 * @param ComponentBase $component
	 */
	public function __construct( $component ) {
		$this->component = $component;
	}

	/**
	 * This will contain the accordions of the section. It will get overwritten by the descendants of this class.
	 * @return SectionAccordion[]
	 */
	abstract public function getSectionAccordionsClasses();

	/**
	 * @return BaseControl[] returns the controls found in all the accordions of the current tab
	 */
	public function getControls() {
		$controls          = array();
		$accordionsClasses = $this->getSectionAccordionsClasses();
		foreach ( $accordionsClasses as $accordionClass ) {
			$accordion = new $accordionClass( $this->component, $this->type );
			$controls  = array_merge( $controls, $accordion->getControls() );
		}
		return $controls;
	}
}
