{% load staticfiles %}
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>{{ show_data.show_title }}</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<style type="text/css">
    @import url(https://fonts.googleapis.com/css?family=Lato:400,300,700);
@import url(https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css);
*, *:before, *:after {
  box-sizing: border-box;
}
body {
  background: #43423E;
}
a {
  text-decoration: none;
  color: #5C7FB8;
}

a:hover {
  text-decoration: underline;
}

.movie-card {
  font: 14px/22px "Lato", Arial, sans-serif;
  color: #A9A8A3;
  padding: 40px 0;
}

.container {
  margin: 0 auto;
  width: 780px;
  height: 640px;
  background: #F0F0ED;
  border-radius: 5px;
  position: relative;
}

.hero {
  height: 342px;
  margin: 0;
  position: relative;
  overflow: hidden;
  z-index: 1;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

.hero:before {
  content: '';
  width: 100%;
  height: 100%;
  position: absolute;
  overflow: hidden;
  top: 0;
  left: 0;
  background: url("{% static 'images/blur_bg.jpg' %}");
  background-repeat: no-repeat;
  background-size: cover;
  z-index: -1;
  -webkit-transform: skewY(-2.2deg);
          transform: skewY(-2.2deg);
  -webkit-transform-origin: 0 0;
          transform-origin: 0 0;
  -webkit-backface-visibility: hidden;
}

.cover {
  position: absolute;
  top: 160px;
  left: 40px;
  z-index: 2;
}

.details {
  padding: 190px 0 0 280px;
}
.details .title1 {
  color: white;
  font-size: 44px;
  margin-bottom: 13px;
  position: relative;
  line-height: 1.0;
}
.details .title1 span {
  position: absolute;
  top: 3px;
  margin-left: 12px;
  background: #C4AF3D;
  border-radius: 5px;
  color: #544C21;
  font-size: 14px;
  padding: 0px 4px;
}
.details .title2 {
  color: #C7C1BA;
  font-size: 23px;
  font-weight: 300;
  margin-bottom: 15px;
}
.details .likes {
  margin-left: 24px;
}
.details .likes:before {
  content: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/195612/icon_like.png");
  position: relative;
  top: 2px;
  padding-right: 7px;
}

.description {
  bottom: 0px;
  height: 200px;
  font-size: 16px;
  line-height: 26px;
  color: #B1B0AC;
}

.column1 {
  padding-left: 50px;
  padding-top: 120px;
  width: 220px;
  float: left;
  text-align: center;
}

.tag {
  background: white;
  border-radius: 10px;
  padding: 3px 8px;
  font-size: 14px;
  margin-right: 4px;
  line-height: 35px;
  cursor: pointer;
}

.tag:hover {
  background: #ddd;
}

.column2 {
  padding-left: 41px;
  padding-top: 30px;
  margin-left: 20px;
  width: 480px;
  float: left;
}


fieldset, label {
  margin: 0;
  padding: 0;
}

/****** Style Star Rating Widget *****/
.rating {
  border: none;
  float: left;
}

.rating > input {
  display: none;
}

.rating > label:before {
  margin: 5px;
  margin-top: 0;
  font-size: 1.5em;
  font-family: FontAwesome;
  display: inline-block;
  content: "\f005";
}

.rating > .half:before {
  content: "\f089";
  position: absolute;
}

.rating > label {
  color: #ddd;
  float: right;
}

/***** CSS Magic to Highlight Stars on Hover *****/
.rating > input:checked ~ label,
.rating:not(:checked) > label:hover,
.rating:not(:checked) > label:hover ~ label {
  color: #FFD700;
}

/* hover previous stars in list */
.rating > input:checked + label:hover,
.rating > input:checked ~ label:hover,
.rating > label:hover ~ input:checked ~ label,
.rating > input:checked ~ label:hover ~ label {
  color: #FFED85;
}
a[data-tooltip] {
  position: relative;
}
a[data-tooltip]::before,
a[data-tooltip]::after {
  position: absolute;
  display: none;
  opacity: 0.85;
}

a[data-tooltip]::before {
  /*
   * using data-tooltip instead of title so we
   * don't have the real tooltip overlapping
   */
  content: attr(data-tooltip);
  background: #000;
  color: #fff;
  font-size: 13px;
  padding: 5px;
  border-radius: 5px;
  /* we don't want the text to wrap */
  white-space: nowrap;
  text-decoration: none;
}

a[data-tooltip]::after {
  width: 0;
  height: 0;
  border: 6px solid transparent;
  content: '';
}

a[data-tooltip]:hover::before,
a[data-tooltip]:hover::after {
  display: block;
}

/** positioning **/
/* top tooltip */
a[data-tooltip][data-placement="top"]::before {
  bottom: 100%;
  left: 0;
  margin-bottom: 40px;
}

a[data-tooltip][data-placement="top"]::after {
  border-top-color: #000;
  border-bottom: none;
  bottom: 50px;
  left: 20px;
  margin-bottom: 4px;
}
    .inline-block {
   display: inline-block;
}
</style>
</head>
<body>
  <div class="movie-card">
  <div class="container">
    <img src="{{ show_data.show_link }}" width="187px" height="282px" alt="cover" class="cover" />
    <div class="hero">
      <div class="details">
        <div class="title1">{{ show_data.show_title }}</div>
            <fieldset class="rating">
            <input onclick="rateAjax(this.value)" type="radio" id="star5" name="rating" value="5" /><label class = "full" for="star5" title="5 stars"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="star4half" name="rating" value="4.5" /><label class="half" for="star4half" title="4.5 stars"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="star4" name="rating" value="4"/><label class = "full" for="star4" title="4 stars"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="star3half" name="rating" value="3.5" /><label class="half" for="star3half" title="3.5 stars"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="star3" name="rating" value="3" /><label class = "full" for="star3" title="3 stars"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="star2half" name="rating" value="2.5" /><label class="half" for="star2half" title="2.5 stars"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="star2" name="rating" value="2" /><label class = "full" for="star2" title="2 stars"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="star1half" name="rating" value="1.5" /><label class="half" for="star1half" title="1.5 stars"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="star1" name="rating" value="1" /><label class = "full" for="star1" title="1 star"></label>
            <input onclick="rateAjax(this.value)" type="radio" id="starhalf" name="rating" value="0.5" /><label class="half" for="starhalf" title="0.5 stars"></label>
          </fieldset>

        <span class="likes">Avg Rating &nbsp;{{show_data.show_rating}}</span>
      <span class="likes">My Rating &nbsp;{{rating_value}}</span>
      </div> <!-- end details -->
    </div> <!-- end hero -->
    <div class="description">
            <div class="column1">
                    <span class="tag">{{ show_data.show_genre }}</span>
      </div> <!-- end column1 -->
      <div class="column2">
        <p>{{ show_data.show_plot }}</p>
      </div> <!-- end column2 -->
    </div> <!-- end description -->
  </div> <!-- end container -->
</div> <!-- end movie-card -->
          <div class="container" style="height: 300px;width: 1000px;margin-top: 20px">
          <div style="padding:20px;">
            <p style="font-weight: bold;font-size: 28px;font-family:Sans-Serif">
                Similar TV Shows to this item
            </p>
            <ul>
            {% for p in similar_tvshows %}
                        <li style="margin-left: 20px" class="inline-block">
                            <a  href="{% url 'tvshows:detail' %}?title={{ p.show_title }}">
                                <img src="{{ p.show_link }}" height="195px" width="130px" alt="" />
                                <p style="width: 128px">{{ p.show_title}}</p>
                                </a>
                        </li>
                <a href="{% url 'tvshows:detail' %}?title={{ p.show_title }}"></a>
            {% endfor %}

</ul>
</div>
      </div>
      <div class="container" style="height: 300px;width: 1000px;margin-top: 20px">
          <div style="padding:20px;">
            <p style="font-weight: bold;font-size: 28px;font-family:Sans-Serif">
                Similar Movies to this item
            </p>
            <ul>
            {% for p in similar_movies %}
                        <li style="margin-left: 20px" class="inline-block">
                            <a  href="{% url 'movies:detail' %}?title={{ p.movie_title }}">
                                <img src="{{ p.movie_link }}" height="195px" width="130px" alt="" />
                                <p style="width: 128px">{{ p.movie_title}}</p>
                                </a>
                        </li>
                <a href="{% url 'movies:detail' %}?title={{ p.movie_title }}"></a>
            {% endfor %}

</ul>
</div>
      </div>
        <div class="container" style="height: 300px;width: 1000px;margin-top: 20px">
          <div style="padding:20px;">
            <p style="font-weight: bold;font-size: 28px;font-family:Sans-Serif">
                Similar Books to this item
            </p>
            <ul>
            {% for p in similar_books %}
                        <li style="margin-left: 20px" class="inline-block">
                            <a  href="{% url 'books:detail' %}?title={{ p.book_title }}">
                                <img src="{{ p.book_link }}" height="195px" width="130px" alt="" />
                                <p style="width: 128px">{{ p.book_title}}</p>
                                </a>
                        </li>
                <a href="{% url 'books:detail' %}?title={{ p.book_title }}"></a>
            {% endfor %}

</ul>
</div>
      </div>
  </div>
</body>
</html>


<!--Ajax part-->
<script type="text/javascript">
	function rateAjax(ratingValue){
            var url="{% url 'tvshows:rate' %}?show_id={{show_data.show_id}}&rating="+ratingValue;
			console.log(url)
			var req=new XMLHttpRequest();
			req.open('GET',url)
			req.onload=function()
			{
				console.log(req.responseText);
				alert("Success. Given "+ratingValue+" rating to {{ show_data.show_title }}.");
				location.reload();
			};
			req.send();
	}
</script>

<script>
    function getId(rating) {
        var ans=0;
        if(rating=='0.5'){
                ans='starhalf';
            }
            else if(rating=='1.0'){
                ans='star1';
            }
            else if(rating=='1.5') {
                ans = 'star1half'
            }
            else if(rating=='2.0'){
                ans='star2'
            }
            else if(rating=='2.5'){
                ans='star2half'
            }
            else if(rating=='3.0'){
                ans='star3'
            }
            else if(rating=='3.5'){
                ans='star3half'
            }
            else if(rating=='4.0'){
                ans='star4'
            }
            else if(rating=='4.5'){
                ans='star4half'
            }
            else if(rating=='5.0'){
                ans='star5'
            }
            return ans;
    }
</script>
<script>
    var id=getId("{{ rating_value }}");
    elem=document.getElementById(id);
    elem.checked=true;
    //console.log(elem);
</script>
