<commit_before><?
namespace Asenine\Element;

class SelectBox extends Common\Root
{
	public
		$name,
		$selectedKey,
		$items;


	public static function keyValue($name, $selectedKey, Array $values)
	{
		$SelectBox = new self($name, $selectedKey);
		$SelectBox->addItemsFromArray($values, true);
		return $SelectBox;
	}

	public static function keyPair($name, $selectedKey, Array $values)
	{
		$SelectBox = new self($name, $selectedKey);
		$SelectBox->addItemsFromArray($values, false);
		return $SelectBox;
	}



	public function __construct($name = null, $selectedKey = null, Array $items = array())
	{
		$this->name = $name;
		$this->selectedKey = $selectedKey;
		$this->items = $items;

		$this->isNoneSelectable = false;
	}

	public function __toString()
	{
		$this->addData('clear', $this->selectedKey);
		$this->addData('origin', $this->selectedKey);

		ob_start();
		?><select name="<? echo htmlspecialchars($this->name); ?>"<? echo $this->getAttributes(); ?>><?
		if($this->isNoneSelectable) { ?><option value=""></option><? }

		foreach($this->items as $key => $value)
		{
			$isSelected = ($this->selectedKey && $this->selectedKey == $key);
			?><option value="<? echo htmlspecialchars($key); ?>" <? if($isSelected) echo 'selected="selected"'; ?>><? echo htmlspecialchars($value); ?></option><?
		}
		?></select><?
		return ob_get_clean();
	}


	public function addItemsFromArray(Array $array, $useValueAsKey = false)
	{
		foreach($array as $key => $value)
			$this->addItem($value, $useValueAsKey ? $value : $key);

		return $this;
	}

	public function addItemsFromArrayOfArrays(Array $arrays, $valueName, $keyName = null)<commit_msg>- Adds whitespace to SelectBox text to mitigate word-trim problem<commit_after><?
namespace Asenine\Element;

class SelectBox extends Common\Root
{
	public
		$name,
		$selectedKey,
		$items;


	public static function keyValue($name, $selectedKey, Array $values)
	{
		$SelectBox = new self($name, $selectedKey);
		$SelectBox->addItemsFromArray($values, true);
		return $SelectBox;
	}

	public static function keyPair($name, $selectedKey, Array $values)
	{
		$SelectBox = new self($name, $selectedKey);
		$SelectBox->addItemsFromArray($values, false);
		return $SelectBox;
	}



	public function __construct($name = null, $selectedKey = null, Array $items = array())
	{
		$this->name = $name;
		$this->selectedKey = $selectedKey;
		$this->items = $items;

		$this->isNoneSelectable = false;
	}

	public function __toString()
	{
		$this->addData('clear', $this->selectedKey);
		$this->addData('origin', $this->selectedKey);

		ob_start();
		?><select name="<? echo htmlspecialchars($this->name); ?>"<? echo $this->getAttributes(); ?>><?
		if($this->isNoneSelectable) { ?><option value=""></option><? }

		foreach($this->items as $key => $value)
		{
			$isSelected = ($this->selectedKey && $this->selectedKey == $key);
			?><option value="<? echo htmlspecialchars($key); ?>" <? if($isSelected) echo 'selected="selected"'; ?>><? echo htmlspecialchars($value), '&emsp;'; ?></option><?
		}
		?></select><?
		return ob_get_clean();
	}


	public function addItemsFromArray(Array $array, $useValueAsKey = false)
	{
		foreach($array as $key => $value)
			$this->addItem($value, $useValueAsKey ? $value : $key);

		return $this;
	}

	public function addItemsFromArrayOfArrays(Array $arrays, $valueName, $keyName = null)
{'fraction_non_alphanumeric': 0.18168257756563247, 'fraction_numerical': 0.0, 'mean_word_length': 5.08529945553539, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2185446', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1098, 'n_words': 247}