<?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_wmr_preprocess_tls_booking_form(&$vars) {
  // Simply override the button style for the form.
  $vars['el']['button_type'] = 'btn-default';
}

function toc_wmr_preprocess_tls_booking_widget(&$vars) {
  // Simply override the button style for the form.
  $vars['button_type'] = 'btn-default';
}

/**
 * Preprocess for toc_best_fares_block_content().
 *
 * @param array $vars
 *   Theme variables.
 */
function toc_wmr_preprocess_toc_best_fares_block_content(array &$vars) {
  $vars["status"] = 'outline-default';
}

/**
 * Preprocess for toc_wmr_preprocess_page_banner_random().
 */
function toc_wmr_preprocess_page_banner_random(array &$vars) {
  // Use the original image size for the bookend style banner overlay.
  $overlay_image_mid = $vars['element']['config']['overlay_image'] ?? 0;
  if ($overlay_image_mid) {
    $overlay_image = _tm_misc_get_styled_images_from_media($overlay_image_mid, '', 'field_media_image', 'media', 'image', 'poly-over crsl-img');
    if ($overlay_image) {
      $vars['element']['overlay'] = $overlay_image;
    }
  }
}

function toc_wmr_preprocess_journey_check_summary_status(array &$vars) {
  $vars['element']->setStatusText('Travel updates');
}

/**
 * Preprocess hook for link blocks - Advanced tickets with latest news.
 */
function toc_wmr_preprocess_link_block__latest_news_header(&$vars) {
  $template_vars = [
    'link_scope' => 'title',
    'block_class' => 'bl-vl cbelianr flex-fill mb-1',
    'header_tag' => 'h2',
    'readmore' => 'More news',
    'readmore_icon_right' => 'fas fa-chevron-right',
  ];
  _toc_master_preprocess_link_block($vars, $template_vars);
}

/**
 * Preprocess hook for link blocks - Advanced tickets with latest news.
 */
function toc_wmr_preprocess_link_block__adv_tickets_latest_news(&$vars) {
  $template_vars = [
    'link_scope' => 'block',
    'block_class' => 'bl-vk cbelianr flex-fill',
    'header_tag' => 'h3',
  ];
  _toc_master_preprocess_link_block($vars, $template_vars);
}
