<!--
Copyright 2025 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<div class="wrapper">
  @if (llmIndex === undefined) {
    <h2>Choose an LLM</h2>
    @for (name of llmNames; track name; let index = $index) {
      <button (click)="llmIndex = index" mat-raised-button>{{ name }}</button>
    }
  } @else {
    <h2>Chat with {{ llmNames[llmIndex] }}</h2>

    @for (entry of history; track entry; let i = $index) {
      <div>
        @if (entry.role === 'user') {
          <div class="user-bubble">
            {{ entry.text }}
          </div>
        }
        @if (entry.role === 'model') {
          <div class="model-bubble">
            @if (entry.text) {
              <span class="text">
                <markdown
                  class="variable-binding"
                  [data]="entry.text"></markdown>
              </span>
            }
          </div>
        }
      </div>
    }

    @if (error) {
      <pre class="error">{{ error }}</pre>
    }

    <form>
      <mat-form-field class="input-field">
        <mat-label
          >Chat input. Press Enter to submit (Shift+Enter for line
          break)</mat-label
        >
        <textarea
          matInput
          (keypress)="keyPress($event)"
          [formControl]="chatFormControl"
          placeholder="Hi..."></textarea>
        @if (loading) {
          <mat-progress-bar mode="indeterminate"></mat-progress-bar>
        }
      </mat-form-field>
    </form>
  }
</div>
