@extends('hello')

@section('content')
<div class="page-header">
	<h1>{{ $film->name }} <small>{{ $tfilm['tagline']}}</small></h1>
</div>

<div class="row">
	<div class="col-md-3">
		@if(!is_null($film->gesehen))
			<div class="label label-success"><span class="glyphicon glyphicon-check"></span> Gesehen am {{ \Carbon\Carbon::parse($film->gesehen)->format('d.m.Y') }}</div>
		@elseif(!is_null($film->abgelehnt))
			<div class="label label-warning"><span class="glyphicon glyphicon-remove"></span> Abgelehnt am {{ \Carbon\Carbon::parse($film->abgelehnt)->format('d.m.Y') }}</div>
		@else
			<div class="label label-danger" <?php if(!is_null(Auth::user()) && Auth::user()->admin) { echo "id='gesehen'"; } ?> style="cursor: pointer;"><span class="glyphicon glyphicon-unchecked"></span> Nicht gesehen</div>
		@endif
			<span class="label label-info">
				<img class="img-circle" src="{{ $film->besitzer->getAvatar() }}" width="16"> {{$film->besitzer->name}}
			</span>
	</div>
	<div class="col-md-9">
		<ul class="nav nav-pills">
			<li class="active"><a href="#ueberblick" data-toggle="tab">Überblick</a></li>
			<li><a href="#cast" data-toggle="tab">Schauspieler</a></li>
			<li><a href="#trailer" data-toggle="tab">Trailer</a></li>
		</ul>
	</div>
</div>
<div class="row">
	<div class="col-md-3 thumbnail">
		<img src="{{ $poster }}" alt="{{ $film->name }} Poster">
	</div>

	<div class="col-md-9 tab-content">
		<div class="tab-pane active" id='ueberblick'>
			<div class="pull-right">
				<a class="btn btn-xs btn-primary" href="http://themoviedb.org/movie/{{ $film->tvdbid }}">themoviedb.org</a>
				<a class="btn btn-xs btn-warning" href="http://imdb.com/title/{{ $tfilm['imdb_id'] }}">IMDB</a>
			</div>
			<dl class="dl-horizontal">
				<dt>Originaltitel</dt>
				<dd>{{ $tfilm['original_title'] }}</dd>
				<dt>Erschienen</dt>
				<dd>
					{{ \Carbon\Carbon::parse($tfilm['release_date'])->format('d.m.Y')}} -
					@foreach($tfilm['production_countries'] as $pc)
						<abbr title="{{$pc['name']}}">{{$pc['iso_3166_1']}}</abbr> 
					@endforeach
					@foreach($tfilm['production_companies'] as $pc)
						- {{$pc['name']}}
					@endforeach
				</dd>
				<dt>Genre</dt>
				<dd>
					@foreach($tfilm['genres'] as $g)
						<span class="label label-default">{{$g['name']}}</span>
					@endforeach
				</dd>
				<dt>Bewertung</dt>
				<dd>{{ $tfilm['vote_average']}} von 10 </dd>
				@if($film->getBewertung() > 0)
					<dt>Eigene Bewertung</dt>
					<dd>
						<div class="label label-{{$labels[round($film->getBewertung())]}}">{{$film->getBewertung()}}</div>
					</dd>
				@endif
				@for($i = 0; $i < 3 && $i < count($cast['crew']); $i++)
					<dt>{{$cast['crew'][$i]['job']}}</dt>
					<dd>{{$cast['crew'][$i]['name']}}</dd>
				@endfor

				<p></p>
				<dt>Inhalt</dt>
				<dd>{{ nl2br($tfilm['overview']) }}</dd>
			</dl>
		</div>
		<div class="tab-pane" id="cast">
				<div class="row" style="margin-top:10px;">
				@for($i = 0; $i < 10 && $i < count($cast['cast']); $i++)
					<div class="col-md-6">
						<div class="pull-left" style="margin-right:5px; min-height: 80px;"><img class="media-object" src="{{ !is_null($cast['cast'][$i]['profile_path']) ? $tmdb->getImageUrl($cast['cast'][$i]['profile_path'], TMDb::IMAGE_PROFILE, 'w185') : asset("img/no-avatar.jpg") }}" alt="{{$cast['cast'][$i]['name']}}" width="55"></div>
						<div class="media-body">
							<h4 class="media-heading">{{$cast['cast'][$i]['name']}}</h4>
							{{$cast['cast'][$i]['character']}}
						</div>
					</div>
					@if($i % 2 == 1)
				</div><div class="row">
					@endif
				@endfor
				</div>
		</div>
		<div class="tab-pane" id="trailer">
			@foreach($trail['youtube'] as $yt)
				<p></p><iframe width="420" height="315" src="//www.youtube.com/embed/{{ $yt['source'] }}" frameborder="0" allowfullscreen></iframe>
			@endforeach
		</div>
	</div>
