<!--
- Copyright 2019 Jason H House
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <title>Gaps</title>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
    <link th:href="@{/images/gaps.ico}" rel="shortcut icon"/>
    <link th:href="@{/css/libraries/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/libraries/datatables.min.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/css/libraries/dataTables.bootstrap4.min.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/css/input.min.css}" rel="stylesheet">

    <!--Let browser know website is optimized for mobile-->
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
</head>

<body>
<div th:insert="fragments/header :: navBar"></div>

<div class="container">
    <h3 class="top-margin">Missing Movies</h3>

    <h4 class="top-margin text-primary" data-cy="libraryTitle"
        id="libraryTitle"
        th:text="${plexServer.friendlyName} + ' - ' + ${plexLibrary.title}"></h4>

    <div class="dropdown show">
        <a aria-expanded="false" aria-haspopup="true" class="btn btn-primary dropdown-toggle" data-cy="dropdownMenu"
           data-toggle="dropdown" href="#"
           id="dropdownMenuLink" role="button">
            Recommended
        </a>

        <div aria-labelledby="dropdownMenuLink" class="dropdown-menu">
            <div th:each="instance : ${plexServers}" th:remove="tag">
                <a class="dropdown-item"
                   data-ol-has-click-handler=""
                   href="javascript:void(0)"
                   onclick="switchPlexLibrary(this.getAttribute('data-machineIdentifier'), this.getAttribute('data-key'))"
                   th:data-cy="*{plexLibrary.title}"
                   th:data-key="*{plexLibrary.key}"
                   th:data-machineIdentifier="*{instance.value.machineIdentifier}"
                   th:each="plexLibrary : *{instance.value.plexLibraries}"
                   th:text="(*{instance.value.friendlyName} + ' - ' + *{plexLibrary.title})"></a>
            </div>
        </div>
    </div>

    <div class="top-margin bottom-margin" id="notSearchedYetContainer" style="display: none;">
        <div class="card mx-auto" style="width: 24rem;">
            <img loading="lazy" alt="..." class="card-img-top" th:src="@{/images/mind_the_gap.png}">
            <div class="card-body">
                <h5 class="card-title">Your movies are really missing</h5>
                <p class="card-text">You need to run Gaps at least once to have found the missing movies.</p>
                <a class="btn btn-primary" data-cy="searchForMovies" href="javascript:void(0)"
                   onclick="searchForMovies()">Search</a>
            </div>
        </div>
    </div>

    <div class="top-margin bottom-margin" id="noMovieContainer" style="display: none;">
        <div class="card mx-auto" style="width: 24rem;">
            <img loading="lazy" alt="..." class="card-img-top" src="/images/mind_the_gap.png">
            <div class="card-body">
                <h5 class="card-title">Your movies are really missing</h5>
                <p class="card-text">You need to find your owned movies first.</p>
            </div>
        </div>
    </div>

    <div class="top-margin bottom-margin" id="movieContainer" style="display: none;">

        <div id="searchContainer" style="display: none;">
            <div class="alert alert-primary alert-dismissible fade show gaps-hide" id="copiedToClipboard" role="alert">
                Copied to Clipboard
                <button aria-label="Close" class="close" data-dismiss="alert" type="button">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <h2 class="top-margin" id="searchTitle">Searching for Movies</h2>

            <div class="top-margin" id="searchDescription">
                <p>Finding all movies in Plex</p>
            </div>

            <div class="progress top-margin bottom-margin" id="progressContainer">
                <div aria-valuemax="100" aria-valuemin="0"
                     aria-valuenow="75"
                     class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar"
                     style="width: 100%"></div>
            </div>
        </div>

        <table aria-label="Table of Recommended Movies" class="display top-margin" id="movies" style="width:100%">
            <thead>
            <tr>
                <th scope="col">Movie</th>
                <th hidden scope="col">Title</th>
                <th hidden scope="col">Year</th>
                <th hidden scope="col">Language</th>
                <th hidden scope="col">Summary</th>
            </tr>
            </thead>
        </table>

        <button class="btn btn-secondary" onclick="copyToClipboard()" type="button">Copy</button>
        <button class="btn btn-secondary" onclick="searchForMovies()" type="button">Re-Search</button>
        <button class="btn btn-warning" onclick="cancel()" type="button">Cancel</button>
    </div>

</div>

<script id="movieCard" type="text/x-handlebars-template">
    <div class="card">
        <div class="row no-gutters">
            <div class="col-12 col-md-auto">
                <img loading="lazy" style="height: auto; width: 225px; display: block;"
                     data-cy="{{imdbId}}"
                     src="{{posterUrl}}"
                     class="card-img" alt="Plex Poster">
            </div>
            <div class="col-12 col-md">
                <div class="card-body">
                    <h5 class="card-title">{{name}} ({{year}})</h5>
                    <h6 class="card-title">{{collectionTitle}}</h6>
                    <p class="card-text text-muted long-text">{{overview}}</p>
                    <p class="card-text"><small class="text-info">English</small></p>
                    <div>
                        <span class="card-text">Owned</span><br>
                        {{#each moviesInCollection}}
                        {{#if this.owned}}
                        <a data-cy="{{@root.imdbId}}-{{this.tmdbId}}"
                           href="https://www.themoviedb.org/movie/{{this.tmdbId}}" class="card-link" target="_blank"
                           rel="noopener noreferrer">{{this.title}}</a>
                        {{/if}}
                        {{/each}}
                    </div>
                    <br>
                    <div>
                        <span class="card-text">Missing</span><br>
                        {{#each moviesInCollection}}
                        {{#if (isNotOwned this.owned)}}
                        <a data-cy="{{@root.imdbId}}-{{this.tmdbId}}"
                           href="https://www.themoviedb.org/movie/{{this.tmdbId}}" class="card-link" target="_blank"
                           rel="noopener noreferrer">{{this.title}}</a>
                        {{/if}}
                        {{/each}}
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>

<script id="updateSearchDescription" type="text/x-handlebars-template">
    <p class="card-text">{{searchedMovieCount}} of {{totalMovieCount}} movies searched. {{percentage}}% complete.</p>
</script>

<input id="plexServers" name="plexServers" th:value="${{plexServers}}" type="hidden"/>
<input id="plexServer" name="plexServer" th:value="${{plexServer}}" type="hidden"/>
<input id="plexProperties" name="plexProperties" th:value="${{plexProperties}}" type="hidden"/>
<input id="libraryKey" name="libraryKey" th:value="${{plexLibrary.key}}" type="hidden"/>
<div th:insert="fragments/common :: contextPath"></div>

<script th:src="@{/js/libraries/jquery-3.4.1.min.js}" type="text/javascript"></script>
<script th:src="@{/js/libraries/bootstrap.bundle.min.js}" type="text/javascript"></script>
<script th:src="@{/js/libraries/datatables.min.js}" type="text/javascript"></script>
<script th:src="@{/js/libraries/sockjs-1.4.0.min.js}" type="text/javascript"></script>
<script th:src="@{/js/libraries/stomp-2.3.3.min.js}" type="text/javascript"></script>
<script th:src="@{/js/libraries/handlebars-v4.7.6.min.js}" type="text/javascript"></script>
<script type="module" th:src="@{/js/page/recommended.min.js}"></script>
</body>
</html>