<!--

    Copyright © 2016-2023 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">
    <mat-label>{{ 'device-profile.lwm2m.instances-list' | translate }}</mat-label>
    <mat-chip-grid #chipList formControlName="instanceList" [required]="required" (focus)="onFocus()">
      <mat-chip-row
        *ngFor="let instanceId of instancesId"
        [removable]="!disabled"
        (removed)="remove(instanceId)">
        {{instanceId}}
        <mat-icon matChipRemove *ngIf="!disabled">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>
    <mat-error *ngIf="instancesListFormGroup.get('instanceList').hasError('required')">
      {{ 'device-profile.lwm2m.instances-list-required' | translate }}
    </mat-error>
    <mat-error *ngIf="instancesListFormGroup.get('instanceId').hasError('pattern')">
      {{ 'device-profile.lwm2m.instance-id-pattern' | translate }}
    </mat-error>
    <mat-error *ngIf="instancesListFormGroup.get('instanceId').hasError('max')">
      {{ 'device-profile.lwm2m.instance-id-max' | translate: {max: instanceIdValueMax} }}
    </mat-error>
  </mat-form-field>
</section>

