<?php

	/**
	* WPBakery Page Builder Stockie Date and time custom type
	*/

	if ( function_exists ( 'vc_add_shortcode_param' ) ) {
		vc_add_shortcode_param( 'stockie_datetime', 'stockie_extra_datetime_settings_field', plugins_url( 'datetime.js' , __FILE__ ) );
	}

	function stockie_extra_datetime_settings_field( $settings, $value ) {
		$year = $month = $day = $hour = $minute = $second = '';
		$value_array = StockieExtraParser::VC_datetime_to_array( $value );
		ob_start();

?>
		<div class="stockie_extra_datetime_block">
			<input type="hidden" name="<?php echo StockieExtraFilter::string( $settings['param_name'], 'attr', '' ); ?>" class="wpb_vc_param_value" value="<?php echo StockieExtraFilter::string( $value, 'attr', '' ); ?>">
			<div class="row">
				<label>
					<div class="title"><?php esc_html_e( 'Year', 'stockie-extra' ); ?></div>
					<input class="year" type="number" data-target="year" value="<?php echo StockieExtraFilter::string( $value_array['year'], 'attr', '' ); ?>">
				</label>
				<span class="divider">/</span>
				<label>
					<div class="title"><?php esc_html_e( 'Month', 'stockie-extra' ); ?></div>
					<input type="number" max="12" min="1" data-target="month" value="<?php echo StockieExtraFilter::string( $value_array['month'], 'attr', '' ); ?>">
				</label>
				<span class="divider">/</span>
				<label>
					<div class="title"><?php esc_html_e( 'Day', 'stockie-extra' ); ?></div>
					<input type="number" max="31" min="1" data-target="day" value="<?php echo StockieExtraFilter::string( $value_array['day'] ); ?>">
				</label>
				<label class="hour">
					<div class="title"><?php esc_html_e( 'Hour', 'stockie-extra' ); ?></div>
					<input type="number" max="23" min="0" data-target="hour" value="<?php echo esc_attr( $value_array['hour'] ); ?>">
				</label>
				<span class="divider">:</span>
				<label>
					<div class="title"><?php esc_html_e( 'Minute', 'stockie-extra' ); ?></div>
					<input type="number" max="59" min="0" data-target="minute" value="<?php echo esc_attr( $value_array['minute'] ); ?>">
				</label>
				<span class="divider">:</span>
				<label>
					<div class="title"><?php esc_html_e( 'Second', 'stockie-extra' ); ?></div>
					<input type="number" max="59" min="0" data-target="second" value="<?php echo esc_attr( $value_array['second'] ); ?>">
				</label>
			</div>
		</div>
<?php

		$content = ob_get_contents();
		ob_end_clean();
		return $content;
	}