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

function toc_lnr_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_lnr_preprocess_toc_best_fares_block_content(array &$vars) {
  $vars["card_button_status"] = 'primary';
  $vars["status"] = 'default';
}

/**
 * Preprocess for page_banner_random().
 */
function toc_lnr_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;
    }
  }
}

/**
 * Preprocess for journey_check_latest_incidents_block().
 */
function toc_lnr_preprocess_journey_check_latest_incidents_block(&$vars) {
  $message = $vars['element']['message'];
  $num_incidents = $vars['element']['num_incidents'];
  if (!$num_incidents) {
    $content = $message;
  }
  else {
    $content = [
      '#theme' => 'status_messages',
      '#message_list' => [
        'default' => [
          $message
        ],
      ],
      '#status_headings' => [
        'default' => FALSE,
      ],
    ];
  }
  $vars['content'] = $content;
}

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

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