<!--

    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]="saveToCustomTableConfigForm" class="tb-form-panel no-border no-padding">
  <mat-form-field class="mat-block" subscriptSizing="dynamic" appearance="outline">
    <mat-label translate>rule-node-config.custom-table-name</mat-label>
    <input required matInput formControlName="tableName">
    <mat-icon class="help-icon m-2 cursor-pointer"
              aria-hidden="false"
              aria-label="help-icon"
              color="primary"
              matSuffix
              matTooltip="{{ 'rule-node-config.custom-table-hint' | translate }}">
      help
    </mat-icon>
    @if (saveToCustomTableConfigForm.get('tableName').hasError('required') ||
      saveToCustomTableConfigForm.get('tableName').hasError('pattern')) {
      <mat-error>
        {{ 'rule-node-config.custom-table-name-required' | translate }}
      </mat-error>
    }
  </mat-form-field>
  <tb-kv-map-config
    required
    formControlName="fieldsMapping"
    [labelText]="'rule-node-config.fields-mapping' | translate"
    [requiredText]="'rule-node-config.fields-mapping-required' | translate"
    [keyText]="'rule-node-config.message-field' | translate"
    [keyRequiredText]="'rule-node-config.message-field-required' | translate"
    [valText]="'rule-node-config.table-col' | translate"
    [valRequiredText]="'rule-node-config.table-col-required' | translate"
    [hintText]="'rule-node-config.fields-mapping-hint'">
  </tb-kv-map-config>
  <mat-form-field class="mat-block flex-1" appearance="outline">
    <mat-label translate>rule-node-config.default-ttl</mat-label>
    <input type="number" min="0" step="1" matInput formControlName="defaultTtl" required>
    <mat-hint translate>rule-node-config.default-ttl-zero-hint</mat-hint>
    @if (saveToCustomTableConfigForm.get('defaultTtl').hasError('min')) {
      <mat-error>
        {{ 'rule-node-config.min-default-ttl-message' | translate }}
      </mat-error>
    }
    @if (saveToCustomTableConfigForm.get('defaultTtl').hasError('required')) {
      <mat-error>
        {{ 'rule-node-config.default-ttl-required' | translate }}
      </mat-error>
    }
  </mat-form-field>
</section>
