<!--

    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]="msgDelayConfigForm" class="flex flex-col">
  <mat-checkbox formControlName="useMetadataPeriodInSecondsPatterns">
    {{ 'rule-node-config.use-metadata-period-in-seconds-patterns' | translate }}
  </mat-checkbox>
  <div class="tb-hint" translate>rule-node-config.use-metadata-period-in-seconds-patterns-hint</div>
  @if (msgDelayConfigForm.get('useMetadataPeriodInSecondsPatterns').value !== true) {
    <mat-form-field
      appearance="outline"
      class="mat-block">
      <mat-label translate>rule-node-config.period-seconds</mat-label>
      <input required type="number" min="0" step="1" matInput formControlName="periodInSeconds">
      @if (msgDelayConfigForm.get('periodInSeconds').hasError('required')) {
        <mat-error>
          {{ 'rule-node-config.period-seconds-required' | translate }}
        </mat-error>
      }
      @if (msgDelayConfigForm.get('periodInSeconds').hasError('min')) {
        <mat-error>
          {{ 'rule-node-config.min-period-0-seconds-message' | translate }}
        </mat-error>
      }
    </mat-form-field>
  } @else {
    <mat-form-field class="mat-block" subscriptSizing="dynamic" appearance="outline">
      <mat-label translate>rule-node-config.period-in-seconds-pattern</mat-label>
      <input required matInput formControlName="periodInSecondsPattern">
      @if (msgDelayConfigForm.get('periodInSecondsPattern').hasError('required')) {
        <mat-error>
          {{ 'rule-node-config.period-in-seconds-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" appearance="outline">
    <mat-label translate>rule-node-config.max-pending-messages</mat-label>
    <input required type="number" min="1" max="100000" step="1" matInput formControlName="maxPendingMsgs">
    @if (msgDelayConfigForm.get('maxPendingMsgs').hasError('required')) {
      <mat-error>
        {{ 'rule-node-config.max-pending-messages-required' | translate }}
      </mat-error>
    }
    @if (msgDelayConfigForm.get('maxPendingMsgs').hasError('min')) {
      <mat-error>
        {{ 'rule-node-config.max-pending-messages-range' | translate }}
      </mat-error>
    }
    @if (msgDelayConfigForm.get('maxPendingMsgs').hasError('max')) {
      <mat-error>
        {{ 'rule-node-config.max-pending-messages-range' | translate }}
      </mat-error>
    }
  </mat-form-field>
</section>
