<?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
 */

foreach ( $this->current_fieldsets as $fid => $fieldset ) :
?>
<fieldset id="it-form-fieldset-<?php esc_attr_e( $fid ); ?>">
	<?php if ( isset( $fieldset['title'] ) ) : ?>
	<legend>
		<?php
		esc_html_e( $fieldset['title'], IT_THEME_TEXTDOMAIN );

		// Check if accordion toggler should be embeded
		if ( @$fieldset['accordion_toggler'] && isset( $fieldset['accordion'] ) ) :
		?>
		<span class="it-form-fieldset-accordion-toggler">
			<a class="icon-minus collapse-all" title="<?php _e( 'Collapse All', IT_THEME_TEXTDOMAIN ); ?>"></a>
			<a class="icon-plus expand-all" title="<?php _e( 'Expand All', IT_THEME_TEXTDOMAIN ); ?>"></a>
		</span>
		<?php
		endif;

		// Check if field inputable switcher should be embeded
		if ( @$fieldset['state_switcher'] && ( isset( $fieldset['fields'] ) || isset( $fieldset['accordion'] ) ) ) :
			// Check if field inputable is enabled?
			$enabled = isset( $fieldset['fields'][ $fid ] ) ? $fieldset['fields'][ $fid ]->get( 'value', 1, true ) : true;
		?>
		<span class="it-form-fieldset-state-switcher btn-group">
			<a class="btn btn-default<?php if ( $enabled ) echo ' btn-success disabled'; ?> turn-on"><?php _e( 'On', IT_THEME_TEXTDOMAIN ); ?></a>
			<a class="btn btn-default<?php if ( ! $enabled ) echo ' btn-danger disabled'; ?> turn-off"><?php _e( 'Off', IT_THEME_TEXTDOMAIN ); ?></a>
		</span>
		<?php
		endif;
		?>
	</legend>
	<?php endif; ?>

	<?php
	if ( isset( $fieldset['fields'] ) ) :
		$this->current_fields = $fieldset['fields'];

		// Load fields template
		include IT_Loader::get_path( 'form/tmpl/fields.php' );
	endif;

	if ( isset( $fieldset['accordion'] ) ) :
		$this->current_accordion = $fieldset['accordion'];

		// Load accordion template
		include IT_Loader::get_path( 'form/tmpl/accordion.php' );
	endif;
	?>
</fieldset>
<?php
endforeach;
