<!--

    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.

-->
<mat-form-field [formGroup]="lwm2mListFormGroup" class="mat-block">
  <mat-label translate>device-profile.lwm2m.object-list</mat-label>
  <mat-chip-grid #chipList formControlName="objectsList" [required]="required">
    <mat-chip-row
      *ngFor="let objectLwm2m of objectsList"
      [removable]="!disabled"
      (removed)="remove(objectLwm2m)">
      {{objectLwm2m.name}} #{{objectLwm2m.keyId}}
      <mat-icon matChipRemove *ngIf="!disabled">close</mat-icon>
    </mat-chip-row>
    <input matInput type="text"
           style="max-width: 200px;"
           #objectInput
           (focusin)="onFocus()"
           formControlName="objectLwm2m"
           matAutocompleteOrigin
           #origin="matAutocompleteOrigin"
           [matAutocompleteConnectedTo]="origin"
           [matAutocomplete]="objectAutocomplete"
           [matChipInputFor]="chipList">
  </mat-chip-grid>
  <mat-autocomplete #objectAutocomplete="matAutocomplete"
                    class="tb-autocomplete"
                    [displayWith]="displayObjectLwm2mFn">
    <mat-option *ngFor="let objectLwm2m of filteredObjectsList | async" [value]="objectLwm2m">
      <span [innerHTML]="objectLwm2m.keyId + ': ' + (objectLwm2m.name  | highlight: searchText)"></span>
    </mat-option>
    <mat-option *ngIf="!(filteredObjectsList | async)?.length" [value]="null">
      <div *ngIf="!textIsNotEmpty(searchText); else searchNotEmpty">
        <span translate>device-profile.lwm2m.no-objects-found</span>
      </div>
      <ng-template #searchNotEmpty>
        <span>
            {{ 'device-profile.lwm2m.no-objects-matching' | translate:{object: truncate.transform(searchText, true, 6, &apos;...&apos;)} }}
        </span>
      </ng-template>
    </mat-option>
  </mat-autocomplete>
  <mat-error *ngIf="lwm2mListFormGroup.get('objectsList').hasError('required')">
    {{ 'device-profile.lwm2m.object-list-empty' | translate }}
  </mat-error>
</mat-form-field>

