<?php

declare(strict_types=1);

namespace Drupal\dc_core\Plugin\Block;

use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;

#[Block(
  id: "characters_block",
  admin_label: new TranslatableMarkup("LOTR Characters"),
  category: new TranslatableMarkup("DC Core")
)]
final class CharactersBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build(): array {
    $path = 'public://api-responses/characters.json';
    $characters = json_decode(file_get_contents($path), TRUE);

    $build = [
      '#theme' => 'lotr_characters',
      '#characters' => $characters,
    ];

    return $build;
  }

}
