<?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) {
  $vars['el']['button_type'] = 'btn-default';
  $vars['el']['chip_icon'] = 'far fa-check-circle';
}
function toc_emr_preprocess_tls_booking_widget(&$vars) {
  $vars['button_type'] = 'btn-default';
  $vars['el']['chip_icon'] = 'far fa-check-circle';
}
function toc_emr_preprocess_tls_booking_form_exposed_alternative(&$vars) {
  $vars['el']['button_type'] = 'btn-default';
  $vars['el']['button_class'] = 'mb-3 p-2 px-3 rounded-3 w-100';
  $vars['el']['button_size'] = 'btn-lg';
}

/**
 * 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"] = 'default';
}

/**
 * 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;
    }
  }
}

/**
 * Preprocess for interstitial_messages_modal().
 */
function toc_emr_preprocess_interstitial_messages_modal(&$vars) {
  $vars['confirm_button_type'] = 'default';
}

/**
 * Preprocess for journey_check_updates_items().
 */
function toc_emr_preprocess_journey_check_updates_items(&$vars) {
  $vars['cutoff'] = 6;
  $vars['item_name'] = 'announcements';
}
