<?php
/**
 * Action Column
 * 
 * Special Column where actions can be easely defined
 * 
 * @author Visual Media 
 */

namespace VisualM\ManagementBundle\AdminList\Column;

use VisualM\ManagementBundle\AdminList\Column\ColumnConfigurationAbstract;
use VisualM\ManagementBundle\AdminList\Column\ColumnConfigurationInterface;
use VisualM\ManagementBundle\AdminList\Column\Action\ActionInterface;
use Exception;

/**
 * Action Column
 *
 * @author Visual Media 
 */
class ActionsColumn extends ColumnConfigurationAbstract implements ColumnConfigurationInterface
{
    /**
     * Actions
     * @var array
     */
    protected $primaryActions;

    /**
     * Actions
     * @var array
     */
    protected $actions;

    /**
     * Drop Down Alignment
     * @var string
     */
    protected $dropdownAlign;

    /**
     * Constructor
     * 
     * @param string $field         Field (null for no field binding)
     * @param string $title         Title
     * @param array  $actions       Actions
     * @param string $dropDownAlign Drop Down Alignment
     */
    public function __construct($field, $title, $actions = array(), $dropdownAlign = 'right')
    {
        foreach($actions as $action) {
            if (!($action instanceof ActionInterface)) {
                throw new Exception("Action should be an implementation of ActionInterface");
            }
        }
        
        $this->primaryActions = [];
        $this->actions = [];
        $this->dropdownAlign = $dropdownAlign;
        
        foreach($actions as $action) {
            if ($action->isPrimaryAction()) {
                $this->primaryActions[] = $action;
            } else {
                $this->actions[] = $action;
            }
        }
        
        parent::__construct(
            $field,
            $title,
            false, 
            'VisualMManagementBundle:AdminList:Column/Actions/listItem.html.twig', 
            'VisualMManagementBundle:AdminList:Column/Actions/listHeader.html.twig',
            null
        );
    }

    /**
     * Get Actions
     * 
     * @return array Actions
     */
    public function getPrimaryActions()
    {
        return $this->primaryActions;
    }

    /**
     * Get Actions
     *
     * @return array Actions
     */
    public function getActions()
    {
        return $this->actions;
    }

    /**
     * Drop Down Alignment
     *
     * @return string Drop Down Alignment
     */
    public function getDropDownAlign()
    {
        return $this->dropdownAlign;
    }

    
}