<?php

class Intense_Field_Box_Shadow extends Intense_Field {
	protected function render() {
		//parse box shadow parts from $value and set the horizontal, vertical, spread, and color
		$parts = explode( ' ', $this->value );

		if ( empty( $this->value ) || count( $parts ) < 4 ) {
			$parts = array('', '', '', '');
		}

		$output = '<input class="dialog boxh" type="text" style="width:80px;" name="boxh_' . $this->id . '" id="boxh_' . $this->id . '" value="' . str_replace( 'px', '', $parts[0] ) . '" />px';

		$output .= '<input class="dialog boxv" type="text" style="width:80px;" name="boxv_' . $this->id . '" id="boxv_' . $this->id . '" value="' . str_replace( 'px', '', $parts[1] ) . '" />px';

		$output .= '<input class="dialog boxspread" type="text" style="width:80px;" name="boxspread_' . $this->id . '" id="boxspread_' . $this->id . '" value="' . str_replace( 'px', '', $parts[2] ) . '" />px';

		$output .= '<div style="display: inline-block; line-height: 35px;">';
		$output .= '	<input name="boxcolor_' . $this->id . '" id="boxcolor_' . $this->id . '" class="of-color boxcolor" type="text" value="' . $parts[3] . '" data-default-color="' . $parts[3] . '" />';
		$output .= '</div>';
		$output .= $this->description;

		return $output;
	}

	public function render_init_script() {
		return "
			$('.of-color.boxcolor.minicolors-input').minicolors('destroy');
			$('.of-color.boxcolor').minicolors({
                    changeDelay: 200,
                    animationEasing: 'swing',
                    //opacity: true,
                    change: function() {
                        intenseRefreshPreview();
                    }
                });";
	}

	public function render_value_script() {
		return '($(\'#boxh_' . $this->id . '\').val().length > 0 &&  $(\'#boxv_' . $this->id . '\').val().length > 0 && $(\'#boxspread_' . $this->id . '\').val().length > 0 && $(\'#boxcolor_' . $this->id . '\').val().length > 0  ? \' ' . $this->id . '="\' + $(\'#boxh_' . $this->id . '\').val() + "px " + $(\'#boxv_' . $this->id . '\').val() + "px " + $(\'#boxspread_' . $this->id . '\').val() + "px " + $(\'#boxcolor_' . $this->id . '\').val() + \'"\' : "" ) + ';
	}

	public function map_visual_composer() {
		return array(
			"type" => "textfield",
			//"holder" => "button",
			"class" => "",
			"heading" => $this->title,
			"param_name" => $this->id,
			"value" => !empty( $this->default ) ? $this->default : '',
			'description' => ( isset( $this->args['description'] ) ? $this->args['description'] : __('CSS box_shadow shorthand property (ex. 0px 0px 10px #cccccc)', 'intense') ),
			"admin_label" => $this->composer_show_value,
		);
	}
}