<!--

    Copyright © 2016-2026 The Thingsboard Authors

    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="flex flex-col">
  @for (deviceProfileCommunication of communicationConfigFormArray.controls; track $index) {
    <div class="scope-row flex flex-row items-center justify-start gap-2" [formGroup]="deviceProfileCommunication">
      <div class="communication-config">
        <mat-form-field class="spec mat-block" appearance="outline" floatLabel="always" hideRequiredMarker>
          <mat-label translate>device-profile.snmp.scope</mat-label>
          <mat-select formControlName="spec" required>
            @for (snmpSpecType of snmpSpecTypes; track snmpSpecType) {
              <mat-option [value]="snmpSpecType"
                          [disabled]="isDisabledSeverity(snmpSpecType, $index)">
                {{ snmpSpecTypeTranslationMap.get(snmpSpecType) }}
              </mat-option>
            }
          </mat-select>
          @if (deviceProfileCommunication.get('spec').hasError('required')) {
            <mat-error>{{ 'device-profile.snmp.scope-required' | translate }}</mat-error>
          }
        </mat-form-field>
        <mat-divider vertical></mat-divider>
        <section class="flex flex-1 flex-col">
          @if (isShowFrequency(deviceProfileCommunication.get('spec').value)) {
            <mat-form-field appearance="outline">
              <mat-label translate>device-profile.snmp.querying-frequency</mat-label>
              <input matInput formControlName="queryingFrequencyMs" type="number" min="0" required/>
              @if (deviceProfileCommunication.get('queryingFrequencyMs').hasError('required')) {
                <mat-error>{{ 'device-profile.snmp.querying-frequency-required' | translate }}</mat-error>
              }
              @if (deviceProfileCommunication.get('queryingFrequencyMs').hasError('pattern') ||
              deviceProfileCommunication.get('queryingFrequencyMs').hasError('min')) {
                <mat-error>{{ 'device-profile.snmp.querying-frequency-invalid-format' | translate }}</mat-error>
              }
            </mat-form-field>
          }
          <tb-snmp-device-profile-mapping formControlName="mappings">
          </tb-snmp-device-profile-mapping>
        </section>
      </div>
      @if (!disabled) {
        <button mat-icon-button color="primary" style="min-width: 40px;"
                type="button"
                (click)="removeCommunicationConfig($index)"
                matTooltip="{{ 'action.remove' | translate }}"
                matTooltipPosition="above">
          <mat-icon>remove_circle_outline</mat-icon>
        </button>
      }
    </div>
  }
  @if (!communicationConfigFormArray.controls.length && !disabled) {
    <div>
      <span class="tb-prompt required required-text flex items-center justify-center" translate>device-profile.snmp.please-add-communication-config</span>
    </div>
  }
  @if (!disabled && isAddEnabled) {
    <div>
      <button mat-stroked-button color="primary"
              type="button"
              (click)="addCommunicationConfig()">
        <mat-icon class="button-icon">add_circle_outline</mat-icon>
        {{ 'device-profile.snmp.add-communication-config' | translate }}
      </button>
    </div>
  }
</div>
