<?php

declare(strict_types=1);

namespace Drupal\flowdrop_playground\Hook;

use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Hook implementations for the flowdrop_playground module.
 *
 * @internal This class is not part of the public API and may change without notice.
 */
final class PlaygroundHooks {

  /**
   * Constructs a new PlaygroundHooks object.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
   *   The current route match.
   */
  public function __construct(
    protected readonly RouteMatchInterface $routeMatch,
  ) {}

  /**
   * Implements hook_theme().
   */
  #[Hook('theme')]
  public function theme(): array {
    return [
      'flowdrop_playground_page' => [
        'variables' => [
          'workflow' => NULL,
          'session' => NULL,
          'messages' => [],
        ],
      ],
      'html__flowdrop_playground_fullscreen' => [
        'render element' => 'elements',
        'base hook' => 'html',
        'template' => 'html--flowdrop-playground-fullscreen',
      ],
      'page__flowdrop_playground' => [
        'render element' => 'elements',
        'base hook' => 'page',
        'template' => 'page--flowdrop-playground',
      ],
    ];
  }

  /**
   * Implements hook_theme_suggestions_html_alter().
   *
   * Suggests a fullscreen HTML template for the playground page route.
   * This removes Drupal's default page chrome (toolbar, admin menu, etc.)
   * to provide an immersive fullscreen experience.
   */
  #[Hook('theme_suggestions_html_alter')]
  public function themeSuggestionsHtmlAlter(array &$suggestions, array $variables): void {
    $route_name = $this->routeMatch->getRouteName();
    if ($route_name === 'flowdrop_playground.page') {
      $suggestions[] = 'html__flowdrop_playground_fullscreen';
    }
  }

  /**
   * Implements hook_theme_suggestions_page_alter().
   *
   * Suggests a minimal page template for the playground route.
   * This renders only the content without local actions, breadcrumbs, etc.
   */
  #[Hook('theme_suggestions_page_alter')]
  public function themeSuggestionsPageAlter(array &$suggestions, array $variables): void {
    $route_name = $this->routeMatch->getRouteName();
    if ($route_name === 'flowdrop_playground.page') {
      $suggestions[] = 'page__flowdrop_playground';
    }
  }

}
