<?php

class Intense_Progress_Segment extends Intense_Shortcode {

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

		global $intense_visions_options;

		$this->title = __( 'Progress Segment', 'intense' );
		$this->category = __( 'Elements', 'intense' );
		$this->show_preview = true;
		$this->hidden = true;
		$this->parent = 'intense_progress';		
	}

	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;

		$animate_text = ( strpos($text, '{0}') >= 0 );

		if ( isset( $intense_progress_animate_text ) ) $animate_text = $intense_progress_animate_text;				

		$base_span_style = 'padding: 0 ' . $intense_progress_height / 2 . 'px; font-size: ' . $intense_progress_font_size . 'px;';

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

		$output = '';

		$color = intense_get_plugin_color( $color );

		$gradient_css = '';

		if ( $intense_progress_gradient ) {
			$end_color = intense_adjust_color_brightness( $color, -60 );
			$gradient_css = intense_linear_gradient_css( $color, $end_color );
		} else {
			$gradient_css = "filter: none !important;";
		}

		if ( $intense_progress_animation ) {
			$width = 'data-progress="' . ( isset( $value ) ? $value : "0" ) . '" style="background: ' . $color  . '; ' . $gradient_css . '" data-animate-text="' . $animate_text . '"';
		} else {
			$width = 'style="width: ' . ( isset( $value ) ? $value : "0" ) . '%; background: ' . $color  . '; ' . $gradient_css . '"';
		}

		$output .= '<div role="progress-bar" aria-valuenow="' . ( isset( $value ) ? $value : "0" ) . '" aria-valuemin="0" aria-valuemax="100" class="intense progress-bar ' . ( is_rtl() ? 'rtl ' : '' ) . '" ' . $width . '>' .
			( isset( $text ) && strlen( $text ) > 0 ? '<span' . ( $intense_progress_animation ? ' style="display: none; ' . $base_span_style . '"' : ' style="' . $base_span_style . '"' ) . '>' . $text . '</span>' : "<span></span>" ) .
			'</div>';

		return $output;
	}
}
