<!--

    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]="timeseriesConfigForm" class="tb-form-panel no-border no-padding">
  <div class="tb-form-panel stroked no-padding-bottom no-gap" formGroupName="processingSettings">
    <div class="mb-4 flex flex-row items-center justify-between">
      <div class="tb-form-panel-title" tb-hint-tooltip-icon="{{ 'rule-node-config.save-time-series.processing-settings-hint' | translate}}" translate>
        rule-node-config.save-time-series.processing-settings
      </div>
      <tb-toggle-select appearance="fill" selectMediaBreakpoint="xs"
                        formControlName="isAdvanced">
        <tb-toggle-option [value]=false>{{ 'rule-node-config.basic-mode' | translate}}</tb-toggle-option>
        <tb-toggle-option [value]=true>{{ 'rule-node-config.advanced-mode' | translate }}</tb-toggle-option>
      </tb-toggle-select>
    </div>
    @if(!timeseriesConfigForm.get('processingSettings.isAdvanced').value) {
      <mat-form-field appearance="outline">
        <mat-label translate>rule-node-config.save-time-series.strategy</mat-label>
        <mat-select formControlName="type">
          @for (strategy of processingStrategies; track strategy) {
            <mat-option [value]="strategy">{{ ProcessingTypeTranslationMap.get(strategy) | translate }}</mat-option>
          }
        </mat-select>
      </mat-form-field>

      @if(timeseriesConfigForm.get('processingSettings.type').value === ProcessingType.DEDUPLICATE) {
        <tb-time-unit-input
          appearance="outline"
          required
          labelText="{{ 'rule-node-config.save-time-series.deduplication-interval' | translate }}"
          requiredText="{{ 'rule-node-config.save-time-series.deduplication-interval-required' | translate }}"
          minErrorText="{{ 'rule-node-config.save-time-series.deduplication-interval-min-max-range' | translate }}"
          maxErrorText="{{ 'rule-node-config.save-time-series.deduplication-interval-min-max-range' | translate }}"
          [maxTime]="maxDeduplicateTime"
          [minTime]="1"
          formControlName="deduplicationIntervalSecs">
        </tb-time-unit-input>
      }
    } @else {
      <tb-advanced-processing-settings
        class="mb-4"
        formControlName="advanced"
        timeseries latest webSockets calculatedFields
      ></tb-advanced-processing-settings>
    }
  </div>
  <section class="tb-form-panel stroked">
    <mat-expansion-panel class="tb-settings">
      <mat-expansion-panel-header>
        <mat-panel-title translate>rule-node-config.advanced-settings</mat-panel-title>
      </mat-expansion-panel-header>
      <ng-template matExpansionPanelContent>
        <div tb-hint-tooltip-icon="{{ 'rule-node-config.use-server-ts-hint' | translate}}"
             class="tb-form-row no-border no-padding">
          <mat-slide-toggle class="mat-slide" formControlName="useServerTs">
            {{ 'rule-node-config.use-server-ts' | translate }}
          </mat-slide-toggle>
        </div>
        <tb-time-unit-input
          appearance="outline"
          required
          subscriptSizing="dynamic"
          labelText="{{ 'rule-node-config.default-ttl' | translate }}"
          requiredText="{{ 'rule-node-config.default-ttl-required' | translate }}"
          minErrorText="{{ 'rule-node-config.min-default-ttl-message' | translate }}"
          formControlName="defaultTTL">
          <mat-icon class="help-icon mr-2 cursor-pointer"
                    aria-hidden="false"
                    aria-label="help-icon"
                    color="primary"
                    matSuffix
                    matTooltip="{{ 'rule-node-config.default-ttl-hint' | translate }}">
            help
          </mat-icon>
        </tb-time-unit-input>
      </ng-template>
    </mat-expansion-panel>
  </section>
</section>
