<!--
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">
  <h3>Chat with Agent Smith</h3>

  @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">{{ entry.text }}</span>
          }
          @if (entry.toolRequest) {
            <div>
              <div>
                @switch (entry.toolRequest.name) {
                  @case ('weatherTool') {
                    <div class="weather-tool">
                      <h4>
                        <mat-icon class="weather-icon">sunny_snowing</mat-icon>
                        {{ getWeatherLocation(entry.toolRequest) }} 27°C
                      </h4>
                      <div>Warn sunny day with a mix of sun and snow.</div>
                    </div>
                  }
                  @case ('datePicker') {
                    <div>
                      <mat-form-field class="example-form-field">
                        <mat-label>Choose a date</mat-label>
                        <input
                          matInput
                          [matDatepicker]="datepicker"
                          (dateChange)="
                            datePicked(entry.toolRequest, $event)
                          " />
                        <mat-hint>MM/DD/YYYY</mat-hint>
                        <mat-datepicker-toggle
                          matIconSuffix
                          [for]="datepicker"></mat-datepicker-toggle>
                        <mat-datepicker #datepicker>
                          <mat-datepicker-actions>
                            <button mat-button matDatepickerCancel>
                              Cancel
                            </button>
                            <button
                              mat-raised-button
                              color="primary"
                              matDatepickerApply>
                              Apply
                            </button>
                          </mat-datepicker-actions>
                        </mat-datepicker>
                      </mat-form-field>
                    </div>
                  }
                  @default {
                    <div>Oops... unknown tool {{ entry.toolRequest.name }}</div>
                  }
                }
              </div>
            </div>
          }
        </div>
      }
    </div>
  }

  <form>
    <mat-form-field class="input-field">
      <mat-label>Chat input</mat-label>
      <textarea
        matInput
        [formControl]="chatFormControl"
        placeholder="Hi..."></textarea>
      @if (loading) {
        <mat-progress-bar mode="indeterminate"></mat-progress-bar>
      }
    </mat-form-field>
    <button mat-button (click)="ask(input)" [disabled]="loading">
      <mat-icon>send</mat-icon>
    </button>
  </form>
</div>
