<!--

    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.

-->
<form [formGroup]="snmpDeviceTransportConfigurationFormGroup" class="flex flex-col gap-2 pb-4">
  <div class="flex flex-row gap-2 xs:flex-col">
    <mat-form-field class="flex-1" appearance="outline">
      <mat-label translate>device-profile.snmp.host</mat-label>
      <input matInput formControlName="host" required>
      @if (snmpDeviceTransportConfigurationFormGroup.get('host').hasError('required') ||
        snmpDeviceTransportConfigurationFormGroup.get('host').hasError('pattern')) {
        <mat-error>
          {{ 'device-profile.snmp.host-required' | translate }}
        </mat-error>
      }
    </mat-form-field>
    <mat-form-field class="flex-1" appearance="outline">
      <mat-label translate>device-profile.snmp.port</mat-label>
      <input matInput formControlName="port" type="number" min="0" required>
      @if (snmpDeviceTransportConfigurationFormGroup.get('port').hasError('required')) {
        <mat-error>
          {{ 'device-profile.snmp.port-required' | translate }}
        </mat-error>
      }
      @if (snmpDeviceTransportConfigurationFormGroup.get('port').hasError('pattern') ||
        snmpDeviceTransportConfigurationFormGroup.get('port').hasError('min')) {
        <mat-error>
          {{ 'device-profile.snmp.port-format' | translate }}
        </mat-error>
      }
    </mat-form-field>
  </div>
  <mat-form-field class="mat-block" floatLabel="always" hideRequiredMarker appearance="outline">
    <mat-label translate>device-profile.snmp.protocol-version</mat-label>
    <mat-select formControlName="protocolVersion" required>
      @for (snmpDeviceProtocolVersion of snmpDeviceProtocolVersions; track snmpDeviceProtocolVersion) {
        <mat-option [value]="snmpDeviceProtocolVersion">
          {{ snmpDeviceProtocolVersion | lowercase }}
        </mat-option>
      }
    </mat-select>
    @if (snmpDeviceTransportConfigurationFormGroup.get('protocolVersion').hasError('required')) {
      <mat-error>
        {{ 'device-profile.snmp.protocol-version-required' | translate }}
      </mat-error>
    }
  </mat-form-field>
  @if (!isV3protocolVersion()) {
    <section>
      <mat-form-field class="mat-block" appearance="outline">
        <mat-label translate>device-profile.snmp.community</mat-label>
        <input matInput formControlName="community" required>
        @if (snmpDeviceTransportConfigurationFormGroup.get('community').hasError('required') ||
          snmpDeviceTransportConfigurationFormGroup.get('community').hasError('pattern')) {
          <mat-error>
            {{ 'device-profile.snmp.community-required' | translate }}
          </mat-error>
        }
      </mat-form-field>
    </section>
  }
  @if (isV3protocolVersion()) {
    <section>
      <div class="flex flex-row gap-2 xs:flex-col">
        <mat-form-field class="flex-1" appearance="outline">
          <mat-label translate>device-profile.snmp.user-name</mat-label>
          <input matInput formControlName="username" required>
          @if (snmpDeviceTransportConfigurationFormGroup.get('username').hasError('required') ||
            snmpDeviceTransportConfigurationFormGroup.get('username').hasError('pattern')) {
            <mat-error>
              {{ 'device-profile.snmp.user-name-required' | translate }}
            </mat-error>
          }
        </mat-form-field>
        <mat-form-field class="flex-1" appearance="outline">
          <mat-label translate>device-profile.snmp.security-name</mat-label>
          <input matInput formControlName="securityName" required>
          @if (snmpDeviceTransportConfigurationFormGroup.get('securityName').hasError('required') ||
            snmpDeviceTransportConfigurationFormGroup.get('securityName').hasError('pattern')) {
            <mat-error>
              {{ 'device-profile.snmp.security-name-required' | translate }}
            </mat-error>
          }
        </mat-form-field>
      </div>
      <div class="flex flex-row gap-2 xs:flex-col">
        <mat-form-field class="flex-1" floatLabel="always" hideRequiredMarker appearance="outline">
          <mat-label translate>device-profile.snmp.authentication-protocol</mat-label>
          <mat-select formControlName="authenticationProtocol" required>
            @for (snmpAuthenticationProtocol of snmpAuthenticationProtocols; track snmpAuthenticationProtocol) {
              <mat-option [value]="snmpAuthenticationProtocol">
                {{ snmpAuthenticationProtocolTranslation.get(snmpAuthenticationProtocol) }}
              </mat-option>
            }
          </mat-select>
          @if (snmpDeviceTransportConfigurationFormGroup.get('authenticationProtocol').hasError('required')) {
            <mat-error>
              {{ 'device-profile.snmp.authentication-protocol-required' | translate }}
            </mat-error>
          }
        </mat-form-field>
        <mat-form-field class="flex-1" appearance="outline">
          <mat-label translate>device-profile.snmp.authentication-passphrase</mat-label>
          <input matInput formControlName="authenticationPassphrase" required>
          @if (snmpDeviceTransportConfigurationFormGroup.get('authenticationPassphrase').hasError('required') ||
            snmpDeviceTransportConfigurationFormGroup.get('authenticationPassphrase').hasError('pattern')) {
            <mat-error>
              {{ 'device-profile.snmp.authentication-passphrase-required' | translate }}
            </mat-error>
          }
        </mat-form-field>
      </div>
      <div class="flex flex-row gap-2 xs:flex-col">
        <mat-form-field class="flex-1" floatLabel="always" hideRequiredMarker appearance="outline">
          <mat-label translate>device-profile.snmp.privacy-protocol</mat-label>
          <mat-select formControlName="privacyProtocol" required>
            @for (snmpPrivacyProtocol of snmpPrivacyProtocols; track snmpPrivacyProtocol) {
              <mat-option [value]="snmpPrivacyProtocol">
                {{ snmpPrivacyProtocolTranslation.get(snmpPrivacyProtocol) }}
              </mat-option>
            }
          </mat-select>
          @if (snmpDeviceTransportConfigurationFormGroup.get('privacyProtocol').hasError('required')) {
            <mat-error>
              {{ 'device-profile.snmp.privacy-protocol-required' | translate }}
            </mat-error>
          }
        </mat-form-field>
        <mat-form-field class="flex-1" appearance="outline">
          <mat-label translate>device-profile.snmp.privacy-passphrase</mat-label>
          <input matInput formControlName="privacyPassphrase" required>
          @if (snmpDeviceTransportConfigurationFormGroup.get('privacyPassphrase').hasError('required') ||
            snmpDeviceTransportConfigurationFormGroup.get('privacyPassphrase').hasError('pattern')) {
            <mat-error>
              {{ 'device-profile.snmp.privacy-passphrase-required' | translate }}
            </mat-error>
          }
        </mat-form-field>
      </div>
      <div class="flex flex-row gap-2 xs:flex-col">
        <mat-form-field class="flex-1" appearance="outline">
          <mat-label translate>device-profile.snmp.context-name</mat-label>
          <input matInput formControlName="contextName">
        </mat-form-field>
        <mat-form-field class="flex-1" appearance="outline">
          <mat-label translate>device-profile.snmp.engine-id</mat-label>
          <input matInput formControlName="engineId">
        </mat-form-field>
      </div>
    </section>
  }
</form>
