<!--
- 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 href="/images/gaps.ico" rel="shortcut icon"/>
    <link href="/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/css/datatables.min.css" rel="stylesheet" type="text/css"/>
    <link href="/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css"/>
    <link 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>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <a class="" href=".">
        <img src="/images/final-gaps.svg" class="d-inline-block align-top" alt="" width="96" height="96">
    </a>
    <div class="collapse navbar-collapse" id="navbarColor01">
        <ul class="navbar-nav mr-auto">
            <li aria-current="page" class="nav-item nav-button-padding active">
                <a class="nav-link center-text nav-anchor-spacing" href="/libraries">
                    <div class="icon list-ul-active"></div>
                    Libraries
                </a>
            </li>
            <li class="nav-item nav-button-padding">
                <a class="nav-link center-text nav-anchor-spacing" href="/recommended">
                    <div class="icon collection-fill-default"></div>
                    Missing
                </a>
            </li>
            <li class="nav-item nav-button-padding" hidden>
                <a class="nav-link center-text nav-anchor-spacing" href="/mislabeled">
                    <div class="icon exclamation-triangle-default"></div>
                    Mislabeled
                </a>
            </li>
            <li class="nav-item nav-button-padding">
                <a class="nav-link center-text nav-anchor-spacing" href="/rssCheck">
                    <div class="icon rss-default"></div>
                    RSS
                </a>
            </li>
            <li class="nav-item nav-button-padding">
                <a class="nav-link center-text nav-anchor-spacing" href="/configuration">
                    <div class="icon gear-default"></div>
                    Settings
                </a>
            </li>
            <li class="nav-item nav-button-padding">
                <a class="nav-link center-text nav-anchor-spacing" href="/updates">
                    <div class="icon arrow-clockwise-default"></div>
                    Updates
                </a>
            </li>
            <li class="nav-item nav-button-padding">
                <a class="nav-link center-text nav-anchor-spacing" href="/about">
                    <div class="icon info-circle-default"></div>
                    About
                </a>
            </li>
        </ul>
    </div>
</nav>

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

    <div th:if="${plexServersFound}" th:remove="tag">
        <h4 class="top-margin text-primary" 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-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)"
                       th:data-key="*{plexLibrary.key}"
                       th:data-machineIdentifier="*{instance.value.machineIdentifier}"
                       th:each="plexLibrary : *{instance.value.plexLibraries}"
                       onclick="switchPlexLibrary(this.getAttribute('data-machineIdentifier'), this.getAttribute('data-key'))"
                       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" 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" href="javascript:void(0)" onclick="searchForMovies()">Search</a>
                </div>
            </div>
        </div>

        <div class="top-margin bottom-margin" id="movieContainer" style="display: none;">
            <table class="display" id="movies" style="width:100%">
                <thead>
                <tr>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></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" 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 style="height: auto; width: 225px; display: block;"
                     src="http://{{address}}:{{port}}{{poster_url}}/?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="plexSearch" name="plexSearch" th:value="${{plexSearch}}" type="hidden"/>
<input id="libraryKey" name="libraryKey" th:value="${{plexLibrary.key}}" type="hidden"/>

<script src="/js/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="/js/bootstrap.bundle.min.js" type="text/javascript"></script>
<script src="/js/datatables.min.js" type="text/javascript"></script>
<script src="/js/handlebars-v4.7.6.min.js" type="text/javascript"></script>
<script type="module" src="/js/libraries.min.js"></script>
</body>
</html>