{% extends "base.html" %}
{% block title %} Moviestar Keyword Search {% endblock %}
{% block script %}
<script type="text/javascript" src="{{ url_for('static', filename='delete.js') }}"></script>
{% endblock %} 
{% block content %} 

	<div class="search-container">
		<form method="post" action="{{ url_for('moviestars.search') }}">
			<input id="text" type="text" placeholder="Search for Moviestar" name="keyword">
			<button class="w3-button w3-black" type="submit">Search</button>
		</form>
	</div>

<h1>Search Results for Keyword: {{ keyword }} in Moviestar's Name</h1>

	{% set nItems = moviestars|length %}
	
	{% if nItems == 0 %}
		<div class="w3-panel w3-pale-red w3-border">
			<h3> Keyword Search Results for Keyword: {{ keyword }} in Moviestar Name </h3>
			<p> Unfortunately your search returned 0 results. </p>
		</div>
	{% else %}
		<div class="w3-panel w3-pale-green w3-border">
			<h3> Keyword Search Results for Keyword: {{ keyword }} in Moviestar Name </h3>
			<p> Your search returned {{ nItems }} results. </p>
		</div>
		
		{% set count = namespace(value=0) %}
		{% set starcount = namespace(value=0) %}
		
			{% for star in moviestars %}
				{% set starcount.value = starcount.value + 1 %}
				{% set starid = "star" + starcount.value|string %}
				

			<div class="w3-container w3-light-grey w3-teal w3-border w3-padding-32">
				<span id="{{ starid }}">

					<h3>  {{ star.Star_Name }} </h3>
					
					<p> ID: {{ star.Star_ID }} </p>
				
					<p> <a class="alink" href="{{ url_for('moviestars.editMoviestar', Id=star.Star_ID) }}"> Edit Moviestar </a> </p>
					
					<p><a class="alink" href="#" 
					onclick="deleteEntity('{{ starid }}','{{ url_for('moviestars.delete',Id=star.Star_ID) }}','{{ star.Star_Name }}')">
					Delete Moviestar {{ star.Star_Name }} </a> </p>
					
				<div class="w3-panel w3-padding-32 w3-pale-green w3-teal w3-border">
					<h4 class="header">Movies Featuring {{ star.Star_Name }} </h4>
					{% if star.movie|length == 0 %}
						<p>{{ star.Star_Name }} has not featured in any movies</p>
					{% else %}
						<ul class="w3-ul">
							<table class="tabledata">
							
								{% for _movie in star.movie %}
								
									{% set count.value = count.value + 1 %}
									{% set rowid = 'row' + count.value|string %}
									
									<tr id="{{ rowid }}">
										<td><li> <a href="{{ url_for('movies.movieDetails', Id=_movie.Movie_ID) }}"> 
										{{ _movie.Movie_Title }} </a></li></td>
										
										<td><a class="alink" href="{{ url_for('movies.editMovie',Id=_movie.Movie_ID) }}">
										Edit Movie {{ _movie.Movie_Title }}</a></td>
										
										<td><a class="alink" href="#"
										onclick="deleteAndHideRow('{{ rowid }}',
										'{{ url_for('moviestars.removeMovie',Id=star.Star_ID, movieId=_movie.Movie_ID) }}'
										,'{{ star.Star_Name }}','{{ _movie.Movie_Title }}')">
										Remove Movie {{ _movie.Movie_Title }} from list</a></td>
										
									</tr>
								{% endfor %}
							</table>
						</ul>
					{% endif %}
					
					<p><a class="alink" href="{{ url_for('moviestars.addMovie', Id=star.Star_ID) }}"> 
					Add Movie for {{ star.Star_Name }} </a> </p>
				</div>
				</span>
			</div>
			{% endfor %}
		
	{% endif %}

{% endblock %}