<?php

/**
 * @file
 * Functions to support theming modules in the Toc Master theme.
 */

use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Template\Attribute;
use Drupal\image\Entity\ImageStyle;

/**
 * Implements hook_form_alter().
 *
 * Trainline suite booking - Desktop and exposed form.
 */
function toc_emr_preprocess_tls_booking_form(&$vars) {
  // Simply override the button style for the form.
  $vars['el']['button_type'] = 'btn-default';
  $vars['el']['chip_icon'] = 'far fa-check-circle';
}

function toc_emr_preprocess_tls_booking_widget(&$vars) {
  // Simply override the button style for the form.
  $vars['button_type'] = 'btn-default';
  $vars['el']['chip_icon'] = 'far fa-check-circle';
}

/**
 * Preprocess for toc_best_fares_block_content().
 *
 * @param array $vars
 *   Theme variables.
 */
function toc_emr_preprocess_toc_best_fares_block_content(array &$vars) {
  $vars['icon'] = 'fas fa-ticket-alt';
  $vars['tickets'] = _tm_misc_fares_direction_string($vars['tickets'], 'one-way', 'return');
}

/**
 * Preprocess for route_information_block().
 *
 * @param array $vars
 *   Theme variables.
 */
function toc_emr_preprocess_cheapest_ticket_types_block(array &$vars) {
  $vars["button_status"] = 'primary';
}

/**
 * Preprocess hook for all card_blocks.
 */
function toc_emr_preprocess_card_block__front_bottom(&$vars) {
  if (!empty($vars['items'])) {
    foreach ($vars['items'] as $delta => $item) {
      /**  @var Drupal\eck\Entity\EckEntity $block */
      $block = $item['#card_block'];
      $block->__set('card_class', "plain-card cbelianr plain-card-alt");
      $vars['items'][$delta]['#card_block'] = $block;
    }
  }
}
