<?php

declare(strict_types=1);

namespace Drupal\flowdrop;

use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;

/**
 * Provides a listing of trusted workflow-bundle publishers.
 *
 * @internal
 *   This class is not part of the public API and may change without notice.
 */
final class FlowDropTrustedPublisherListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   *
   * @return array<string, mixed>
   *   The table header.
   */
  public function buildHeader(): array {
    $header['label'] = $this->t('Publisher');
    $header['id'] = $this->t('Key ID');
    $header['enabled'] = $this->t('Status');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   *
   * @return array<string, mixed>
   *   The table row.
   */
  public function buildRow(EntityInterface $entity): array {
    /** @var \Drupal\flowdrop\FlowDropTrustedPublisherInterface $entity */
    $row['label'] = $entity->label();
    $row['id'] = $entity->id();
    $row['enabled'] = $entity->isEnabled() ? $this->t('Enabled') : $this->t('Disabled');
    return $row + parent::buildRow($entity);
  }

}
