<?php
/**
 * Panel section for configuring layout options
 *
 * @author jason.xie@victheme.com
 *
 */
class VTCore_Zeus_Panels_Layout
extends VTCore_Zeus_Panels_Model {

  /**
   * Panel content
   */
  public function buildElement() {

    $assistance = new VTCore_Zeus_Assistance();

    // Page width and style
    $this->panel = new VTCore_Bootstrap_Element_BsPanel(array(
        'id' => 'vtcore-zeus-layout-panel',
        'text' => __('Page Layout', BASE_THEME),
      ));

    $this->panel
      ->setChildrenPointer('heading')
      ->BsBadge(array(
        'attributes' => array(
          'class' => array(
            'pull-right',
          ),
        ),
      ))
      ->lastChild()
      ->Hyperlink(array(
        'text' => 'help',
        'attributes' => array(
          'href' => $assistance->getAssistanceItem('pagelayout', 'url'),
          'target' => $assistance->getAssistanceItem('pagelayout', 'target'),
          'data-title' => $assistance->getAssistanceItem('pagelayout', 'title'),
          'data-type' => $assistance->getAssistanceItem('pagelayout', 'type'),
          'data-toggle' => 'modal',
          'data-target' => '#vtcore-zeus-help-modal',
        ),
      ))
      ->getParent()
      ->setChildrenPointer('content')
      ->BsRow()
      ->lastChild()
      ->BsSelect(array(
        'text' => __('Maximum Width', BASE_THEME),
        'description' => __('Define the maximum page width for the theme.', BASE_THEME),
        'name' =>  'theme[features][options][page][maxwidth]',
        'value' => $this->getOption('page', 'maxwidth'),
        'options' => array('max-960' => '960px', 'max-1170' => '1170px', 'max-fluid' => __('Fluid', BASE_THEME)),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ))
      ->BsSelect(array(
        'text' => __('Page Style', BASE_THEME),
        'description' => __('Define the main styling for the theme page.', BASE_THEME),
        'name' =>  'theme[features][options][page][style]',
        'value' => $this->getOption('page', 'style'),
        'options' => array('style-normal' => __('Normal', BASE_THEME),  'style-boxed' => __('Boxed', BASE_THEME)),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ))
      ->BsSelect(array(
        'text' => __('Responsive', BASE_THEME),
        'description' => __('Define the if the page should be responsive or not.', BASE_THEME),
        'name' =>  'theme[features][options][page][responsive]',
        'value' => $this->getOption('page', 'responsive'),
        'options' => array('bs-responsive' => __('Responsive', BASE_THEME),  'bs-fixed' => __('Non Responsive', BASE_THEME)),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ));

    $this->processPanel();

    // Building the sidebar configuration
    $this->panel = new VTCore_Bootstrap_Element_BsPanel(array(
        'id' => 'vtcore-zeus-sidebar-panel',
        'text' => __('Sidebar Position', BASE_THEME),
      ));

    $this->panel
      ->setChildrenPointer('heading')
      ->BsBadge(array(
        'attributes' => array(
          'class' => array(
            'pull-right',
          ),
        ),
      ))
      ->lastChild()
      ->Hyperlink(array(
        'text' => 'help',
        'attributes' => array(
          'href' => $assistance->getAssistanceItem('sidebar_position_blog', 'url'),
          'target' => $assistance->getAssistanceItem('sidebar_position_blog', 'target'),
          'data-title' => $assistance->getAssistanceItem('sidebar_position_blog', 'title'),
          'data-type' => $assistance->getAssistanceItem('sidebar_position_blog', 'type'),
          'data-toggle' => 'modal',
          'data-target' => '#vtcore-zeus-help-modal',
        ),
      ))
      ->getParent()
      ->setChildrenPointer('content')
      ->BsRow()
      ->lastChild()
      ->BsSelect(array(
        'text' => __('Teaser Listing Page', BASE_THEME),
        'description' => __('This settings will be applied to all teasers listing pages', BASE_THEME),
        'name' =>  'theme[features][sidebars][teaser]',
        'value' => $this->getSidebar('teaser'),
        'options' => array(
          'none' => __('No Sidebar', BASE_THEME),
          'left' => __('Left', BASE_THEME),
          'right' => __('Right', BASE_THEME),
        ),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ))
      ->BsSelect(array(
        'text' => __('Single Post', BASE_THEME),
        'description' => __('This settings will be applied to post single page', BASE_THEME),
        'name' =>  'theme[features][sidebars][full]',
        'value' => $this->getSidebar('full'),
        'options' => array(
          'none' => __('No Sidebar', BASE_THEME),
          'left' => __('Left', BASE_THEME),
          'right' => __('Right', BASE_THEME),
        ),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ))
      ->BsSelect(array(
        'text' => __('Page 404', BASE_THEME),
        'description' => __('This settings will be applied to page 404 only.', BASE_THEME),
        'name' =>  'theme[features][sidebars][notfound]',
        'value' => $this->getSidebar('notfound'),
        'options' => array(
          'none' => __('No Sidebar', BASE_THEME),
          'left' => __('Left', BASE_THEME),
          'right' => __('Right', BASE_THEME),
        ),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ))
      ->BsSelect(array(
        'text' => __('Single Page', BASE_THEME),
        'description' => __('This settings will be applied to single page only.', BASE_THEME),
        'name' =>  'theme[features][sidebars][page]',
        'value' => $this->getSidebar('page'),
        'options' => array(
          'none' => __('No Sidebar', BASE_THEME),
          'left' => __('Left', BASE_THEME),
          'right' => __('Right', BASE_THEME),
        ),
        'attributes' => array(
          'class' => array(
            'clearboth'
          ),
        ),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ))
      ->BsSelect(array(
        'text' => __('Portfolio Teasers Listing Page', BASE_THEME),
        'description' => __('This settings will be applied to portfolio listing page and portfolio category taxonomy page.', BASE_THEME),
        'name' =>  'theme[features][sidebars][portfolio_teaser]',
        'value' => $this->getSidebar('portfolio_teaser'),
        'options' => array(
          'none' => __('No Sidebar', BASE_THEME),
          'left' => __('Left', BASE_THEME),
          'right' => __('Right', BASE_THEME),
        ),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ))
      ->BsSelect(array(
        'text' => __('Portfolio Single Page', BASE_THEME),
        'description' => __('This settings will be applied to portfolio single page only.', BASE_THEME),
        'name' =>  'theme[features][sidebars][portfolio_full]',
        'value' => $this->getSidebar('portfolio_full'),
        'options' => array(
          'none' => __('No Sidebar', BASE_THEME),
          'left' => __('Left', BASE_THEME),
          'right' => __('Right', BASE_THEME),
        ),
        'grids' => array(
          'columns' => array(
            'mobile' => 12,
            'tablet' => 4,
            'small' => 4,
            'large' => 4,
          ),
        ),
      ));

    $this->processPanel();

      // Building the layout configuration per area and per region
    foreach ($this->getContext('layout')->getChildrens() as $area) {

      $this->panel = new VTCore_Bootstrap_Element_BsPanel(array(
          'id' => 'vtcore-zeus-area-' . str_replace(array(' ', '_'), '-', $area->getContext('id')) .'-panel',
          'text' => sprintf(__('%s Column Grid', BASE_THEME), $area->getContext('name')),
        ));

      $this->panel
        ->setChildrenPointer('heading')
        ->BsBadge(array(
          'attributes' => array(
            'class' => array(
              'pull-right',
            ),
          ),
        ))
        ->lastChild()
        ->Hyperlink(array(
          'text' => 'help',
          'attributes' => array(
            'href' => $assistance->getAssistanceItem('layout_' . $area->getContext('id'), 'url'),
            'target' => $assistance->getAssistanceItem('layout_' . $area->getContext('id'), 'target'),
            'data-title' => $assistance->getAssistanceItem('layout_' . $area->getContext('id'), 'title'),
            'data-type' => $assistance->getAssistanceItem('layout_' . $area->getContext('id'), 'type'),
            'data-toggle' => 'modal',
            'data-target' => '#vtcore-zeus-help-modal',
          ),
        ))
        ->getParent()
        ->setChildrenPointer('content')
        ->BsDescription(array(
          'text' => $area->getContext('description'),
        ))
        ->BsRow();


      $regions = $area->getChildrens();
      $grid = 12 / count($regions);

      if (count($regions) < 2) {
        continue;
      }

      // Don't attempt to stringify the regions!
      // It will break validation.
      foreach ($regions as $region) {
        $this->panel
          ->lastChild()
          ->BsColumn(array(
            'grids' => array(
              'columns' => array(
                'mobile' => 12,
                'tablet' => $grid,
                'small' => $grid,
                'large' => $grid,
              ),
            ),
          ))
          ->lastChild()
          ->addChildren(new VTCore_Bootstrap_Form_BsGrids(array(
            'name' =>  'theme[regions][' . $region->getContext('arguments.id') . '][grids]',
            'columns' => array(
              'text' => sprintf(__('%s Region', BASE_THEME), $region->getContext('arguments.name')),
            ),
            'value' => $region->getContext('grids'),
            'element_grids' => array(
              'columns' => array(
                'mobile' => '12',
                'tablet' => '12',
                'small' => '12',
                'large' => '12',
              ),
            ),
          )));

      }

      $this->processPanel();
    }

  }

}