<?php
/**
 * The template for displaying Contact Info
 *
 * @package Signify
 */

$enable_info   = get_theme_mod( 'signify_contact_info_option', 'disabled' );
$enable_form   = get_theme_mod( 'signify_contact_option', 'disabled' );

if ( ! signify_check_section( $enable_info ) && ! signify_check_section( $enable_form ) ) {
	// Bail if featured content is disabled.
	return;
}

$layout = 'layout-one';

if ( signify_check_section( $enable_info ) && signify_check_section( $enable_form ) ) {
	$layout = 'layout-two';
}

$background_image = get_theme_mod( 'signify_contact_bg_image' ); 

$signify_sub_title   = get_theme_mod( 'signify_contact_info_sub_title' );
$signify_title       = get_theme_mod( 'signify_contact_info_title' );
$signify_description = get_theme_mod( 'signify_contact_info_description' );

if ( ! $signify_sub_title && ! $signify_title && ! $signify_description ) {
	$classes[] = 'no-section-heading';
}
?> 	
<div id="contact-section" class="section<?php echo ( ! $signify_sub_title && ! $signify_title && ! $signify_description ) ? ' no-section-heading' : ''; ?>">
	<div class="wrapper">
		<?php if ( $background_image ) : ?>
		<div class="main-image post-thumbnail" style="background-image: url( <?php echo $background_image; ?> );">
			<a class="cover-link" href="#"></a>
		</div><!-- .post-thumbnail -->
		<?php endif; ?>
		<div class="inner-section-content-wrapper">
			<div class="section-content-wrapper contact-content-wrapper <?php echo esc_attr( $layout ); ?>">
				<?php
					if ( signify_check_section( $enable_info ) ) :
					$phone_label = get_theme_mod( 'signify_contact_phone_label', esc_html__( 'Phone', 'signify-pro' ) );
					$phone       = get_theme_mod( 'signify_contact_phone', '123-456-7890' );
					
					$email_label = get_theme_mod( 'signify_contact_email_label', esc_html__( 'Email', 'signify-pro' ) );
					$email       = get_theme_mod( 'signify_contact_email', 'someone@somewhere.com' );
					
					$address_label = get_theme_mod( 'signify_contact_address_label', esc_html__( 'Location', 'signify-pro' ) );
					$address       = get_theme_mod( 'signify_contact_address', 'Boston, MA, USA' );
					
					$address_link = get_theme_mod( 'signify_contact_address_link', '#' );
					$target       = get_theme_mod( 'signify_contact_address_target' ) ? '_blank' : '_self'; ?>
				<article class="hentry contact-info-with-social">
					<div class="hentry-inner">
						<div class="entry-container">
							<?php signify_section_header( $signify_sub_title, $signify_title, $signify_description ); ?>
							
							<div class="entry-content">
								<div class="contact-info-details contact-information">
									<ul class="contact-details">
										<?php if ( $email ) : ?>
											<li class="contact-email">
												<a target="_blank" title="<?php echo esc_attr( antispambot( $email ) ); ?>" href="mailto:<?php echo esc_attr( antispambot( $email ) ); ?>">
													<i class="contact-icon fa fa-envelope"></i>
													<span class="contact-details-wrap">
														<?php if ( $email_label ) : ?>
															<span class="contact-details-label">
																<?php echo esc_html( $email_label ); ?>
															</span>
														<?php endif; ?>
														<span><?php echo esc_html( antispambot( $email ) ); ?></span>
													</span> 
												</a>
											</li>
									<?php endif; ?>

									<?php if ( $phone ) : ?>
										<li class="contact-phone">
											<?php if ( $phone ) : ?>
												<a target="_blank" title="<?php echo esc_attr( preg_replace( '/\s+/', '', $phone ) ); ?>"    href="tel:<?php echo esc_attr( preg_replace( '/\s+/', '', $phone ) ); ?>"><i class="		fa fa-phone"></i>
												<span class="contact-details-wrap">
													<?php if ( $phone_label ) : ?>
														<span class="contact-details-label">
															<?php echo esc_html( $phone_label ); ?>
														</span>
													<?php endif; ?>	
														<span>
															<?php echo esc_html( $phone ); ?>
														</span>
												</span> 
												</a>
											<?php endif; ?>	
										</li>
									<?php endif; ?>

										<li class="contact-address">
											<?php if ( $address ) : ?>
												<a target="<?php echo esc_attr( $target ); ?>" href="<?php echo esc_url($address_link); ?>">
													<i class="fa fa-map-marker" aria-label="Icon Address"></i>
													<span class="contact-details-wrap">
														<?php if ( $address_label ) : ?>
															<span class="contact-details-label">
																<?php echo esc_html( $address_label ); ?>
															</span>
														<?php endif; ?>	
														<span>
															<?php echo esc_html( $address ); ?>
														</span>
													</span> 
												</a>
											<?php endif; ?>	
										</li>
									</ul>
								</div><!-- .contact-info-details -->

								<?php if ( has_nav_menu( 'social-contact' ) ) : ?>
									<div class="contact-info-details stay-connected">
										<nav class="social-navigation" role="navigation" aria-label="Contact Info Details Stay Connected">
											<?php
												wp_nav_menu( array(
													'theme_location' => 'social-contact',
													'menu_class'     => 'social-links-menu',
													'depth'          => 1,
													'link_before'    => '<span class="screen-reader-text">',
													'link_after'     => '</span>',
												) );
											?>
										</nav><!-- .social-navigation -->
									</div><!-- .contact-info-details -->
								<?php endif; ?>
							</div><!-- .entry-content -->
						</div><!-- .entry-container -->
					</div><!-- .hentry-inner -->	
				</article><!-- .hentry -->	
			<?php endif; ?>
			<?php
			if ( signify_check_section( $enable_form ) ) :
				$type     = get_theme_mod( 'signify_contact_type' ); 
				$title    = get_theme_mod( 'signify_contact_title', esc_html__( 'Reservation', 'signify-pro' ) ); ?>
				<article class="hentry contact-us-form">
					<div class="entry-container">
					<?php if ( $title ) : ?>
						<header class="entry-header">
							<h2 class="entry-title "><?php echo esc_html( $title ); ?></h2>
						</header>
					<?php endif; ?>
					<?php
					$inner_content = '';

					if ('post' === $type && 'publish' === get_post_status( get_theme_mod( 'signify_contact_post' ) ) ) {
						$post_object = get_post( get_theme_mod( 'signify_contact_post' ) );

						$inner_content = apply_filters( 'the_content', $post_object->post_content );
					} elseif ( 'page' === $type  && 'publish' === get_post_status( get_theme_mod( 'signify_contact_page' ) ) ) {
						$post_object = get_post( get_theme_mod( 'signify_contact_page' ) );

						$inner_content = apply_filters( 'the_content', $post_object->post_content );
					} elseif ( 'custom' === $type ) {

						$inner_content = get_theme_mod( 'signify_contact_custom' );
					}
					?>

						<div class="entry-content">
							<?php echo do_shortcode( $inner_content );?> 
						</div>
					</div>
				</article><!-- .hentry -->	
			<?php endif; ?>	
			</div>
		</div>
	</div><!-- .wrapper -->
</div><!-- .section -->
