<!--

    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]="instancesListFormGroup" class="lwm2m-instances-list">
  <mat-form-field class="mat-block" appearance="outline">
    <mat-label>{{ 'device-profile.lwm2m.instances-list' | translate }}</mat-label>
    <mat-chip-grid #chipList formControlName="instanceList" [required]="required" (focus)="onFocus()">
      @for (instanceId of instancesId; track instanceId) {
        <mat-chip-row
          [removable]="!disabled"
          (removed)="remove(instanceId)">
          {{instanceId}}
          @if (!disabled) {
            <mat-icon matChipRemove>close</mat-icon>
          }
        </mat-chip-row>
      }
      <input matInput type="text"
             #instanceId
             style="max-width: 70px;"
             formControlName="instanceId"
             [matChipInputFor]="chipList"
             [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
             matChipInputAddOnBlur
             (matChipInputTokenEnd)="add($event)">
    </mat-chip-grid>
    @if (instancesListFormGroup.get('instanceList').hasError('required')) {
      <mat-error>
        {{ 'device-profile.lwm2m.instances-list-required' | translate }}
      </mat-error>
    }
    @if (instancesListFormGroup.get('instanceId').hasError('pattern')) {
      <mat-error>
        {{ 'device-profile.lwm2m.instance-id-pattern' | translate }}
      </mat-error>
    }
    @if (instancesListFormGroup.get('instanceId').hasError('max')) {
      <mat-error>
        {{ 'device-profile.lwm2m.instance-id-max' | translate: {max: instanceIdValueMax} }}
      </mat-error>
    }
  </mat-form-field>
</section>

