<?php

class Intense_Chart_Data extends Intense_Shortcode {

	function __construct() {
		parent::__construct();
		
		global $intense_visions_options;

		$this->title = __( 'Chart Data', 'intense' );
		$this->category = __( 'Media', 'intense' );
		$this->show_preview = true;
		$this->hidden = true;
		$this->parent = 'intense_chart';	
	}

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

		if ( isset( $values ) && isset( $colors ) ) {
			$values = explode( ",", str_replace( " ", "", $values ) );
			$colors = explode( ",", str_replace( " ", "", $colors ) );
			$tooltips = explode( ",", str_replace( " ", "", $tooltips ) );
			$output = '';

			$i = 0;

			foreach ( $values as $value ) {
				$color = $colors[ $i ];

				if ( isset( $tooltips[ $i ] ) ) {
					$tooltip = ", label: '" . $tooltips[ $i ] . "'";
				} else {
					$tooltip = '';
				}
				
				$output .= "{ value: $value, color: \"$color\" $tooltip },";
				$i++;
			}
			$output = rtrim( $output, "," );
		} else {
			$values = explode( ",", str_replace( " ", "", $values ) );
			$output = '{fillColor : "' . $fill_color . '", strokeColor : "' . $stroke_color . '", pointColor : "' . $point_color . '", pointStrokeColor : "' . $point_stroke_color . '", data : [';

			foreach ( $values as $value ) {
				$output .= "$value,";
			}

			$output = rtrim( $output, "," );
			$output .= ']},';
		}

		return $output;
	}
}