</div>

<div class="clearfix"></div>
<hr>
@if($votes > 0 || is_null($film->gesehen) || is_null($film->abgelehnt))
@if($votes > 0)
<h2>Abstimmung</h2>
<p>Insgesamt haben <b>{{$votes}}</b> Personen abgestimmt. <b>{{$vposi}}</b> davon waren <i>daf&uuml;r</i>. @if($uvote[0])
	Du hast <i>{{ $uvote[1] ? "daf&uuml;r" : "nicht daf&uuml;r"}}</i> gestimmt.
@endif
</p>
<dl class="dl-horizontal">
	<dt>Daf&uuml;r</dt>
	<dd>
		@foreach($pv as $v)
			<span class="badge" {{ $v->getSetting('disabled') ? 'style="color: #c77; font-style: italic;"' : '' }}>
				<img class="img-circle" src="{{ $v->getAvatar() }}" width="20"> {{$v->name}}
			</span>&nbsp;
		@endforeach
	</dd>
	<p></p>
	<dt>Nicht daf&uuml;r</dt>
	<dd>
		@foreach($nv as $v)
			<span class="badge" {{ $v->getSetting('disabled') ? 'style="color: #c77; font-style: italic"' : '' }}>
				<img class="img-circle" src="{{ $v->getAvatar() }}" width="20"> {{$v->name}}
			</span>&nbsp;
		@endforeach
	</dd>
</dl>


@endif
@if(is_null($film->gesehen) && is_null($film->abgelehnt) && !is_null(Auth::user()))
<div class="container" style="text-align: center">
	<div class="btn-group">
		<a class="btn btn-lg btn-success <?php echo $uvote[0] && $uvote[1] ? "disabled" : ""; ?>" href="{{ url('vote', array('yes', Auth::user()->id, $film->id)) }}">
			<span class="glyphicon glyphicon-thumbs-up"></span> Daf&uuml;r
		</a>
		<a class="btn btn-lg btn-default <?php echo $uvote[0] && !$uvote[1] ? "disabled" : ""; ?>"  href="{{ url('vote', array('no', Auth::user()->id, $film->id)) }}">
			<span class="glyphicon glyphicon-hand-right"></span> Nicht daf&uuml;r
		</a>
	</div>
</div>
@endif
<hr>@endif

<h2>Kommentare</h2>

@if(is_null(Auth::user()))
<p>Melde Dich an, um diesen Film zu kommentieren.</p>
@else
<div class="media">
	<div class="pull-left">
		<img class="media-object" src="{{ Auth::user()->getAvatar() }}" width="64">
	</div>
	<div class="media-body">
		<h4 class="media-heading">Neuer Kommentar</h4>
		{{Form::open(array('route' => 'comment'))}}
			@if(!is_null(Auth::user()) && !is_null($film->gesehen) && Comment::where('user', Auth::user()->id)->where('film', $film->id)->where('bewertung', '>', 0)->count() < 1 )
				<p><div class="pull-left" style="margin-right: 5px">Bewerten:</div>
					<div class="btn-group btn-group-xs" data-toggle="buttons">
						@for($i = 1; $i < 11; $i++)
						<label class="btn btn-{{ $labels[$i] }}">
							<input type="radio" name="rate" id="rate{{ $i }}" value="{{ $i }}"> {{ $i }}
						</label>
						@endfor
					</div>
				</p>
			@endif
			<input type="hidden" name="user" value="{{Auth::user()->id}}">
			<input type="hidden" name="film" value="{{$film->id}}">
			<div class="form-group"><textarea class="form-control" rows="1" name="text"></textarea></div>
			<div class="form-group"><button type="submit" class="btn btn-primary btn-xs">Absenden</button></div>
		{{Form::close()}}
	</div>
