<?php

$fp = Freshop_Manager::get_instance();

global $additional_store_links;

get_header();
do_shortcode("[sd-store-landing]");

// Freshop Store Id
$store_id = types_render_field("store-id", array("output"=>"raw"));

// Store Info
$store_object = $fp->api_get('stores/' . $store_id);

$store_name				= $store_object->name;
$store_has_delivery		= $store_object->has_delivery;
$store_has_pick_up		= $store_object->has_pickup;

$store_address_1 		= $store_object->address_0;
$store_address_2 		= $store_object->address_1;
$store_address_3 		= $store_object->address_2;

$store_city				= $store_object->city;
$store_state			= $store_object->state;
$store_zip_code			= $store_object->postal_code;
$store_email	        = $store_object->email;

$store_hours			= fp_markdown_to_html($store_object->hours_md);
$store_phone			= fp_markdown_to_html($store_object->phone_md);
$store_description 		= fp_markdown_to_html($store_object->description_md);

$social_media_urls      = social_media_urls();

// WYSIWYG
$store_img 						= types_render_field("store-image", array("output"=>"raw"));
$store_img_alt_text 			= types_render_field("store-image-alt-text", array("output"=>"raw"));
$store_note 					= types_render_field("store-note");
$store_department_contact_info 	= types_render_field("store-department-contact-info");
// $store_email					= types_render_field("store-email",array("output"=>"raw"));
$store_features_departments		= types_render_field("store-departments", array("output"=>"html"));
$store_other_services			= types_render_field("store-services", array("output"=>"html"));
$store_xtrainf 					= types_render_field("store-extra-info", array("output"=>"html"));

// Checkboxes
$store_weekly_ad			= types_render_field("store-weekly-ad", array("output"=>"raw"));
$store_online_shopping		= types_render_field("store-online-shopping", array("output"=>"raw"));
$store_weekly_daily_deli	= types_render_field("store-daily-deli-menu", array("output"=>"raw"));

// Display Left Column
$store_display_left_col = true;

if(empty($store_weekly_ad) && empty($store_online_shopping) && empty($store_weekly_daily_deli)
    && empty($social_media_urls['facebook']) && empty($social_media_urls['twitter'])
    && empty($social_media_urls['pinterest']) && empty($social_media_urls['youtube'])):
	$store_display_left_col = false;
endif
?>

<script>
	var storeJsonData = <?php echo json_encode($store_object) ?>;
</script>

