<html>
  {{> partials/head title="Browse" }}
  <body>

    {{> partials/prefix isBrowse=true}}

    <!-- Table Selector -->
    <form action="browse" method="post">
      <select name="table">
        {{#each tableNames}}
          <option value="{{this}}">{{this}}</option>
        {{/each}}
      </select>
      <input type="hidden" name="db" value="{{database}}" />
      <input type="submit" value="browse" />
    </form>

    <!-- Data -->
    {{#if table}}
      <h1>{{table}}</h1>
    {{else}}
      <h1>Data</h1>
    {{/if}}

    {{#if queryResult}}
      <p>Viewing rows {{pagingData.startRow}}-{{pagingData.endRow}} of {{pagingData.rowCount}}.</p>

      <!-- Paging Controls -->
      <form action="browse" method="post">
        <input type="hidden" name="table" value="{{table}}" />
        <input type="hidden" name="pageSize" value="{{pagingData.pageSize}}" />
        <input type="hidden" name="pageIndex" value="{{pagingData.pageIndex}}" />

        <input type="submit" name="action" value="first" {{#if pagingData.firstPage}}disabled{{/if}} />
        <input type="submit" name="action" value="previous" {{#if pagingData.firstPage}}disabled{{/if}} />
        <input type="submit" name="action" value="next" {{#if pagingData.lastPage}}disabled{{/if}} />
        <input type="submit" name="action" value="last" {{#if pagingData.lastPage}}disabled{{/if}} />
      </form>

      <!-- Data Rows -->
      <table>
        <tr>
          {{#each queryResult.columns}}
            <th>{{this}}</th>
          {{/each}}
        </tr>
        {{#each queryResult.rows}}
          <tr>
            {{#each this}}
              <td><pre>{{{this}}}</pre></td>
            {{/each}}
          </tr>
        {{/each}}
      </table>
    {{else}}
      <div>Select a table from above and click 'browse'.</div>
    {{/if}}

    <br />

    <!-- Paging Controls -->
    <form action="browse" method="post">
      <input type="hidden" name="table" value="{{table}}" />
      <input type="hidden" name="pageSize" value="{{pagingData.pageSize}}" />
      <input type="hidden" name="pageIndex" value="{{pagingData.pageIndex}}" />

      <input type="submit" name="action" value="first" {{#if pagingData.firstPage}}disabled{{/if}} />
      <input type="submit" name="action" value="previous" {{#if pagingData.firstPage}}disabled{{/if}} />
      <input type="submit" name="action" value="next" {{#if pagingData.lastPage}}disabled{{/if}} />
      <input type="submit" name="action" value="last" {{#if pagingData.lastPage}}disabled{{/if}} />
    </form>

    {{> partials/suffix}}
  </body>
</html>
