<!-- Movie tab -->
<div role="tabpanel" class="tab-pane active" id="MoviesTab">
    <div class="input-group">
        <input id="search" type="text" class="form-control form-control-custom form-control-search form-control-withbuttons" (keyup)="search($event)">
        <div class="input-group-addon right-radius">
            <div class="btn-group">
                <a href="#" class="btn btn-sm btn-primary-outline dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                    Suggestions
                    <i class="fa fa-chevron-down"></i>
                </a>
                <ul class="dropdown-menu">
                    <li>
                        <a (click)="popularMovies()">Popular Movies</a>
                    </li>
                    <li>
                        <a (click)="upcomingMovies()">Upcoming Movies</a>
                    </li>
                    <li>
                        <a (click)="topRatedMovies()">Top Rated Movies</a>
                    </li>
                    <li>
                        <a (click)="nowPlayingMovies()">Now Playing Movies</a>
                    </li>
                </ul>
            </div>
            <i id="movieSearchButton" class="fa fa-search"></i>
        </div>
    </div>
    <br />
    <br />
    <!-- Movie content -->
    <div id="movieList">
        <div *ngIf="searchApplied && movieResults?.length <= 0" class='no-search-results'>
            <i class='fa fa-film no-search-results-icon'></i>
            <div class='no-search-results-text'>Sorry, we didn't find any results!</div>
        </div>

        <!--NEW-->
        <div *ngFor="let grid of movieResultGrid; let i = index">
            <div class="row">
                <div *ngFor="let r of grid.movies">
                    <div class="col-md-3">

                        <img *ngIf="r.posterPath" class="img-responsive poster" src="https://image.tmdb.org/t/p/w150/{{r.posterPath}}"
                            alt="poster">

                    </div>
                </div>
            </div>
        </div>
        <!--END NEW-->

        <br/>
        <br/>
        <br/>

        <hr/>
        <div *ngFor="let result of movieResults">
            <div class="row">
                <div id="imgDiv" class="col-sm-2">


                    <img *ngIf="result.posterPath" class="img-responsive poster" src="https://image.tmdb.org/t/p/w150/{{result.posterPath}}"
                        alt="poster">

                </div>
                <div class="col-sm-8">
                    <div>
                        <a href="https://www.themoviedb.org/movie/{{result.id}}/" target="_blank">
                            <h4>{{result.title}} ({{result.releaseDate | date: 'yyyy'}})</h4>
                        </a>

                        <span *ngIf="result.releaseDate" class="label label-info" target="_blank">Release Date: {{result.releaseDate | date: 'dd/MM/yyyy'}}</span>

                        <a *ngIf="result.homepage" href="{{result.homepage}}" id="homepageLabel" target="_blank">
                            <span class="label label-info">HomePage</span>
                        </a>

                        <a *ngIf="result.trailer" href="{{result.trailer}}" id="trailerLabel" target="_blank">
                            <span class="label label-info">Trailer</span>
                        </a>
                        <span *ngIf="result.quality" class="label label-success" id="qualityLabel">{{result.quality}}p</span>

                        <ng-template [ngIf]="result.available">
                            <span class="label label-success"  id="availableLabel">Available</span>
                        </ng-template>
                        <ng-template [ngIf]="result.approved && !result.available">
                            <span class="label label-info" id="processingRequestLabel">Processing Request</span>
                        </ng-template>
                        <ng-template [ngIf]="result.requested && !result.approved && !result.available">
                            <span class="label label-warning" id="pendingApprovalLabel">Pending Approval</span>
                        </ng-template>
                        <ng-template [ngIf]="!result.requested && !result.available && !result.approved">
                            <span class="label label-danger" id="notRequetsedLabel">Not Requested</span>
                        </ng-template>




                        <br/>
                        <br/>
                    </div>
                    <p style="font-size: 0.9rem !important">{{result.overview}}</p>
                </div>


                <div class="col-sm-2">

                    <div *ngIf="result.available">
                        <button style="text-align: right" class="btn btn-success-outline disabled" disabled>
                            <i class="fa fa-check"></i> Available</button>

                        <div *ngIf="result.plexUrl">
                            <br/>
                            <br/>
                            <a style="text-align: right" class="btn btn-sm btn-primary-outline" href="{{result.plexUrl}}" target="_blank">
                                <i class="fa fa-eye"></i> View In Plex</a>

                        </div>
                    </div>
                    <div *ngIf="!result.available">
                        <div *ngIf="result.requested || result.approved; then requestedBtn else notRequestedBtn"></div>
                        <ng-template #requestedBtn>
                            <button style="text-align: right" class="btn btn-primary-outline disabled" [disabled]>
                                <i class="fa fa-check"></i> Requested</button>
                        </ng-template>
                        <ng-template #notRequestedBtn>
                            <button id="{{result.id}}" style="text-align: right" class="btn btn-primary-outline" (click)="request(result)">
                                <i *ngIf="result.requestProcessing" class="fa fa-circle-o-notch fa-spin fa-fw"></i>
                                <i *ngIf="!result.requestProcessing && !result.processed" class="fa fa-plus"></i>
                                <i *ngIf="result.processed && !result.requestProcessing" class="fa fa-check"></i>Request</button>
                        </ng-template>
                    </div>

                    <br/>
                    <div *ngIf="result.available">
                        <a *ngIf="result.plexUrl" style="text-align: right" class="btn btn-sm btn-success-outline" href="{{result.plexUrl}}" target="_blank">
                            <i class="fa fa-eye"></i> View On Plex</a>

                    </div>

                </div>

            </div>
            <hr/>
        </div>

    </div>
</div>