<div class="store-landing container main-content-wrap" role="main">
	<div class="breadcrumb-wrapper hidden">
	    <ul id="breadcrumb-other-store" class="breadcrumb other-store">
	        <?php display_bc($post->post_parent); ?>
	    </ul>
	</div>

	<header class="header page-title">
        <div class="my-store">
        	<h1 class="page-title">
        		My Store
        	</h1>
        </div>
        <div class="other-store">
        	<h1 class="page-title">
        		<?php the_title(); ?>
        	</h1>
        </div>
	</header>

	<section id="content" class="selected-store">
			<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

			<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
				<section class="entry-content">

					<div class="responsive hidden-sm hidden-xs">
						<?php if ( !empty($store_img) ) : ?>
						<?php if(!$store_display_left_col): ?>
						<div class="text-center">
						<?php endif ?>

						<img class="max-width hidden-sm hidden-xs margin-top" src="<?php echo $store_img; ?>" alt="<?php echo $store_img_alt_text; ?>">

						<?php if(!$store_display_left_col): ?>
						</div>
						<?php endif ?>

					<?php endif; ?>

					</div>

					<div class="row margin-top responsive">

						<div class="col-md-4">
							<div class="clearfix">
								<h3>Address</h3>

								<?php
									if(!empty($store_address_1)) :
										$store_address = $store_address_1;
									endif;

									if(!empty($store_address_2)) :
										$store_address = $store_address . ' ' . $store_address_2;
									endif;

									if(!empty($store_address_3)) :
										$store_address = $store_address . ' ' . $store_address_3;
									endif;

									$store_address = $store_address . ' ' . $store_city . ',' . $store_state . ' ' . $store_zip_code;
								?>
								<div class="fp-store-address">
                				<div class="fp-store-options"></div>
									<span class="store-name"><?php echo $store_name; ?></span>
									<?php if(!empty($store_address)) : ?>
										<div><?php echo $store_address_1; ?></div>
										<?php if(!empty($store_address_2)): ?><div><?php echo $store_address_2; ?></div><?php endif; ?>
										<?php if(!empty($store_address_3)): ?><div><?php echo $store_address_3; ?></div><?php endif; ?>

										<?php echo $store_city; ?>, <?php echo $store_state; ?> <?php echo $store_zip_code; ?>
									<?php endif ?>
								</div>
							</div>
							<div class="margin-top store-buttons">
				                <?php if(!empty($store_address)) : ?>
				                <a href="https://www.google.com/maps/dir//<?php echo urlencode($store_address); ?>" target="_blank" class="fp-btn button">Get Directions</a>
				            	<?php endif; ?>
				            </div>

				            <?php if($store_id > 0): ?>
							<div class="fp-make-my-store margin-top">
							</div>
							<?php endif; ?>

							<hr />

							<?php if($store_id > 0 && ($store_has_delivery || $store_has_pick_up)): ?>
							<div class="store-services-wrap clearfix">
								<div class="row">
									<div class="col-sm-6">
										<h3>Shopping Services</h3>
									</div>
									<div class="col-sm-6">
										<div class="store-services">
											<?php if($store_has_delivery): ?><span class="fp-icon fp-icon-fulfillment-delivery" title="Delivery"></span><?php endif; ?>
											<?php if($store_has_pick_up): ?><span class="fp-icon fp-icon-fulfillment-pickup" title="Pick Up"></span><?php endif; ?>
										</div>
									</div>
								</div>
							</div>
							<hr />
							<?php endif; ?>

							<div>
								<h3>Hours</h3>
								<?php if(!empty($store_hours)): ?>
								<?php echo $store_hours; ?>
								<?php endif; ?>
							</div>
							<hr />

							<div>
								<h3>Contact</h3>
								<?php if(!empty($store_phone)): ?>
									<div class="semi-bold">Phone:</div>
									<div class="visible-lg visible-md visible-sm"><?php echo $store_phone; ?></div>
									<div class="visible-xs"><a href="tel:<?php echo strip_tags($store_phone); ?>"><?php echo $store_phone; ?></a></div>
								<?php endif; ?>

								<?php if(!empty($store_email)): ?>
									<div class="margin-top semi-bold">Email:</div>
									<a href="mailto:<?php echo $store_email; ?>"><?php echo $store_email; ?></a>
								<?php endif; ?>
							</div>

							<?php if(!empty($store_weekly_ad) || !empty($store_online_shopping)): ?>
							<hr />
							<div class="store-explore">
								<h3>Explore</h3>

								<?php if(!empty($store_weekly_ad)):
										$circularAdNum = get_id_by_slug('weekly-circular');
										$weeklyAdUrl = '/weekly-ad';
										$weeklyAdText = 'Weekly Ad';

										if($circularAdNum > 0) {
											$weeklyAdText = 'Weekly Circular';
											$weeklyAdUrl = '/weekly-circular';
										}
								?>
									<div>
										<a href="<?php echo user_trailingslashit($weeklyAdUrl); ?>#!/?store_id=<?php echo $store_id; ?>" class="">View <?php echo $weeklyAdText ?></a>
									</div>
								<?php endif; ?>

								<?php if(!empty($store_online_shopping)): ?>
									<div><a href="<?php echo user_trailingslashit('/shop'); ?>" class="">Online Shopping</a></div>
								<?php endif; ?>

								<?php echo $additional_store_links; ?>
							</div>
							<?php endif; ?>

					 	</div>

						<div class="col-md-8">
							<div>
								<div class="fp-store-info">
									<div class="row">
										<div class="col-md-6">
											<?php if(!empty($store_features_departments)): ?>
											<div>
												<h3>Departments</h3>
												<?php echo $store_features_departments ?>
											</div>
											<?php endif; ?>
										</div>
										<div class="col-md-6">
											<?php if(!empty($store_other_services)): ?>
											<div class="margin-bottom">
												<h3>Services</h3>
												<?php echo $store_other_services ?>
											</div>
											<?php endif; ?>

											<?php if(!empty($social_media_urls['facebook']) || !empty($social_media_urls['twitter'])): ?>

											<div class="social-links-wrap">
												<h3>Connect</h3>
												<ul class="social-links">
													<?php if (!empty($social_media_urls['facebook'])) { ?>
								                        <li><a href="<?= $social_media_urls['facebook'] ?>" target="_blank" title="Facebook" class="my-store-link-facebook"><span class="fp-icon-facebook-layered bg-facebook"></span><span class="hidden">Facebook</span></a></li>
								                    <?php } ?>
								                    <?php if (!empty($social_media_urls['twitter'])) { ?>
								                        <li><a href="<?= $social_media_urls['twitter'] ?>" target="_blank" title="Twitter" class="my-store-link-twitter"><span class="fp-icon-twitter-layered bg-twitter"></span><span class="hidden">Twitter</span></a></li>
								                    <?php } ?>
								                    <?php if (!empty($social_media_urls['instagram'])) { ?>
													    <li><a href="<?= $social_media_urls['instagram'] ?>" target="_blank" title="instagram" class="my-store-link-instagram"><span class="fp-icon-instagram-layered bg-instagram"></span><span class="hidden">Instagram</span></a></li>
								                    <?php } ?>
								                    <?php if (!empty($social_media_urls['pinterest'])) { ?>
													    <li><a href="<?= $social_media_urls['pinterest'] ?>" target="_blank" title="Pinterest" class="my-store-link-pinterest"><span class="fp-icon-pinterest-layered bg-pinterest"></span><span class="hidden">Pinterest</span></a></li>
								                    <?php } ?>
								                    <?php if (!empty($social_media_urls['youtube'])) { ?>
													    <li><a href="<?= $social_media_urls['youtube'] ?>" target="_blank" title="YouTube" class="my-store-link-youtube"><span class="fp-icon-youtube-layered bg-youtube"></span><span class="hidden">YouTube</span></a></li>
								                    <?php } ?>
												</ul>
											</div>
											<?php endif; ?>
										</div>
									</div>
								</div>

								<hr class="bd-hr responsive hidden-sm hidden-xs">

								<div>
									<?php if(!empty($store_xtrainf)): ?>
										<?php echo $store_xtrainf ?>
									<?php endif; ?>
								</div>

							</div>
						</div>

					</div>

				</section>
			</article>

			<?php endwhile; endif; ?>
	</section>
</div>
<?php get_footer(); ?>
