<?php

use Drupal\Core\Url;

function template_preprocess_edlp_home(&$vars){
  $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
  // dpm($vars);

  // render the presentation column
  $vars["presentation"] = array(
    "#type"=>"container",
    "pres"=>$view_builder->view($vars["presentation_node"], 'default'),
    "link"=> array(
      '#title' => t('Visiter la collection sonore.'),
      '#type' => 'link',
      '#url' => Url::fromRoute('<front>', [], array(
        'attributes' => array(
          'class' => ['corpus-link', 'ajax-link']
        )
      ))
    )
  );

  // render the last fil column
  $vars["last_fil"] = array(
    "#type" => "container",
    // 'fil' => $view_builder->view($vars['last_fil_node'], 'teaser'),
    'title'=> array("#markup" => "<h2 class='title'>Dernier Fil</h2>"),
    'fil' => $vars['last_fil_node'],
    // 'links' => array(
    //   '#theme' => 'item_list',
    //   '#items' => array(
    //     'link_all' => array(
    //       '#title' => t("Voir tous les fils de l'EP."),
    //       '#type' => 'link',
    //       '#url' => Url::fromRoute('edlp_fils.fils', [], array(
    //         'attributes' => array(
    //           'class' => ['fils-link', 'ajax-link']
    //         )
    //       ))
    //     ),
    //     // TODO: link posdcast fils
    //     'link_podcast' => array(
    //       '#title' => t("S'abonner au podcast des fils."),
    //       '#type' => 'link',
    //       '#url' => Url::fromRoute('<front>', [], array(
    //         'attributes' => array(
    //           'class' => ['fils-link']
    //         )
    //       ))
    //     )
    //   )
    // )
  );

  // render the last production column
  $vars["last_production"] = array(
    '#type' => 'container',
    'prod' => $view_builder->view($vars['last_production_node'], 'teaser'),
    'link'=> array(
      '#title' => t('Voir toutes les productions.'),
      '#type' => 'link',
      '#url' => Url::fromRoute('edlp_productions.productions', [], array(
        'attributes' => array(
          'class' => ['productions-link', 'ajax-link']
        )
      ))
    )
  );

  // render the next events of agenda as list
  $agenda = array (
    '#theme' => 'item_list',
    '#items' => [],
  );
  foreach($vars['agenda_items'] as $node){
    $agenda['#items'][] = $view_builder->view($node, 'teaser');
  }
  $vars['agenda'] = render($agenda);

}
