<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You 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.
  -->

<h2 mat-dialog-title>{{ readonly ? portTypeLabel + ' Details' : 'Edit ' + portTypeLabel }}</h2>
<form class="edit-port-form" [formGroup]="editPortForm">
    <error-banner></error-banner>
    <mat-dialog-content>
        <div>
            <mat-form-field>
                <mat-label>{{ portTypeLabel }} Name</mat-label>
                <input matInput formControlName="name" type="text" [readonly]="readonly" />
            </mat-form-field>
        </div>
        <div>
            @if (request.entity.component.allowRemoteAccess) {
                <mat-form-field>
                    <mat-label>
                        Concurrent Tasks
                        <i
                            class="fa fa-info-circle"
                            nifiTooltip
                            [tooltipComponentType]="TextTip"
                            tooltipInputData="The number of tasks that should be concurrently scheduled for this port."></i>
                    </mat-label>
                    <input matInput formControlName="concurrentTasks" type="text" [readonly]="readonly" />
                </mat-form-field>
            }
        </div>
        @if (portTypeLabel == 'Output Port') {
            <div class="mb-3.5">
                <mat-label>
                    Failure Port
                    <i
                        class="fa fa-info-circle"
                        nifiTooltip
                        [tooltipComponentType]="TextTip"
                        tooltipInputData="When using the Stateless Engine, if any FlowFile is routed to a port marked as a Failure Port, all data in the transaction is rolled back, and the input FlowFile, if any, is routed to the Failure Port."></i>
                </mat-label>
                <mat-checkbox color="primary" formControlName="portFunction"></mat-checkbox>
            </div>
        }
        <div>
            <mat-form-field>
                <mat-label>Comments</mat-label>
                <textarea matInput formControlName="comments" type="text" [readonly]="readonly"></textarea>
            </mat-form-field>
        </div>
    </mat-dialog-content>
    @if ({ value: (saving$ | async)! }; as saving) {
        <mat-dialog-actions align="end">
            @if (readonly) {
                <button mat-button mat-dialog-close color="primary">Close</button>
            } @else {
                <button mat-button mat-dialog-close>Cancel</button>
                <button
                    [disabled]="!editPortForm.dirty || editPortForm.invalid || saving.value"
                    type="button"
                    color="primary"
                    (click)="editPort()"
                    mat-button>
                    <span *nifiSpinner="saving.value">Apply</span>
                </button>
            }
        </mat-dialog-actions>
    }
</form>
