<?php
/**
 * The default template for displaying Home page Slider
 *
 * @package WordPress
 * @subpackage Charity
 * @since Charity 1.0
 */
?>
<?php
	$wplook_header_image = get_header_image();
	$wplook_slider_args = array( 'post_type' => 'post_sliders', 'post_status' => 'publish', 'posts_per_page' => 10 );
	$wplook_slider_query = new WP_Query( $wplook_slider_args );
?>

<?php if ( ( ot_get_option('wpl_rev_slider') == "on") && ot_get_option('wpl_slider_revolution') != '' && function_exists('putRevSlider') ) {
		putRevSlider( ot_get_option( 'wpl_slider_revolution') );
} elseif (! empty( $wplook_header_image ) ) { ?>
	<img class="header-image" src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
<?php } else { ?>
	<?php if ( $wplook_slider_query->post_count > 0)  { ?>

	<div class="slider-intro">
		<div class="slider-clip">
			<ul class="slides owl-carousel">
				<?php if ( $wplook_slider_query->have_posts() ) : while ( $wplook_slider_query->have_posts() ) : $wplook_slider_query->the_post(); ?>
					<?php
						$wplook_slide_meta 			= get_post_meta($post->ID);
						$wplook_slide_image 		= isset($wplook_slide_meta['wpl_slide_image'][0]) ? $wplook_slide_meta['wpl_slide_image'][0] : false;
						$wplook_slider_slide_type 	= isset($wplook_slide_meta['wpl_slide_type'][0]) ? $wplook_slide_meta['wpl_slide_type'][0] : "standard_slider";

						$wplook_slider_button_text 	= isset($wplook_slide_meta['wpl_slider_button_text'][0]) ? $wplook_slide_meta['wpl_slider_button_text'][0] : false;
						$wplook_slider_button_url 		= isset($wplook_slide_meta['wpl_slider_button_url'][0]) ? $wplook_slide_meta['wpl_slider_button_url'][0] : false;

						// Standard Slider
						$wplook_slider_button_text_standard = isset($wplook_slide_meta['wpl_slider_button_text_standard'][0]) ? $wplook_slide_meta['wpl_slider_button_text_standard'][0] : false;
						$wplook_slider_button_url_standard = isset($wplook_slide_meta['wpl_slider_button_url_standard'][0]) ? $wplook_slide_meta['wpl_slider_button_url_standard'][0] : false;

						$wplook_slider_button_cause_id = isset($wplook_slide_meta['wpl_slider_button_cause_id'][0]) ? $wplook_slide_meta['wpl_slider_button_cause_id'][0] : false;
					?>

					<?php if ($wplook_slider_slide_type == 'cause_slider') : ?>

						<?php
							$wplook_cause_meta = get_post_meta($wplook_slider_button_cause_id);
							$wplook_donations_raised_nb = wplook_donations_raised($wplook_slider_button_cause_id);
							$wplook_donations_number = $wplook_donations_raised_nb[0];
							$wplook_donations_raised = $wplook_donations_raised_nb[1];
							$wplook_cause_goal_amount	= isset($wplook_cause_meta['wpl_goal_amount'][0]) ? $wplook_cause_meta['wpl_goal_amount'][0] : 0;
							$wplook_cause_to_go = $wplook_cause_goal_amount ? $wplook_cause_goal_amount - $wplook_donations_raised : false;
							$wplook_cause_urgent	= isset($wplook_cause_meta['wpl_urgent_cause'][0]) ? $wplook_cause_meta['wpl_urgent_cause'][0] : "off";

							$wplook_slider_button_text 	= isset($wplook_slide_meta['wpl_slider_button_text'][0]) ? $wplook_slide_meta['wpl_slider_button_text'][0] : false;
							$wplook_slider_button_url 		= isset($wplook_slide_meta['wpl_slider_button_url'][0]) ? $wplook_slide_meta['wpl_slider_button_url'][0] : false;
						 ?>
						<li class="slide">
							<div class="slide-image fullscreener">
								<?php if ( $wplook_slide_image ) { ?>
									<img class="lazyOwl" src="<?php echo esc_url($wplook_slide_image) ?>" alt="<?php the_title(); ?>" width="1800" height="890">
								<?php } ?>
							</div><!-- /.slide-image -->

							<div class="slide-content">
								<div class="grid-container">
									<div class="grid-x grid-margin-x">
										<div class="cell large-7">
											<h2 class="slide-title"><?php the_title(); ?></h2><!-- /.slide-title -->

											<div class="slide-entry">
												<p><?php the_excerpt(); ?></p>
											</div><!-- /.slide-entry -->
										</div><!-- /.cell large-7 -->

										<div class="cell large-5">
											<div class="slide-aside">
												<?php if ($wplook_cause_urgent == "on" ) : ?>
													<div class="slide-tag"><?php _e( 'Urgent Cause', 'charity-wpl') ?></div><!-- /.cause-tag -->
												<?php endif; ?>

												<div class="slide-progress <?php echo $wplook_cause_to_go ? 'two-columns' : 'one-column'; ?>">
													<div class="slide-raised">
														<span><?php _e('Raised', 'charity-wpl'); ?></span>

														<strong><?php echo esc_html(wplook_format_money($wplook_donations_raised)). ' '. esc_attr( ot_get_option('wpl_curency_code') ); ?></strong>
													</div><!-- /.slide-raised -->

													<?php if( $wplook_cause_to_go ) : ?>
														<div class="slide-to-go">
															<span><?php _e('To Go', 'charity-wpl'); ?></span>

															<strong><?php echo esc_html(wplook_format_money($wplook_cause_to_go)). ' '. esc_attr( ot_get_option('wpl_curency_code') ); ?></strong>
														</div><!-- /.slide-to-go -->
													<?php endif; ?>
												</div><!-- /.slide-progress -->

												<div class="slide-actions">

													<?php if ( $wplook_slider_button_url) { ?>
														<a href="<?php echo esc_url($wplook_slider_button_url); ?>">
															<?php if ( $wplook_slider_button_text ) {
																echo esc_html($wplook_slider_button_text);
															} else {
																_e('Donate Now', 'charity-wpl');
															} ?>
														</a>

													<?php } else { ?>
														<a href="<?php echo esc_url( get_permalink($wplook_slider_button_cause_id) ); ?>">
															<?php if ( $wplook_slider_button_text ) {
																echo esc_html($wplook_slider_button_text);
															} else {
																_e('Donate Now', 'charity-wpl');
															} ?>
														</a>
													<?php } ?>

												</div><!-- /.slide-actions -->
											</div><!-- /.slide-aside -->
										</div><!-- /.columns large-5 -->
									</div><!-- /.grid-x grid-margin-x -->
								</div><!-- /.grid-container -->
							</div><!-- /.slide-content -->
						</li><!-- /.slide -->
					<?php else : ?>

						<li class="slide-alt">
							<div class="slide-image fullscreener">
								<?php if ( $wplook_slide_image ) { ?>
									<img src="<?php echo esc_url($wplook_slide_image) ?>" alt="<?php the_title(); ?>" width="1800" height="890">
								<?php } ?>
							</div><!-- /.slide-image -->

							<div class="slide-content">
								<div class="grid-container">
									<div class="grid-x grid-margin-x">
										<div class="cell small-12">
											<div class="slide-content-inner">
												<h2 class="slide-title"><?php the_title(); ?></h2><!-- /.slide-title -->

												<p><?php the_excerpt(); ?></p>

												<div class="slide-actions">
													<?php if ($wplook_slider_button_text_standard) { ?>
														<a href="<?php echo esc_url($wplook_slider_button_url_standard); ?>" class="button button-white" itemprop="url"><?php echo esc_html($wplook_slider_button_text_standard); ?></a>
													<?php } ?>
												</div><!-- /.slide-actions -->
											</div><!-- /.slide-content-inner -->
										</div><!-- /.cell small-12 -->
									</div><!-- /.grid-x grid-margin-x -->
								</div><!-- /.grid-container -->
							</div><!-- /.slide-content -->
						</li><!-- /.slide-alt --><!-- /.slide-alt -->
					<?php endif; ?>
				<?php endwhile; ?>
				<?php wp_reset_postdata(); ?>
				<?php endif; ?>
				<?php wp_reset_query(); ?>
			</ul><!-- /.slides -->
		</div><!-- /.slider-clip -->
		<div class="slider-actions"></div><!-- /.slider-actions -->
	</div><!-- /.slider-intro -->
	<?php } ?>
<?php } ?>
