<?php

declare(strict_types=1);

namespace Drupal\farm_plant_type\Hook;

use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Hook\Attribute\Hook;

/**
 * Theme hook implementations for farm_plant_type.
 */
class ThemeHooks {

  /**
   * Implements hook_entity_form_display_alter().
   */
  #[Hook('entity_form_display_alter')]
  public function entityFormDisplayAlter(EntityFormDisplayInterface $form_display, array $context) {
    if ($context['entity_type'] == 'taxonomy_term' && $context['bundle'] == 'plant_type' && $form_display->getMode() == 'default' && $form_display->isNew()) {
      $form_display->setComponent('crop_family', [
        'type' => 'entity_reference_autocomplete',
        'settings' => [
          'match_operator' => 'CONTAINS',
          'match_limit' => 10,
          'size' => 60,
          'placeholder' => '',
        ],
        'region' => 'content',
        'weight' => 10,
      ]);
      $form_display->setComponent('maturity_days', [
        'type' => 'number',
        'settings' => [
          'placeholder' => '',
        ],
        'region' => 'content',
        'weight' => 20,
      ]);
      $form_display->setComponent('harvest_days', [
        'type' => 'number',
        'settings' => [
          'placeholder' => '',
        ],
        'region' => 'content',
        'weight' => 30,
      ]);
      $form_display->setComponent('companions', [
        'type' => 'entity_reference_autocomplete',
        'settings' => [
          'match_operator' => 'CONTAINS',
          'match_limit' => 10,
          'size' => 60,
          'placeholder' => '',
        ],
        'region' => 'content',
        'weight' => 40,
      ]);
    }
  }

  /**
   * Implements hook_entity_view_display_alter().
   */
  #[Hook('entity_view_display_alter')]
  public function entityViewDisplayAlter(EntityViewDisplayInterface $display, array $context) {
    if ($context['entity_type'] == 'taxonomy_term' && $context['bundle'] == 'plant_type' && $display->getMode() == 'full' && $display->isNew()) {
      $display->setComponent('crop_family', [
        'type' => 'entity_reference_label',
        'label' => 'inline',
        'settings' => [
          'link' => TRUE,
        ],
        'region' => 'content',
        'weight' => 10,
      ]);
      $display->setComponent('maturity_days', [
        'type' => 'number_integer',
        'label' => 'inline',
        'settings' => [
          'thousand_separator' => '',
          'prefix_suffix' => TRUE,
        ],
        'region' => 'content',
        'weight' => 20,
      ]);
      $display->setComponent('harvest_days', [
        'type' => 'number_integer',
        'label' => 'inline',
        'settings' => [
          'thousand_separator' => '',
          'prefix_suffix' => TRUE,
        ],
        'region' => 'content',
        'weight' => 30,
      ]);
      $display->setComponent('companions', [
        'type' => 'entity_reference_label',
        'label' => 'inline',
        'settings' => [
          'link' => TRUE,
        ],
        'region' => 'content',
        'weight' => 40,
      ]);
    }
  }

}
