<?php

class Intense_Progress extends Intense_Shortcode {

	function __construct() {
        parent::__construct();

		global $intense_visions_options;

		$this->title = __( 'Progress', 'intense' );
		$this->description = __( 'Add progress bars using the progress bar shortcode. Choose unlimited colors for each individual progress segment. Animate the segment and/or text. Choose from five different sizes. Add a gradient or round the corners.', 'intense' );
		$this->category = __( 'Elements', 'intense' );
		$this->show_preview = true;
		$this->is_container = true;
	}

	function shortcode( $atts, $content = null ) {
		global $intense_visions_options;
		extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

		global $intense_progress_animate_text;		
		global $intense_progress_height;
		global $intense_progress_font_size;
		global $intense_progress_animation;
		global $intense_progress_gradient;

		$intense_progress_animate_text = $animate_text;		
		$intense_progress_animation = $animation;
		$intense_progress_gradient = $gradient;
		$id = ( !empty ( $id ) ) ? ' id="' . $id . '"' : '';

		$radius = '';

		if ( isset( $border_radius ) ) {
			$radius = ' border-radius:' . $border_radius . ';';
		}

		$color_list = explode( ",", str_replace( " ", "", $colors ) );
		$value_list = explode( ",", str_replace( " ", "", $values ) );
		$texts_list = explode( ",", $texts );

		intense_add_script( 'jquery.appear' );
		intense_add_script( 'intense.progress' );

		switch ( $size ) {
		case 'mini':
			$height = 10;
			$font_size = 8;
			break;
		case 'small':
			$height = 20;
			$font_size = 10;
			break;
		case 'large':
			$height = 40;
			$font_size = 14;
			break;
		case 'mega':
			$height = 50;
			$font_size = 16;
			break;
		case 'medium':
		default:
			$height = 30;
			$font_size = 12;
			break;
		}

		$intense_progress_height = $height;
		$intense_progress_font_size	= $font_size;

		$output = '<div' . $id . ' class="intense progress' . ( !empty( $class ) ? ' ' . $class : '' ) . '" style="filter: none; height: ' . $height . 'px; line-height: ' . $height . 'px;' . $radius . '"' . ( $animation ? ' data-animate-speed="' . $animation_speed . '"' : '' ) . '>';
		$base_span_style = 'padding: 0 ' . $height / 2 . 'px; font-size: ' . $font_size . 'px;';

		// This makes the old method still work
		foreach ( $color_list as $i => $color ) {
			if ( !empty( $color ) ) {
				$output .= intense_run_shortcode( 'intense_progress_segment', array(
					'color' => $color,
					'value' => ( isset( $value_list[$i] ) ? $value_list[$i] : '' ),
					'text' => ( isset( $texts_list[$i] ) ? $texts_list[$i] : '' )
				));
			}
		}

		$output .= do_shortcode( $content );

		$output .= "</div>";

		return $output;
	}
}
