<?php

namespace Hecate\Components\Column;

use Hecate\Components\ComponentBase;
use Hecate\Components\ComponentContainerBase;
use Hecate\Components\ComponentMods;

class ColumnComponent extends ComponentContainerBase {

	public static $type         = 'column';
	protected static $rootClass = 'hecate-column';
	protected static $template  = 'components/column';

	public function getExtraWrapperClasses() {
        $classes = $this->getWidthClasses();

        $classes[] = $this->getComponentIdClass();
		if ( ! $this->hasChildren() ) {
			$classes[] = 'd-none';
		}
		return $classes;
	}

	public function getOuterClasses() {
		$classes = $this->getWidthClasses();

		$classes[] = 'd-flex';
		if ( ! $this->hasChildren() ) {
			$classes[] = 'd-none';
		}

		return $classes;
	}

	public function getDirectionClasses() {
		$direction = $this->getAttribute( 'direction' );
		$classes   = array( $direction );
		return $classes;
	}


	public function hasChildren() {
		$componentId = $this->componentId;
		$childrenIds = ComponentMods::getChildrenIds( $componentId );
		return count( $childrenIds ) !== 0;
	}
	public function getExtraRootClasses() {
		$classes = array( 'd-flex' );
		if ( $this->renderFromFrontend ) {
			$classes = array_merge( $classes, $this->getOuterClasses() );
		}
		return $classes;
	}

	public function getInnerClasses() {
		$classes = $this->getDirectionClasses();
		return implode( ' ', $classes );
	}

	public function getWidthClasses() {
		$widthType    = $this->getAttribute( 'width' );
		$widthClasses = array();
		switch ( $widthType ) {
			case 'auto':
				$widthClasses[] = 'col';
				break;
			case 'fitToContent':
				$widthClasses[] = 'col-auto';
				break;
		}

		return $widthClasses;
	}

	public function getSections() {
		return array(
			array(
				'id'            => $this->getSectionId(),
				'title'         => __( 'Column', 'hecate' ),
				'hiddenSection' => true,
				'panel'         => $this->getCurrentPanel(),
				'type'          => 'hecate-tab-section',
				'priority'      => 1,
			),
		);
	}
	public function getOverlayClasses() {
		return array( 'hecate-component-overlay--column' );
	}
}

