<discover-app class="app-container">
  <!-- Local nav. -->
  <kbn-top-nav name="discover" config="topNavMenu">
    <!-- Transcluded elements. -->
    <div data-transclude-slots>
      <!-- Breadcrumbs. -->
      <div data-transclude-slot="topLeftCorner" class="kuiLocalBreadcrumbs">
        <h1 tabindex="0" id="kui_local_breadcrumb" class="kuiLocalBreadcrumb">
          <span ng-show="opts.savedSearch.id" class="kuiLocalBreadcrumb__emphasis">
            <span data-test-subj="discoverCurrentQuery" ng-bind="opts.savedSearch.lastSavedTitle"></span>
            <span
              id="reload_saved_search"
              aria-label="Reload Saved Search"
              tooltip="Reload Saved Search"
              ng-click="resetQuery()"
              kbn-accessible-click
              class="kuiIcon fa-undo small"
            ></span>&nbsp;
          </span>
          <span data-test-subj="discoverQueryHits" class="kuiLocalBreadcrumb__emphasis">{{(hits || 0) | number:0}}</span>
          <ng-pluralize count="hits" when="{'1':'hit', 'other':'hits'}"></ng-pluralize>
        </h1>
      </div>

      <!-- Search. -->
      <div data-transclude-slot="bottomRow" class="fullWidth">
        <query-bar
          query="state.query"
          on-submit="updateQueryAndFetch"
          app-name="'discover'"
          index-patterns="[indexPattern]"
        ></query-bar>
      </div>
    </div>
  </kbn-top-nav>

  <main class="container-fluid">
    <div class="row">
      <filter-bar
        state="state"
        index-patterns="[indexPattern]"
      ></filter-bar>
    </div>
    <div class="row">
      <div class="col-md-2 sidebar-container collapsible-sidebar" id="discover-sidebar">
        <disc-field-chooser
          class="dscFieldChooser"
          columns="state.columns"
          hits="rows"
          field-counts="fieldCounts"
          index-pattern="searchSource.getField('index')"
          index-pattern-list="opts.indexPatternList"
          state="state"
          on-add-field="addColumn"
          on-add-filter="filterQuery"
          on-remove-field="removeColumn"
        >
        </disc-field-chooser>
      </div>

      <div class="dscWrapper col-md-10">
        <div class="dscWrapper__content">
          <discover-unsupported-index-pattern
            ng-if="isUnsupportedIndexPattern"
            unsupported-type="unsupportedIndexPatternType"
          ></discover-unsupported-index-pattern>

          <discover-no-results
            ng-show="resultState === 'none'"
            top-nav-toggle="kbnTopNav.toggle"
            is-time-picker-open="kbnTopNav.isCurrent('filter')"
            shard-failures="failures"
            time-field-name="opts.timefield"
            query-language="state.query.language"
            get-doc-link="getDocLink"
          ></discover-no-results>

          <!-- loading -->
          <div ng-show="resultState === 'loading'">
            <discover-fetch-error
              ng-show="fetchError"
              fetch-error="fetchError"
            ></discover-fetch-error>

            <div
              ng-hide="fetchError"
              class="dscOverlay"
            >
              <div class="euiTitle" >
                <h2>Searching</h2>
              </div>
              <div class="euiSpacer euiSpacer--m"></div>
              <div ng-show="fetchStatus">{{fetchStatus.complete}}/{{fetchStatus.total}}</div>
            </div>
          </div>

          <!-- result -->
          <div class="dscResults" ng-show="resultState === 'ready'">
            <button
              class="kuiButton kuiButton--basic kuiButton--iconText dscSkipButton"
              ng-click="showAllRows(); scrollToBottom()"
            >
              <span class="kuiButton__inner">
                <span aria-hidden="true" class="kuiButton__icon kuiIcon fa-chevron-down"></span>
                <span>Skip to bottom</span>
              </span>
            </button>

            <section aria-label="Histogram of found documents" class="dscTimechart" ng-if="opts.timefield">
              <header class="dscTimechart__header">
                <div class="small">
                  <span tooltip="To change the time, click the clock icon in the navigation bar">{{timeRange.from | moment}} - {{timeRange.to | moment}}</span>

                  &mdash;

                  <span class="form-inline">
                    <select
                      class="dscResults__interval form-control"
                      ng-model="state.interval"
                      ng-options="interval.val as interval.display for interval in intervalOptions | filter: intervalEnabled"
                      ng-blur="toggleInterval()"
                      data-test-subj="discoverIntervalSelect"
                      >
                    </select>
                    <span ng-if="bucketInterval.scaled">
                      <icon-tip
                        content="getBucketIntervalToolTipText()"
                        position="'top'"
                      ></icon-tip>
                      Scaled to {{ bucketInterval.description }}
                    </span>
                  </span>
                </div>

              </header>

              <div id="discoverHistogram"
                 ng-if="vis && rows.length !== 0"
                 style="display: flex; height: 200px"
                >
              </div>
            </section>

            <section class="dscTable" fixed-scroll aria-label="Documents">
              <doc-table
                hits="rows"
                index-pattern="indexPattern"
                sorting="state.sort"
                columns="state.columns"
                infinite-scroll="true"
                filter="filterQuery"
                filters="state.filters"
                data-shared-item
                data-title="{{opts.savedSearch.lastSavedTitle}}"
                data-description="{{opts.savedSearch.description}}"
                minimum-visible-rows="minimumVisibleRows"
                render-complete
                on-add-column="addColumn"
                on-change-sort-order="setSortOrder"
                on-move-column="moveColumn"
                on-remove-column="removeColumn"
              ></doc-table>

              <a tabindex="0" id="discoverBottomMarker"></a>

              <div ng-if="rows.length == opts.sampleSize" class="dscTable__footer">
                These are the first {{opts.sampleSize}} documents matching
                your search, refine your search to see others.
                <a kbn-accessible-click ng-click="scrollToTop()">Back to top.</a>
              </div>
            </section>
          </div>
        </div>
      </div>
    </div>
  </main>
</discover-app>
