<!--
- 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">Libraries</h3>

    <div th:if="${plexServersFound}" th:remove="tag">
        <h4 class="top-margin text-primary" data-cy="libraryTitle"
            id="libraryTitle"
            th:data-key="*{plexLibrary.key}"
            th:data-machineIdentifier="*{plexServer.machineIdentifier}"
            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">Libraries</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="movieSearchingContainer" style="display: none;">
            <div class="d-flex justify-content-center top-margin ">
                <div class="spinner-border text-primary" role="status">
                    <span class="sr-only">Searching Plex for Movies</span>
                </div>
            </div>
            <div class="d-flex justify-content-center top-margin">
                <p class="card-text">Searching Plex for Movies</p>
            </div>
        </div>

        <div class="top-margin bottom-margin" id="noMovieContainer" style="display: none;">
            <div class="card mx-auto" style="width: 24rem;">
                <img alt="..." class="card-img-top" loading="lazy" 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="movieContainer" style="display: none;">
            <table aria-label="Table of Owned Movies" class="display" id="movies" style="width:100%">
                <thead>
                <tr>
                    <th scope="col"></th>
                    <th scope="col"></th>
                    <th scope="col"></th>
                    <th scope="col"></th>
                    <th scope="col"></th>
                </tr>
                </thead>
            </table>

            <a class="top-margin btn btn-primary" href="javascript:void(0)" onclick="searchForMovies()">Search</a>
        </div>
    </div>
    <div th:remove="tag" th:unless="${plexServersFound}">
        <div class="top-margin bottom-margin">
            <div class="card mx-auto" style="width: 24rem;">
                <img alt="..." class="card-img-top" loading="lazy" 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 configure Gaps before you can search for missing movies. Check out
                        the <a href="https://github.com/JasonHHouse/Gaps/blob/master/README.md">README</a> file.</p>
                </div>
            </div>
        </div>
    </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" data-cy="{{imdbId}}" style="height: auto; width: 225px; display: block;"
                     src="http://{{address}}:{{port}}{{posterUrl}}/?X-Plex-Token={{plexToken}}"
                     class="card-img" alt="Plex Poster">
            </div>
            <div class="col-12 col-md">
                <div class="card-body">
                    <h5 class="card-title">{{name}} ({{year}})</h5>
                    <p class="card-text text-muted">{{overview}}</p>
                    <p class="card-text"><small class="text-info">English</small></p>
                </div>
            </div>
        </div>
    </div>
</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/handlebars-v4.7.6.min.js}" type="text/javascript"></script>
<script type="module" th:src="@{/js/page/libraries.min.js}"></script>
</body>
</html>