<!--
  ~ 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>Create New {{ portTypeLabel }}</h2>
<form class="create-port-form" [formGroup]="createPortForm">
    <context-error-banner [context]="ErrorContextKey.PORT"></context-error-banner>
    <mat-dialog-content>
        <mat-form-field>
            <mat-label>{{ portTypeLabel }} Name</mat-label>
            <input matInput formControlName="newPortName" type="text" />
        </mat-form-field>
        @if (!isRootProcessGroup) {
            <mat-form-field>
                <mat-label>
                    {{ ComponentType.InputPort == request.type ? 'Receive From' : 'Send To' }}
                    <i
                        class="fa fa-info-circle"
                        nifiTooltip
                        [tooltipComponentType]="TextTip"
                        [tooltipInputData]="
                            ComponentType.InputPort == request.type
                                ? 'Specify where FlowFiles are received from.'
                                : 'Specify where FlowFiles are sent.'
                        "></i>
                </mat-label>
                <mat-select formControlName="newPortAllowRemoteAccess">
                    @for (option of allowRemoteAccessOptions; track option) {
                        @if (option.description) {
                            <mat-option
                                [value]="option.value"
                                nifiTooltip
                                [tooltipComponentType]="TextTip"
                                [tooltipInputData]="option.description"
                                [delayClose]="false"
                                >{{ option.text }}</mat-option
                            >
                        } @else {
                            <mat-option [value]="option.value">{{ option.text }}</mat-option>
                        }
                    }
                </mat-select>
            </mat-form-field>
        }
    </mat-dialog-content>
    @if ({ value: (saving$ | async)! }; as saving) {
        <mat-dialog-actions align="end">
            <button mat-button mat-dialog-close>Cancel</button>
            <button
                [disabled]="!createPortForm.dirty || createPortForm.invalid || saving.value || createPortForm.pending"
                type="submit"
                (click)="createPort()"
                mat-flat-button>
                <span *nifiSpinner="saving.value">Add</span>
            </button>
        </mat-dialog-actions>
    }
</form>
