<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

// namespace Bootstrap;

/**
 * Creates a Bootstrap Button object
 *
 * @author Maggie Magpie
 * @link http://www.oldauntie.org
 * @author Maggie Marple <oldauntie@oldauntie.org>
 * @version 1.0
 */
class BootstrapButton {
	const TYPE_BUTTON	= 'button';
	const TYPE_RESET	= 'reset';
	const TYPE_SUBMIT	= 'submit';
	
	private $type = self::TYPE_BUTTON;
	
	public $name;
	public $id;
	public $value;
	public $class = 'btn btn-primary';
	public $label = '';
	public $onclick = '';
	public $disabled = false;
	public $attributes = array();
			
	protected $output;
	
	public function __construct( $name, $label = '', $value='' ) {
		$this->name		= $name;
		$this->id		= $name;
		$this->label	= $label;
		$this->value	= $value;
	}
	
	public function setID( $id ){
		$this->id = $id;
	}
	
	public function setType( $type ){
		$this->type = $type;
	}
	
	public function setClass( $class ){
		$this->class = $class;
	}
	
	public function addClass( $class ){
		$this->class .= $class;
	}
	
	public function setValue( $value ) {
		$this->value = $value;
	}
	
	function setAttribute( $attribute ){
		$this->attributes = ' ' . $attribute;
	}

	function addAttribute( $attribute ){
		$this->attributes .= ' ' . $attribute;
	}

	
	public function output(){
		$disabled	= '';
		
		if( $this->disabled == true ){
			$disabled = ' disabled';
		}

		$this->output .= '<button type="' . $this->type . '" 
							name="' . $this->name . '" 
							value="' . $this->value . '" 
							class="' . $this->class . '" 
							id="' . $this->id . '"' .
							$disabled;
		
		if( empty( $this->onclick ) == false ){
			$this->output .= ' onclick="' . $this->onclick . '"'; 
		}
		
		// adding additional data-properties
		if ( is_array ( $this->attributes ) && empty ( $this->attributes ) == false ){
			foreach ( $this->attributes as $property ) {
				$this->output .= ' ' . $property;
			}
		}
		
		$this->output .= '>'.$this->label.'</button>';

		return $this->output;
	}
	
	
	public static function create( $name, $label = '', $value='' ){
		$bso = new BootstrapButton( $name, $label, $value );
		return $bso->output();
	}
	
		
}