</div>
@endif

@foreach($comments as $comment)

<div class="media">
	<div class="pull-left">
		<img class="media-object" src="{{ $comment->autor->getAvatar() }}" alt="{{ $comment->autor->name }}" width="64">
	</div>
	<div class="media-body" id="comment{{$comment->id}}">
		<h5 class="media-heading">{{ $comment->autor->name }} <small>{{\Carbon\Carbon::parse($comment->created_at)->format('d.m.Y H:i')}}
		@if($comment->updated_at != $comment->created_at)
		 &mdash; Zuletzt bearbeitet: {{\Carbon\Carbon::parse($comment->updated_at)->format('d.m.Y H:i')}}
		@endif
		</small></h5>
		@if(!is_null(Auth::user()) && Auth::user()->id === $comment->autor->id)
		<div class="collapse in" data-parent="#comment{{$comment->id}}" id="comment{{$comment->id}}comment">
			@if($comment->bewertung > 0)
			<div class="pull-left label label-{{ $labels[$comment->bewertung] }}"  style="margin-right: 5px;">{{$comment->bewertung}}</div>
			@endif
			<p>{{$comment->text}}</p>
			<button type="button" class="btn btn-default btn-xs" onclick="toggleComment('#comment{{$comment->id}}')">Bearbeiten</button>
		</div>
		<div class="collapse" id="comment{{$comment->id}}edit">
			{{Form::open(array('route' => 'modcomment'))}}
				@if($comment->bewertung > 0)
					<p><div class="pull-left" style="margin-right: 5px">Bewerten:</div>
						<div class="btn-group btn-group-xs" data-toggle="buttons">
							@for($i = 1; $i < 11; $i++)
							<label class="btn btn-{{ $labels[$i] }}">
								<input type="radio" name="rate" id="rate{{ $i }}" value="{{ $i }}"> {{ $i }}
							</label>
							@endfor
						</div>
					</p>
				@endif
				<input type="hidden" name="id" value="{{$comment->id}}">
				<div class="form-group"><textarea class="form-control" rows="1" name="text">{{$comment->text}}</textarea></div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-xs">Absenden</button>
					<button type="button" class="btn btn-default btn-xs" onclick="toggleComment('#comment{{$comment->id}}')">Abbrechen</button>
				</div>
			{{Form::close()}}
		</div>
		@else
		@if($comment->bewertung > 0)
			<div class="pull-left label label-{{ $labels[$comment->bewertung] }}" style="margin-right: 5px;">{{$comment->bewertung}}</div>
		@endif
		<p>{{$comment->text}}</p>
		@endif
	</div>
</div>
@endforeach



@stop

@section('script')
<script type="text/javascript">
	function toggleComment(id) {
		$(id + 'edit').collapse('toggle');
		$(id + 'comment').collapse('toggle');
	}

	$(function () {
		$('[data-toggle="tooltip"]').tooltip()
	})

	$(function() {
		$('#gesehen').popover({
			html: true,
			placement: "right",
			trigger: "click",
			title: "Als gesehen markieren",
			content: "<div class='container'><a href='{{ url('mark-read/' . $film->id) }}' class='btn btn-success'>Gesehen</a><a href='{{ url('view-next/' . $film->id) }}' class='btn btn-warning'>Als n&auml;chstes sehen</a><a href='{{ url('mark-declined/' . $film->id) }}' class='btn btn-danger'>Ablehnen</a></div>"
		});
	});
</script>
@stop

@section('title')
{{ $film->name }} ~ 
@stop
