<!--

    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.

-->
<section [formGroup]="rabbitMqConfigForm" class="flex flex-col">
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.exchange-name-pattern</mat-label>
    <input matInput formControlName="exchangeNamePattern">
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.routing-key-pattern</mat-label>
    <input matInput formControlName="routingKeyPattern">
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.message-properties</mat-label>
    <mat-select formControlName="messageProperties">
      @for (property of messageProperties; track property) {
        <mat-option [value]="property">
          {{ property }}
        </mat-option>
      }
    </mat-select>
  </mat-form-field>
  <div class="gt-sm:flex gt-sm:flex-row gt-sm:gap-2">
    <mat-form-field class="mat-block gt-sm:max-w-60% gt-sm:flex-full" appearance="outline">
      <mat-label translate>rule-node-config.host</mat-label>
      <input required matInput formControlName="host">
      @if (rabbitMqConfigForm.get('host').hasError('required')) {
        <mat-error>
          {{ 'rule-node-config.host-required' | translate }}
        </mat-error>
      }
    </mat-form-field>
    <mat-form-field class="mat-block gt-sm:max-w-40% gt-sm:flex-full" appearance="outline">
      <mat-label translate>rule-node-config.port</mat-label>
      <input required type="number" step="1" min="1" max="65535" matInput formControlName="port">
      @if (rabbitMqConfigForm.get('port').hasError('required')) {
        <mat-error>
          {{ 'rule-node-config.port-required' | translate }}
        </mat-error>
      }
      @if (rabbitMqConfigForm.get('port').hasError('min')) {
        <mat-error>
          {{ 'rule-node-config.port-range' | translate }}
        </mat-error>
      }
      @if (rabbitMqConfigForm.get('port').hasError('max')) {
        <mat-error>
          {{ 'rule-node-config.port-range' | translate }}
        </mat-error>
      }
    </mat-form-field>
  </div>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.virtual-host</mat-label>
    <input matInput formControlName="virtualHost">
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.username</mat-label>
    <input matInput formControlName="username">
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.password</mat-label>
    <input type="password" matInput formControlName="password" autocomplete="new-password">
    <tb-toggle-password matSuffix></tb-toggle-password>
  </mat-form-field>
  <mat-checkbox formControlName="automaticRecoveryEnabled">
    {{ 'rule-node-config.automatic-recovery' | translate }}
  </mat-checkbox>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.connection-timeout-ms</mat-label>
    <input type="number" step="1" min="0" matInput formControlName="connectionTimeout">
    @if (rabbitMqConfigForm.get('connectionTimeout').hasError('min')) {
      <mat-error>
        {{ 'rule-node-config.min-connection-timeout-ms-message' | translate }}
      </mat-error>
    }
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.handshake-timeout-ms</mat-label>
    <input type="number" step="1" min="0" matInput formControlName="handshakeTimeout">
    @if (rabbitMqConfigForm.get('handshakeTimeout').hasError('min')) {
      <mat-error>
        {{ 'rule-node-config.min-handshake-timeout-ms-message' | translate }}
      </mat-error>
    }
  </mat-form-field>
  <label translate class="tb-title">rule-node-config.client-properties</label>
  <tb-kv-map-config
    required="false"
    formControlName="clientProperties"
    [keyText]="'rule-node-config.key' | translate"
    [keyRequiredText]="'rule-node-config.key-required' | translate"
    [valText]="'rule-node-config.value' | translate"
    [valRequiredText]="'rule-node-config.value-required' | translate"
    [emptyText]="'rule-node-config.client-properties-empty' | translate">
  </tb-kv-map-config>
</section>
