<?php
/**
 * @version    $Id$
 * @package    IT_Theme_Framework
 * @author     InnoThemes Team <support@innothemes.com>
 * @copyright  Copyright (C) 2012 InnoThemes.com. All Rights Reserved.
 * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * Websites: http://www.innothemes.com
 */

// Count options
$num_checkbox = count( $this->choices );

// Prepare name attribute
$this->attributes['name'] = ( $num_checkbox == 1 ) ? $this->name : "{$this->name}[]";
?>
<div class="it-form-field-checkbox" id="<?php $this->get( 'id' ); ?>">
<?php
// Backup original attributes
$original_attrs = $this->attributes;

foreach ( $this->choices as $value => $label ) :

// Update attributes
$this->attributes['value'] = $value;

if ( ( 1 == $num_checkbox && $this->value == $value ) || ( $num_checkbox > 1 && @in_array( $value, $this->value ) ) ) {
	$this->attributes['checked'] = 'checked';
}

// Prepare additional attributes
if ( is_array( $label ) ) {
	foreach ( $label as $k => $v ) {
		if ( 'label' != $k ) {
			$this->attributes[ $k ] = $v;
		}
	}

	$label = $label['label'];
}
?>
	<label class="checkbox-<?php if ( $this->inline ) echo 'inline'; ?>">
		<input <?php $this->html_attributes( array( 'class', 'id', 'placeholder' ) ); ?> />
		<?php esc_html_e( $label ); ?>
	</label>
<?php
// Restore original attributes
$this->attributes = $original_attrs;

endforeach;
?>
</div>
