<?php

namespace Drupal\ai_prompt_test\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Test settings form embedding AI Prompt elements.
 */
class AiPromptTestSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return ['ai_prompt_test.settings'];
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'ai_prompt_test_settings';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('ai_prompt_test.settings');

    $form['prompts'] = [
      '#tree' => TRUE,
    ];

    $form['prompts']['prompt_open'] = [
      '#title' => $this->t('Open tags prompt'),
      '#type' => 'ai_prompt',
      '#prompt_types' => ['suggest_tags'],
      '#required' => TRUE,
      '#default_value' => $config->get('prompt_open'),
    ];

    $form['prompts']['prompt_from_voc'] = [
      '#title' => $this->t('Vocabulary prompt'),
      '#type' => 'ai_prompt',
      '#prompt_types' => ['suggest_vocabulary'],
      '#required' => TRUE,
      '#default_value' => $config->get('prompt_from_voc'),
    ];

    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->config('ai_prompt_test.settings')
      ->set('prompt_open', $form_state->getValue(['prompts', 'prompt_open']))
      ->set('prompt_from_voc', $form_state->getValue(['prompts', 'prompt_from_voc']))
      ->save();

    parent::submitForm($form, $form_state);
  }

}
