<!--
 Copyright 2023 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="repl-console-wrapper" >
  <h1>REPL Console</h1>

    <p>Add statements to evaluate.</p>
    <p>Do not include sensitive data.</p>
    <span class="reset-wrapper">
      <button mat-fab (click)="reset()" color="primary" aria-label="Reset REPL statements"><mat-icon>refresh</mat-icon></button>
    </span>

    <div class="repl-input-block" (keydown)="onEnter($event)">
        <!-- Inputs for previously entered REPL commands -->
        <div class="statement-block" *ngFor="let command of lastRequest.commands; let i = index">
            <mat-form-field class="statement-container" appearance="outline">
                <mat-label>{{i + 1}}</mat-label>

                <input matInput class="repl-stmt-input"
                  value="{{command}}"
                  [attr.data-stmt-index]="i"
                  (keydown.ArrowUp)="handleUp(i)"
                  (keydown.ArrowDown)="handleDown(i)">

                <mat-hint>
                    <code *ngIf="getResponse(i).evaluated" class="repl-out-ok">{{getResponse(i).replOutput || (getResponse(i).issue ? '&lt;err&gt;' : '&lt;ok&gt;' ) | trim:80}}</code>
                </mat-hint>

            </mat-form-field>
        </div>

        <!-- Input for next command -->
        <div class="statement-block">
          <mat-form-field class="statement-container" appearance="outline">
            <mat-label>&gt; </mat-label>
            <input matInput class="repl-stmt-input repl-stmt-new"
            (keydown.ArrowUp)="handleUp(numStatements())"
            (keydown.ArrowDown)="handleDown(numStatements())"
            [attr.data-stmt-index]="lastRequest.commands.length" value="">
          </mat-form-field>
        </div>
    </div>

    <app-repl-result-detail
    [lastResponse]="(numStatements())? lastEvaluate.responses[numStatements() - 1] : undefined"
    [evalTime]="(!!lastEvaluate.evalTime)? lastEvaluate.evalTime : undefined"
    ></app-repl-result-detail>

</div>