<?php
get_header();

if (have_posts()) : the_post();
	$postMeta = get_post_meta(get_the_ID());
	$meta     = array(
		'restaurant' => get_post($postMeta['meal-restaurant'][0]),
		'weight'     => $postMeta['meal-weight'][0],
		'calories'   => $postMeta['meal-calories'][0],
		'price'      => $postMeta['meal-price'][0],
	);
//	varDump($meta, 0, 0);
?>

	<section class="container container-dish">
		<div class="row-fluid">
			<div class="span16">
				<div class="dish-wrapper">
					<div class="dish-container">
						<div class="dish-container-inner">
							<div class="container-items">
								<article class="item">
<?php if (has_post_thumbnail()) : ?>
									<div class="image"><?php the_post_thumbnail(); ?></div>
<?php endif; ?>
									<div class="content">
										<header>
											<h1 class="title"><?php the_title(); ?></h1>
										</header>
										<div class="description"><?php the_content(); ?></div>
										<footer>
											<time datetime="<?php echo get_the_date('c') ?>" class="pull-right"><span class="less"><?php echo get_the_date('d.m.y'); ?></span><span class="more"><?php the_date('d.m.Y <\i>H:i</\i>'); ?></span></time>
											<a class="feedback" href="#"><i class="icon icon-lighting"></i><span>пожаловаться или предложить</span></a>
											<div class="likes">
												<a <?php echo (bool)get_user_meta(get_current_user_id(), 'liked_' . get_the_ID(), true) ? 'class="active"' : ''; ?> href="#" data-entity="<?php the_ID(); ?>"></a>
												<span><?php echo (int) get_post_meta(get_the_ID(), 'likes', true); ?></span>
											</div>
											<a href="#" class="favorite"><i class="icon icon-star"></i><span>в избранное</span></a>
											<a class="comments"><?php comments_number('0', '1', '%'); ?></a>
											<div class="facebook-like">
												<div id="fb-root"></div>
												<script>
													$(function(){
														(function(d, s, id) {
															var js, fjs = d.getElementsByTagName(s)[0];
															if (d.getElementById(id)) return;
															js = d.createElement(s); js.id = id;
															js.src = "//connect.facebook.net/ru_RU/all.js#xfbml=1&appId=371760426267502";
															fjs.parentNode.insertBefore(js, fjs);
														}(document, 'script', 'facebook-jssdk'));
													})
												</script>
												<div class="fb-like" data-href="http://foody.dev" data-width="380" data-show-faces="false" data-send="false"></div>
											</div>
										</footer>
									</div>
								</article>
							</div>
						</div>
					</div>
					<div class="dish-container-left">
						<div class="dish-options">
							<div class="dish-switch">
								<a data-toggle="collapse" data-target="#dish-details" class="collapsed">дополнительная информация</a>
							</div>
							<div id="dish-details">
								<div class="dish-parameters">
									<div class="parameter">
										<div class="row1">
											<span class="value"><?php echo $meta['weight']; ?></span><span class="unit">гр.</span>
										</div>
										<div class="row2">
											<span class="type">вес</span>
										</div>
									</div>
									<div class="parameter">
										<div class="row1">
											<span class="value"><?php echo $meta['calories'] ? $meta['calories'] : '0'; ?></span><span class="unit">Ккал.</span>
										</div>
										<div class="row2">
											<span class="type">калории</span>
										</div>
									</div>
									<div class="parameter">
										<div class="row1"><span class="value"><?php echo $meta['price']; ?></span><span class="unit">лей</span></div>
										<div class="row2"><span class="type">цена</span></div>
									</div>
								</div>
<?php // @todo list categories below ?>
								<div class="dish-categories">
									<div class="category">
										<div class="title">Салат</div>
										<div class="type">тип блюда</div>
									</div>
									<div class="category">
										<div class="title">Греческий салат</div>
										<div class="type">вид еды</div>
									</div>
									<div class="category">
										<div class="title">Русская кухня</div>
										<div class="type">тип блюда</div>
									</div>
								</div>
								<div class="dish-location">
									<div class="heading"><?php echo $meta['restaurant']->post_title; ?></div>
<?php // @todo add working hours ?>
									<div class="time">9<sup>00</sup>-23<sup>00</sup></div>
									<address><?php echo get_post_meta($meta['restaurant']->ID, 'restaurant-address', true); ?><br><?php echo get_post_meta($meta['restaurant']->ID, 'restaurant-phone', true); ?></address>
									<a href="#create-path" class="create-path">проложить путь</a>
								</div>
								<div class="dish-footer">
									<div class="likes">
										<a <?php echo (bool)get_user_meta(get_current_user_id(), 'liked_' . $meta['restaurant']->ID, true) ? 'class="active"' : ''; ?> href="#" data-entity="<?php echo $meta['restaurant']->ID; ?>"></a>
										<span><?php echo (int) get_post_meta($meta['restaurant']->ID, 'likes', true); ?></span>
									</div>
									<a class="comments"><?php comments_number('0', '1', '%'); ?></a>
								</div>
							</div>
						</div>
						<div class="dish-banner">
							<a href="#">
								<img src="<?php echo TPLDIR; ?>/images/banner.jpg" alt="">
							</a>
						</div>
					</div>
					<div class="dish-comments">
						comments
					</div>
					<div class="clearfix"></div>
				</div>
			</div>
		</div>
	</section>

<?php
endif;

get_footer();
