<div class="btn-group">
  <button type="button" class="btn btn-sm btn-outline-primary" (click)="clickSuggest()" [disabled]="disabled() || loading() || (suggestions() && !aiEnabled())" [aria-label]="noSuggestions ? 'No suggestions' : 'Suggest'" i18n-aria-label>
    @if (loading()) {
      <div class="spinner-border spinner-border-sm" role="status"></div>
    } @else if (noSuggestions) {
      <i-bs width="1.2em" height="1.2em" name="check-circle"></i-bs>
    } @else {
      <i-bs width="1.2em" height="1.2em" name="stars"></i-bs>
    }
    @if (noSuggestions) {
      <span class="d-none d-lg-inline ps-1" i18n>No suggestions</span>
    } @else {
      <span class="d-none d-lg-inline ps-1" i18n>Suggest</span>
    }
    @if (totalSuggestions > 0) {
      <span class="badge bg-primary ms-2">{{ totalSuggestions }}</span>
    }
  </button>

  @if (aiEnabled()) {
    <div class="btn-group" ngbDropdown #dropdown="ngbDropdown" [popperOptions]="popperOptions">
      <button type="button" class="btn btn-sm btn-outline-primary" ngbDropdownToggle [disabled]="disabled() || loading() || !suggestions()" aria-expanded="false" aria-controls="suggestionsDropdown" aria-label="Suggestions dropdown">
        <span class="visually-hidden" i18n>Show suggestions</span>
      </button>

      <div ngbDropdownMenu aria-labelledby="suggestionsDropdown" class="shadow suggestions-dropdown">
        <div class="list-group list-group-flush small pb-0">
          @if (novelSuggestions === 0 && reusableSuggestions === 0) {
            <div class="list-group-item text-muted fst-italic">
              <small class="text-muted small fst-italic" i18n>No novel suggestions</small>
            </div>
          }
          @if (suggestions()?.suggested_tags?.length > 0) {
            <small class="list-group-item text-uppercase text-muted small"><i-bs class="me-2" name="tags"></i-bs><ng-container i18n>Tags</ng-container></small>
            @for (tag of suggestions().suggested_tags; track tag) {
              <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addTag.emit(tag)">{{ tag }}</button>
            }
          }
          @if (suggestions()?.suggested_document_types?.length > 0) {
            <div class="list-group-item text-uppercase text-muted small"><i-bs class="me-2" name="hash"></i-bs><ng-container i18n>Document Types</ng-container></div>
            @for (type of suggestions().suggested_document_types; track type) {
              <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addDocumentType.emit(type)">{{ type }}</button>
            }
          }
          @if (suggestions()?.suggested_correspondents?.length > 0) {
            <div class="list-group-item text-uppercase text-muted small"><i-bs class="me-2" name="person"></i-bs><ng-container i18n>Correspondents</ng-container></div>
            @for (correspondent of suggestions().suggested_correspondents; track correspondent) {
              <button type="button" class="list-group-item list-group-item-action bg-light" (click)="addCorrespondent.emit(correspondent)">{{ correspondent }}</button>
            }
          }
          @if (reusableSuggestions > 0) {
            <div class="list-group-item text-muted fst-italic">
              <small class="text-muted small fst-italic" i18n>{reusableSuggestions, plural, =1 {1 existing value suggested below} other {{{reusableSuggestions}} existing values suggested below}}</small>
            </div>
          }
        </div>
      </div>
    </div>
  }
</div>
