<!--

    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.

-->
<div class="flex flex-col gap-2 px-4">
  <div>{{ 'calculated-fields.arguments' | translate }}</div>
  <div class="tb-form-table">
    <div class="tb-form-table-header">
      <div class="tb-form-table-header-cell w-1/6">{{ 'common.name' | translate }}</div>
      <div class="tb-form-table-header-cell w-1/5 xs:hidden">{{ 'common.type' | translate }}</div>
      <div class="tb-form-table-header-cell flex-1">{{ 'common.data' | translate }}</div>
    </div>
    <div class="tb-form-table-body">
      @for (group of argumentsFormArray.controls; track group) {
        <div [formGroup]="group" class="tb-form-table-row">
          <mat-form-field appearance="outline" class="tb-inline-field w-1/6" subscriptSizing="dynamic">
            <input matInput formControlName="argumentName" placeholder="{{ 'action.set' | translate }}">
          </mat-form-field>
          <mat-form-field appearance="outline" class="tb-inline-field w-1/5 xs:hidden" subscriptSizing="dynamic">
            <mat-select [value]="argumentsTypeMap.get(group.get('argumentName').value)" [disabled]="true">
              <mat-option [value]="argumentsTypeMap.get(group.get('argumentName').value)">
                {{ ArgumentTypeTranslations.get(argumentsTypeMap.get(group.get('argumentName').value)) | translate }}
              </mat-option>
            </mat-select>
          </mat-form-field>
          <div class="flex flex-1 items-center gap-2">
            @if (argumentsTypeMap.get(group.get('argumentName').value) === ArgumentType.Rolling) {
              <mat-form-field appearance="outline" subscriptSizing="dynamic" class="tb-inline-field flex-1">
                <input matInput tb-json-to-string name="rollingJson" formControlName="rollingJson" placeholder="{{ 'value.json-value' | translate }}"/>
              </mat-form-field>
            } @else {
              <mat-form-field appearance="outline" class="tb-inline-field w-1/3" subscriptSizing="dynamic">
                <input matInput formControlName="ts" type="number" placeholder="{{ 'common.timestamp' | translate }}">
              </mat-form-field>
              <tb-value-input class="argument-value min-w-60 flex-1" [required]="false" [hideJsonEdit]="true" [shortBooleanField]="true" formControlName="value"/>
            }
            <button mat-icon-button class="tb-mat-32" (click)="openEditJSONDialog(group)">
              <mat-icon class="tb-mat-20">open_in_new</mat-icon>
            </button>
          </div>
        </div>
      }
    </div>
  </div>
</div>
