<?php

declare(strict_types=1);

namespace Drupal\ffmpeg_media\Form\SettingsTab;

use Drupal\Core\Config\Config;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
 * Builds the manifest settings tab for the FFmpeg Media settings form.
 *
 * @internal
 */
final class ManifestSettingsBuilder {

  use StringTranslationTrait;

  /**
   * Builds the manifest section render array.
   *
   * @param array<string, mixed> $form
   *   Form structure, passed by reference.
   * @param \Drupal\Core\Config\Config $config
   *   Module configuration.
   */
  public function build(array &$form, Config $config): void {
    $form['manifest'] = [
      '#type' => 'details',
      '#title' => $this->t('Manifest'),
      '#description' => $this->t('Generate a file listing all conversion outputs with optional checksums and sizes for external integrations.'),
      '#group' => 'settings_tabs',
      '#open' => FALSE,
      '#states' => [
        'visible' => [
          ':input[name="enabled_processors[manifest]"]' => ['checked' => TRUE],
        ],
      ],
    ];

    $form['manifest']['manifest_enabled'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enable manifest generation'),
      '#description' => $this->t('Generate a manifest file listing all conversion outputs.'),
      '#default_value' => $config->get('manifest_enabled') ?? FALSE,
    ];

    $form['manifest']['manifest_format'] = [
      '#type' => 'select',
      '#title' => $this->t('Format'),
      '#description' => $this->t('Output format for the manifest file.'),
      '#options' => [
        'json' => $this->t('JSON'),
        'yaml' => $this->t('YAML'),
      ],
      '#default_value' => $config->get('manifest_format') ?? 'json',
    ];

    $form['manifest']['manifest_include_checksums'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Include checksums'),
      '#description' => $this->t('Include file checksums in the manifest.'),
      '#default_value' => $config->get('manifest_include_checksums') ?? FALSE,
    ];

    $form['manifest']['manifest_include_sizes'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Include file sizes'),
      '#description' => $this->t('Include file sizes in the manifest.'),
      '#default_value' => $config->get('manifest_include_sizes') ?? TRUE,
    ];
  }

}
