<!--

    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]="kafkaConfigForm" class="flex flex-col">
  <mat-form-field class="mat-block" subscriptSizing="dynamic" appearance="outline">
    <mat-label translate>rule-node-config.topic-pattern</mat-label>
    <input required matInput formControlName="topicPattern">
    @if (kafkaConfigForm.get('topicPattern').hasError('required')) {
      <mat-error>
        {{ 'rule-node-config.topic-pattern-required' | translate }}
      </mat-error>
    }
    <mat-hint translate>rule-node-config.general-pattern-hint</mat-hint>
  </mat-form-field>
  <mat-form-field class="mat-block" subscriptSizing="dynamic" appearance="outline">
    <mat-label translate>rule-node-config.key-pattern</mat-label>
    <input matInput formControlName="keyPattern">
    <mat-hint translate>rule-node-config.general-pattern-hint</mat-hint>
  </mat-form-field>
  <div class="tb-hint" translate>rule-node-config.key-pattern-hint</div>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.bootstrap-servers</mat-label>
    <input required matInput formControlName="bootstrapServers">
    @if (kafkaConfigForm.get('bootstrapServers').hasError('required')) {
      <mat-error>
        {{ 'rule-node-config.bootstrap-servers-required' | translate }}
      </mat-error>
    }
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.retries</mat-label>
    <input type="number" step="1" min="0" matInput formControlName="retries">
    @if (kafkaConfigForm.get('retries').hasError('min')) {
      <mat-error>
        {{ 'rule-node-config.min-retries-message' | translate }}
      </mat-error>
    }
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.batch-size-bytes</mat-label>
    <input type="number" step="1" min="0" matInput formControlName="batchSize">
    @if (kafkaConfigForm.get('batchSize').hasError('min')) {
      <mat-error>
        {{ 'rule-node-config.min-batch-size-bytes-message' | translate }}
      </mat-error>
    }
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.linger-ms</mat-label>
    <input type="number" step="1" min="0" matInput formControlName="linger">
    @if (kafkaConfigForm.get('linger').hasError('min')) {
      <mat-error>
        {{ 'rule-node-config.min-linger-ms-message' | translate }}
      </mat-error>
    }
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.buffer-memory-bytes</mat-label>
    <input type="number" step="1" min="0" matInput formControlName="bufferMemory">
    @if (kafkaConfigForm.get('bufferMemory').hasError('min')) {
      <mat-error>
        {{ 'rule-node-config.min-buffer-memory-bytes-message' | translate }}
      </mat-error>
    }
  </mat-form-field>
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label translate>rule-node-config.acks</mat-label>
    <mat-select formControlName="acks" required>
      @for (ackValue of ackValues; track ackValue) {
        <mat-option [value]="ackValue">
          {{ ackValue }}
        </mat-option>
      }
    </mat-select>
  </mat-form-field>
  <label translate class="tb-title">rule-node-config.other-properties</label>
  <tb-kv-map-config
    required="false"
    formControlName="otherProperties"
    [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.other-properties-empty' | translate">
  </tb-kv-map-config>
  <mat-checkbox class="flex-1" formControlName="addMetadataKeyValuesAsKafkaHeaders">
    {{ 'rule-node-config.add-metadata-key-values-as-kafka-headers' | translate }}
  </mat-checkbox>
  <div class="tb-hint" translate>rule-node-config.add-metadata-key-values-as-kafka-headers-hint</div>
  @if (kafkaConfigForm.get('addMetadataKeyValuesAsKafkaHeaders').value) {
    <mat-form-field class="mat-block flex-1" appearance="outline">
      <mat-label translate>rule-node-config.charset-encoding</mat-label>
      <mat-select formControlName="kafkaHeadersCharset" required>
        @for (charset of ToByteStandartCharsetTypesValues; track charset) {
          <mat-option [value]="charset">
            {{ ToByteStandartCharsetTypeTranslationMap.get(charset) | translate }}
          </mat-option>
        }
      </mat-select>
    </mat-form-field>
  }
</section>
