<?php

namespace Planaday\Utility\FormBuilder\InputFields;

use Planaday\Utility\FormBuilder\DataTypes\StringType;
use Planaday\Utility\FormBuilder\InputField;

/**
 * @uses BasicInputField<string>
 * @implements InputField<string>
 */
class TextEditorInput implements InputField {
	use BasicInputField;

	public function __construct(StringType $dataType = new StringType()) {
		$this->dataType = $dataType;
	}

	protected array $buttons = [];

	/**
	 * @param array $layout
	 * an array where the final value is the value that will get placed and the indexes are the text on the buttons, for example:
	 *
	 * [ "values" => [ "student" => [ "name" => "{name}", "email" => "{email}" ], "startdate" => "{startdate}"] ]
	 *
	 * would output a menu with a values button under which a student and a startdate button would be, the student would
	 * have another submenu while the startdate would output "{startdate}"
	 *
	 * @return $this
	 */
	public function setButtonLayout(array $layout): self {
		$this->buttons = $layout;
		return $this;
	}

	public function getImplJson(): array {
		return [
			"type" => 'textEditor',
			"buttons" => $this->buttons
		];
	}
}