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

if ( empty( $data ) ) {
	return;
}

foreach ( $data as $type => $plugins ) :

// Start output buffering
ob_start();
?>
<span>
<?php
if ( 'required' == $type ) {
	_e( 'Install required plugins.', IT_THEME_TEXTDOMAIN );
} else {
	_e( 'For the best experience, it\'s strongly recommended for you to install following <strong>FREE</strong> plugins.', IT_THEME_TEXTDOMAIN );
}
?>
</span>
<ul>
<?php
foreach ( $plugins as $plugin ) :

// Check plugin status
$show = ( string ) $plugin['state'] != 'installed';

if ( 'installed' == ( string ) $plugin['state'] && count( $plugin['dependencies'] ) ) {
	foreach ( $plugin['dependencies'] as $dependency ) {
		if ( 'installed' != ( string ) $dependency['state'] ) {
			$show = true;
		}
	}
}

if ( $show ) :

$class = 'label';

switch ( ( string ) $plugin['state'] ) {
	case 'install':
		$class .= ' label-success';
		$status = __( 'New Installation', IT_THEME_TEXTDOMAIN );
	break;

	case 'update':
		$class .= ' label-warning';
		$status = __( 'Update', IT_THEME_TEXTDOMAIN );
	break;

	case 'installed':
	default:
		$status = __( 'Installed', IT_THEME_TEXTDOMAIN );
	break;
}
?>
	<li>
		<label class="checkbox it-title">
<?php if ( 'required' == $type ) : ?>
			<input type="hidden" value="<?php esc_attr_e( ( string ) $plugin['name'] ); ?>" />
<?php else : ?>
			<input type="checkbox" value="<?php esc_attr_e( ( string ) $plugin['name'] ); ?>" checked="checked" <?php if ( 'install' != ( string ) $plugin['state'] ) echo 'disabled="disabled"'; ?> />
<?php
endif;

esc_html_e( ( string ) $plugin['description'], IT_THEME_TEXTDOMAIN );
?>
		</label>
		<i class="jsn-icon-loading"></i>
		<span class="<?php esc_attr_e( $class ); ?>"><?php esc_html_e( $status, IT_THEME_TEXTDOMAIN ); ?></span>
		<a href="javascript:void(0)" class="it-plugin-details-toggle"><i class="icon-plus-sign"></i></a>
		<span class="it-status"></span>
		<p class="it-plugin-details hide">
			<?php esc_html_e( ( string ) $plugin['productdesc'], IT_THEME_TEXTDOMAIN ); ?>
			<a class="it-read-more" target="_blank" href="<?php echo esc_url( ( string ) $plugin['producturl'] ); ?>"><?php _e( 'Read more...', IT_THEME_TEXTDOMAIN ); ?></a>
		</p>
<?php if ( count( $plugin['dependencies'] ) ) : ?>
		<ul class="it-sample-data-plugin-dependencies">
<?php
foreach ( $plugin['dependencies'] as $dependency ) :

if ( 'installed' != ( string ) $dependency['state'] ) :
?>

			<li>
				<label class="checkbox it-title">
					<input type="checkbox" value="<?php esc_attr_e( ( string ) $dependency['name'] ); ?>" checked="checked" disabled="disabled" />
					<?php esc_html_e( ( string ) $dependency['description'], IT_THEME_TEXTDOMAIN ); ?>
				</label>
				<i class="jsn-icon-loading"></i>
				<span class="label label-<?php if ( 'install' == ( string ) $dependency['state'] ) echo 'success'; else echo 'warning'; ?>">
					<?php ( 'install' == ( string ) $dependency['state'] ) ? _e( 'New Installation', IT_THEME_TEXTDOMAIN ) :  _e( 'Update', IT_THEME_TEXTDOMAIN ); ?>
				</span>
				<span class="it-status"></span>
			</li>
<?php
endif;

endforeach;
?>
		</ul>
<?php endif; ?>
	</li>
<?php
endif;

endforeach;
?>
</ul>
<?php
$final_response[$type] = ob_get_clean();

endforeach;

// Set the final response
$this->set_response( 'success', $final_response );
