<?php

/**
 * @file
 * Functions to support theming in the sobki_theme_bootstrap theme.
 */

declare(strict_types=1);

use Drupal\Core\Form\FormStateInterface;
use Drupal\sobki_theme_bootstrap\HookHandler\ElementInfoAlter;
use Drupal\sobki_theme_bootstrap\HookHandler\FormSystemThemeSettingsAlter;
use Drupal\sobki_theme_bootstrap\HookHandler\LibraryInfoAlter;
use Drupal\sobki_theme_bootstrap\HookHandler\PreprocessBreadcrumb;
use Drupal\sobki_theme_bootstrap\HookHandler\PreprocessLinksLanguageBlock;
use Drupal\sobki_theme_bootstrap\HookHandler\PreprocessMenu;
use Drupal\sobki_theme_bootstrap\HookHandler\PreprocessMoreLink;

/**
 * Implements hook_element_info_alter().
 */
function sobki_theme_bootstrap_element_info_alter(array &$info): void {
  /** @var \Drupal\sobki_theme_bootstrap\HookHandler\ElementInfoAlter $instance */
  $instance = \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(ElementInfoAlter::class);
  $instance->alter($info);
}

/**
 * Implements hook_form_FORM_ID_alter() for 'system_theme_settings'.
 */
function sobki_theme_bootstrap_form_system_theme_settings_alter(array &$form, FormStateInterface $form_state): void {
  /** @var \Drupal\sobki_theme_bootstrap\HookHandler\FormSystemThemeSettingsAlter $instance */
  $instance = \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(FormSystemThemeSettingsAlter::class);
  $instance->alter($form, $form_state);
}

/**
 * Implements hook_library_info_alter().
 */
function sobki_theme_bootstrap_library_info_alter(array &$libraries, string $extension): void {
  /** @var \Drupal\sobki_theme_bootstrap\HookHandler\LibraryInfoAlter $instance */
  $instance = \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(LibraryInfoAlter::class);
  $instance->alter($libraries, $extension);
}

/**
 * Implements hook_preprocess_HOOK() for 'breadcrumb'.
 */
function sobki_theme_bootstrap_preprocess_breadcrumb(array &$variables): void {
  /** @var \Drupal\sobki_theme_bootstrap\HookHandler\PreprocessBreadcrumb $instance */
  $instance = \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(PreprocessBreadcrumb::class);
  $instance->preprocess($variables);
}

/**
 * Implements hook_preprocess_HOOK() for 'container__more_link'.
 */
function sobki_theme_bootstrap_preprocess_container__more_link(array &$variables): void {
  /** @var \Drupal\sobki_theme_bootstrap\HookHandler\PreprocessMoreLink $instance */
  $instance = \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(PreprocessMoreLink::class);
  $instance->preprocessContainer($variables);
}

/**
 * Implements hook_preprocess_HOOK() for 'links__language_block'.
 */
function ui_suite_bootstrap_preprocess_links__language_block(array &$variables): void {
  /** @var \Drupal\sobki_theme_bootstrap\HookHandler\PreprocessLinksLanguageBlock $instance */
  $instance = \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(PreprocessLinksLanguageBlock::class);
  $instance->preprocess($variables);
}

/**
 * Implements hook_preprocess_HOOK() for 'menu'.
 */
function sobki_theme_bootstrap_preprocess_menu(array &$variables): void {
  /** @var \Drupal\sobki_theme_bootstrap\HookHandler\PreprocessMenu $instance */
  $instance = \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(PreprocessMenu::class);
  $instance->preprocess($variables);
}
