<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Trilium Notes</title>
  </head>
  <body>
    <div id="container" style="display:none;">
      <div id="header" class="hide-toggle">
        <div id="header-title">
          <img src="/images/app-icons/png/24x24.png">

          Trilium Notes
        </div>

        <div style="flex-grow: 100;">
          <button class="btn btn-xs" id="jump-to-note-button" title="CTRL+J">Jump to note</button>
          <button class="btn btn-xs" id="recent-notes-button" title="CTRL+E">Recent notes</button>
          <button class="btn btn-xs" id="recent-changes-button">Recent changes</button>
        </div>

        <div id="plugin-buttons">
        </div>

        <div>
          <button class="btn btn-xs" id="sync-now-button" title="Number of outstanding changes to be pushed to server">
            <span class="ui-icon ui-icon-refresh"></span>

            Sync now (<span id="changes-to-push-count">0</span>)
          </button>

          <button class="btn btn-xs" id="options-button">
            <span class="ui-icon ui-icon-gear"></span> Options</button>

          <form action="logout" id="logout-button" method="POST" style="display: inline;">
            <input type="submit" class="btn btn-xs" value="Logout">
          </form>
        </div>
      </div>

      <div class="hide-toggle" style="grid-area: tree-actions;">
        <div style="display: flex; justify-content: space-around; padding: 10px 0 10px 0; margin: 0 20px 0 20px; border: 1px solid #ccc;">
          <a id="create-top-level-note-button" title="Create new top level note" class="icon-action"
             style="background: url('/images/icons/file-plus.png')"></a>

          <a id="collapse-tree-button" title="Collapse note tree" class="icon-action"
             style="background: url('/images/icons/list.png')"></a>

          <a id="scroll-to-current-note-button" title="Scroll to current note. Shortcut CTRL+." class="icon-action"
             style="background: url('/images/icons/crosshair.png')"></a>

          <a id="toggle-search-button" title="Search in notes" class="icon-action"
             style="background: url('/images/icons/search.png')"></a>
        </div>

        <input type="file" id="import-upload" style="display: none" />
      </div>

      <div id="search-box" class="hide-toggle" style="grid-area: search; display: none; padding: 10px; margin-top: 10px;">
        <div style="display: flex; align-items: center;">
          <input name="search-text" placeholder="Search text, labels" style="flex-grow: 100; margin-left: 5px; margin-right: 5px;" autocomplete="off">
          <button id="do-search-button" class="btn btn-primary btn-sm" title="Search">Search</button>
        </div>

        <div style="display: flex; align-items: center; justify-content: space-evenly; margin-top: 10px;">
          <button id="reset-search-button" class="btn btn-sm" title="Reset search">Reset search</button>

          <button id="save-search-button" class="btn btn-sm" title="Save search">Save search</button>
        </div>
      </div>

      <div id="tree" class="hide-toggle" style="grid-area: tree; overflow: auto;">
      </div>

      <div id="parent-list" class="hide-toggle">
        <p><strong>Note locations:</strong></p>

        <ul id="parent-list-inner"></ul>
      </div>

      <div class="hide-toggle" style="grid-area: title;">
        <div style="display: flex; align-items: center;">
          <a title="Protect the note so that password will be required to view the note"
             class="icon-action"
             id="protect-button"
             style="display: none; background: url('images/icons/lock.png')"></a>

          <a title="Unprotect note so that password will not be required to access this note in the future"
             class="icon-action"
             id="unprotect-button"
             style="display: none; background: url('images/icons/unlock.png')"></a>

          &nbsp;

          <input autocomplete="off" value="" id="note-title" style="font-size: x-large; border: 0; flex-grow: 100;" tabindex="1">

          <span id="note-id-display" title="Note ID"></span>

          <button class="btn btn-sm"
                  style="display: none; margin-right: 10px"
                  id="execute-script-button">Execute <kbd>Ctrl+Enter</kbd></button>

          <div class="dropdown" id="note-type" data-bind="visible: type() != 'search'">
            <button data-bind="disable: isDisabled()" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-sm">
              Type: <span data-bind="text: typeString()"></span>
              <span class="caret"></span>
            </button>
            <ul id="note-type-dropdown" class="dropdown-menu dropdown-menu-right" aria-labelledby="dLabel">
              <li data-bind="click: selectText, css: { selected: type() == 'text' }"><span class="check">&check;</span> <strong>Text</strong></li>
              <li role="separator" class="divider"></li>
              <li data-bind="click: selectRender, css: { selected: type() == 'render' && mime() == '' }"><span class="check">&check;</span> <strong>Render HTML note</strong></li>
              <li role="separator" class="divider"></li>
              <li data-bind="click: selectCode, css: { selected: type() == 'code' && mime() == '' }"><span class="check">&check;</span> <strong>Code</strong></li>
              <!-- ko foreach: codeMimeTypes -->
              <li data-bind="click: $parent.selectCodeMime, css: { selected: $parent.type() == 'code' && $parent.mime() == mime }"><span class="check">&check;</span> <span data-bind="text: title"></span></li>
              <!-- /ko -->
            </ul>
          </div>

          <div class="dropdown" style="margin-left: 10px; margin-right: 10px;">
            <button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-sm">
              Note actions
              <span class="caret"></span>
            </button>
            <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dLabel">
              <li><a id="show-note-revisions-button">Note revisions</a></li>
              <li><a class="show-labels-button"><kbd>Alt+L</kbd> Labels</a></li>
              <li><a id="show-source-button"><kbd>Ctrl+U</kbd> HTML source</a></li>
              <li><a id="upload-file-button">Upload file</a></li>
            </ul>
          </div>
        </div>
      </div>

      <div style="position: relative; overflow: hidden; grid-area: note-detail; padding-left: 10px; padding-top: 10px; display: flex; flex-direction: column;" id="note-detail-wrapper">
        <div style="flex-grow: 1; position: relative; overflow: auto; flex-basis: content;">
          <div id="note-detail-text" style="height: 100%;" class="note-detail-component"></div>

          <div id="note-detail-search" class="note-detail-component">
            <div style="display: flex; align-items: center;">
              <strong>Search string: &nbsp; &nbsp;</strong>
              <textarea rows="4" cols="50" id="search-string"></textarea>
            </div>

            <br />

            <h4>Help</h4>
            <p>
              <ul>
                <li>
                  <code>@abc</code> - matches notes with label abc</li>
                <li>
                  <code>@!abc</code> - matches notes without abc label (maybe not the best syntax)</li>
                <li>
                  <code>@abc=true</code> - matches notes with label abc having value true</li>
                <li><code>@abc!=true</code></li>
                <li>
                  <code>@"weird label"="weird value"</code> - works also with whitespace inside names values</li>
                <li>
                  <code>@abc and @def</code> - matches notes with both abc and def</li>
                <li>
                  <code>@abc @def</code> - AND relation is implicit when specifying multiple labels</li>
                <li>
                  <code>@abc or @def</code> - OR relation</li>
                <li>
                  <code>@abc&lt;=5</code> - numerical comparison (also &gt;, &gt;=, &lt;).</li>
                <li>
                  <code>some search string @abc @def</code> - combination of fulltext and label search - both of them need to match (OR not supported)</li>
                <li>
                  <code>@abc @def some search string</code> - same combination</li>
              </ul>

              <a href="https://github.com/zadam/trilium/wiki/Labels">Complete help on search syntax</a>
            </p>
          </div>

          <div id="note-detail-code" class="note-detail-component"></div>

          <div id="note-detail-render" class="note-detail-component"></div>

          <div id="note-detail-file" class="note-detail-component">
            <table id="file-table">
              <tr>
                <th>File name:</th>
                <td id="file-filename"></td>
              </tr>
              <tr>
                <th>File type:</th>
                <td id="file-filetype"></td>
              </tr>
              <tr>
                <th>File size:</th>
                <td id="file-filesize"></td>
              </tr>
              <tr>
                <td>
                  <button id="file-download" class="btn btn-primary" type="button">Download</button>
                  &nbsp;
                  <button id="file-open" class="btn btn-primary" type="button">Open</button>
                </td>
              </tr>
            </table>
          </div>

          <input type="file" id="file-upload" style="display: none" />
        </div>

        <div id="children-overview"></div>
      </div>

      <div id="label-list">
        <button class="btn btn-sm show-labels-button">Labels:</button>

        <span id="label-list-inner"></span>
      </div>
    </div>

    <div id="recent-notes-dialog" title="Recent notes" style="display: none;">
      <input id="recent-notes-search-input" class="form-control"/>
    </div>

    <div id="add-link-dialog" title="Add link" style="display: none;">
      <form id="add-link-form">
        <div class="radio">
          <label title="Add HTML link to the selected note at cursor in current note">
            <input type="radio" name="add-link-type" value="html"/>
            add normal HTML link</label>

          <label title="Add selected note as a child of current note">
            <input type="radio" name="add-link-type" value="selected-to-current"/>
            add selected note to current note</label>

          <label title="Add current note as a child of the selected note">
            <input type="radio" name="add-link-type" value="current-to-selected"/>
            add current note to selected note</label>
        </div>

        <div class="form-group">
          <label for="note-autocomplete">Note</label>
          <input id="note-autocomplete" style="width: 100%;">
        </div>

        <div class="form-group" id="add-link-title-form-group">
          <label for="link-title">Link title</label>
          <input id="link-title" style="width: 100%;">
        </div>

        <div class="form-group" id="add-link-prefix-form-group" title="Cloned note will be shown in note tree with given prefix">
          <label for="clone-prefix">Prefix (optional)</label>
          <input id="clone-prefix" style="width: 100%;">
        </div>

        <button class="btn btn-sm">Add link</button>
      </form>
    </div>

    <div id="jump-to-note-dialog" title="Jump to note" style="display: none;">
      <form id="jump-to-note-form">
        <div class="form-group">
          <label for="jump-to-note-autocomplete">Note</label>
          <input id="jump-to-note-autocomplete" style="width: 100%;">
        </div>

        <button name="action" value="jump" class="btn btn-sm">Jump <kbd>enter</kbd></button>
      </form>
    </div>

    <div id="protected-session-password-dialog" title="Protected session" style="display: none;">
      <form id="protected-session-password-form">
        <div class="form-group">
          <label for="protected-session-password">To proceed with requested action you need to start protected session by entering password:</label>
          <input id="protected-session-password" class="form-control" type="password">
        </div>

        <button class="btn btn-sm">Start protected session <kbd>enter</kbd></button>
      </form>
    </div>

    <div id="options-dialog" title="Options" style="display: none;">
      <div id="options-tabs">
        <ul>
          <li><a href="#change-password">Change password</a></li>
          <li><a href="#protected-session-timeout">Protected session</a></li>
          <li><a href="#note-revision-snapshot-time-interval">Note revisions</a></li>
          <li><a href="#advanced">Advanced</a></li>
          <li><a href="#about">About Trilium</a></li>
        </ul>
        <div id="change-password">
          <form id="change-password-form">
            <div class="form-group">
              <label for="old-password">Old password</label>
              <input class="form-control" id="old-password" type="password">
            </div>

            <div class="form-group">
              <label for="new-password1">New password</label>
              <input class="form-control" id="new-password1" type="password">
            </div>

            <div class="form-group">
              <label for="new-password2">New password once more</label>
              <input class="form-control" id="new-password2" type="password">
            </div>

            <button class="btn btn-sm">Change password</button>
          </form>
        </div>
        <div id="protected-session-timeout">
          <p>Protected session timeout is a time period after which the protected session is wiped out from
            browser's memory. This is measured from the last interaction with protected notes.</p>

          <form id="protected-session-timeout-form">
            <div class="form-group">
              <label for="protected-session-timeout-in-seconds">Protected session timeout (in seconds)</label>
              <input class="form-control" id="protected-session-timeout-in-seconds" type="number">
            </div>

            <button class="btn btn-sm">Save</button>
          </form>
        </div>
        <div id="note-revision-snapshot-time-interval">
          <p>Note revision snapshot time interval is time in seconds after which new note revision will be created for the note.</p>

          <form id="note-revision-snapshot-time-interval-form">
            <div class="form-group">
              <label for="note-revision-snapshot-time-interval-in-seconds">Note revision snapshot time interval (in seconds)</label>
              <input class="form-control" id="note-revision-snapshot-time-interval-in-seconds" type="number">
            </div>

            <button class="btn btn-sm">Save</button>
          </form>
        </div>
        <div id="advanced">
          <h4 style="margin-top: 0px;">Sync</h4>
          <button id="force-full-sync-button" class="btn btn-sm">Force full sync</button>

          <br/>
          <br/>

          <button id="fill-sync-rows-button" class="btn btn-sm">Fill sync rows</button>

          <h4>Debugging</h4>

          <button id="anonymize-button" class="btn btn-sm">Save anonymized database</button><br/><br/>

          <p>This action will create a new copy of the database and anonymise it (remove all note content and leave only structure and metadata)
            for sharing online for debugging purposes without fear of leaking your personal data.</p>

          <h4>Image cleanup</h4>

          <p>This will remove all image data of images not used in any current version of note from the database (metadata will remain).

            This means that some images can disappear from note revisions.</p>

          <button id="cleanup-unused-images-button" class="btn btn-warning btn-sm">Permanently cleanup unused images</button>

          <h4>Soft-delete cleanup</h4>

          <p>This deletes all soft deleted rows from the database. This change isn't synced and should be done manually on all instances.
            <strong>Use this only if you really know what you're doing.</strong></p>

          <button id="cleanup-soft-deleted-items-button" class="btn btn-danger btn-sm">Permanently cleanup soft-deleted items</button>

          <h4>Vacuum database</h4>

          <p>This will rebuild database which will typically result in smaller database file. No data will be actually changed.</p>

          <button id="vacuum-database-button" class="btn btn-sm">Vacuum database</button>
        </div>
        <div id="about">
          <table class="table">
            <tr>
              <th>App version:</th>
              <td id="app-version"></td>
            </tr>

            <tr>
              <th>DB version:</th>
              <td id="db-version"></td>
            </tr>

            <tr>
              <th>Build date:</th>
              <td id="build-date"></td>
            </tr>

            <tr>
              <th>Build revision:</th>
              <td><a href="" target="_blank" id="build-revision"></a></td>
            </tr>
          </table>
        </div>
      </div>
    </div>

    <div id="note-revisions-dialog" title="Note revisions" style="display: none;">
      <div style="display: flex;">
        <select id="note-revision-list" size="25" style="width: 150px; height: 630px;">
        </select>

        <div id="note-revision-content-wrapper" style="flex-grow: 1; margin-left: 20px;">
          <h3 id="note-revision-title" style="margin: 3px;"></h3>

          <div id="note-revision-content" style="height: 600px; width: 600px; overflow: auto;"></div>
        </div>
      </div>
    </div>

    <div id="recent-changes-dialog" title="Recent changes" style="display: none; padding: 20px;">
    </div>

    <div id="event-log-dialog" title="Event log" style="display: none; padding: 20px;">
      <ul id="event-log-list"></ul>
    </div>

    <div id="edit-tree-prefix-dialog" title="Edit tree prefix" style="display: none; padding: 20px;">
      <form id="edit-tree-prefix-form">
        <div class="form-group">
          <label for="tree-prefix-input">Prefix</label>
          <input id="tree-prefix-input" style="width: 20em;"> - <span id="tree-prefix-note-title"></span>
        </div>

        <button name="action" class="btn btn-sm">Save</button>
      </form>
    </div>

    <div id="sql-console-dialog" title="SQL console" style="display: none; padding: 20px;">
      <div style="height: 150px; width: 100%; border: 1px solid #ccc; margin-bottom: 10px;" id="sql-console-query"></div>

      <div style="text-align: center">
        <button class="btn btn-danger" id="sql-console-execute">Execute <kbd>CTRL+ENTER</kbd></button>
      </div>

      <table id="sql-console-results" class="table table-striped" style="overflow: scroll; width: 100%;">
        <thead></thead>
        <tbody></tbody>
      </table>
    </div>

    <div id="note-source-dialog" title="Note source" style="display: none; padding: 20px;">
      <textarea id="note-source" readonly="readonly"></textarea>
    </div>

    <div id="labels-dialog" title="Note labels" style="display: none; padding: 20px;">
      <form data-bind="submit: save">
      <div style="text-align: center">
        <button class="btn btn-large" style="width: 200px;" id="save-labels-button" type="submit">Save changes <kbd>enter</kbd></button>
      </div>

      <div style="height: 97%; overflow: auto">
        <table id="labels-table" class="table">
          <thead>
            <tr>
              <th></th>
              <th>ID</th>
              <th>Name</th>
              <th>Value</th>
              <th></th>
            </tr>
          </thead>
          <tbody data-bind="foreach: labels">
            <tr data-bind="if: isDeleted == 0">
              <td class="handle">
                <span class="glyphicon glyphicon-resize-vertical"></span>
                <input type="hidden" name="position" data-bind="value: position"/>
              </td>
              <!-- ID column has specific width because if it's empty its size can be deformed when dragging -->
              <td data-bind="text: labelId" style="width: 150px;"></td>
              <td>
                <!-- Change to valueUpdate: blur is necessary because jQuery UI autocomplete hijacks change event -->
                <input type="text" class="label-name" data-bind="value: name, valueUpdate: 'blur',  event: { blur: $parent.labelChanged }"/>
                <div style="color: yellowgreen" data-bind="if: $parent.isNotUnique($index())"><span class="glyphicon glyphicon-info-sign"></span> Duplicate label.</div>
                <div style="color: red" data-bind="if: $parent.isEmptyName($index())">Label name can't be empty.</div>
              </td>
              <td>
                <input type="text" class="label-value" data-bind="value: value, valueUpdate: 'blur', event: { blur: $parent.labelChanged }" style="width: 300px"/>
              </td>
              <td title="Delete" style="padding: 13px;">
                <span class="glyphicon glyphicon-trash" data-bind="click: $parent.deleteLabel"></span>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      </form>
    </div>

    <div id="tooltip" style="display: none;"></div>

    <script type="text/javascript">
      window.baseApiUrl = 'api/';
      window.glob = {
          activeDialog: null,
          sourceId: '<%= sourceId %>',
          maxSyncIdAtLoad: <%= maxSyncIdAtLoad %>,
          instanceName: '<%= instanceName %>'
      };
    </script>

    <!-- Required for correct loading of scripts in Electron -->
    <script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>

    <script src="/libraries/jquery.min.js"></script>

    <!-- bootstrap needs to be included before jQuery UI, otherwise close icon in the dialog will be missing -->
    <link href="/libraries/bootstrap/css/bootstrap.css" rel="stylesheet">
    <script src="/libraries/bootstrap/js/bootstrap.js"></script>

    <link href="/libraries/jqueryui/jquery-ui.min.css" rel="stylesheet">
    <script src="/libraries/jqueryui/jquery-ui.min.js"></script>

    <script src="/libraries/bootstrap-notify.min.js"></script>

    <!-- Include Fancytree skin and library -->
    <link href="/libraries/fancytree/skin-win8/ui.fancytree.css" rel="stylesheet">
    <script src="/libraries/fancytree/jquery.fancytree-all.min.js"></script>

    <script src="/libraries/jquery.hotkeys.js"></script>
    <script src="/libraries/jquery.fancytree.hotkeys.js"></script>

    <script src="/libraries/jquery.ui-contextmenu.min.js"></script>

    <script src="/libraries/knockout.min.js"></script>

    <link href="/stylesheets/style.css" rel="stylesheet">

    <script src="/javascripts/services/bootstrap.js" type="module"></script>

    <script type="text/javascript">
      // we hide container initally because otherwise it is rendered first without CSS and then flickers into
      // final form which is pretty ugly.
      $("#container").show();
    </script>

    <style type="text/css">
      <%= appCss %>
    </style>
  </body>
</html>