<!--

    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]="resourcesFormGroup">
  <div fxLayout="row" fxLayoutAlign="start center">
    <div fxFlex="30">
      <mat-label translate>device-profile.lwm2m.resource-label</mat-label>
    </div>
    <div fxFlex="10" class="checkbox-column-title">
      <mat-label translate>device-profile.lwm2m.attribute-label</mat-label>
    </div>
    <div fxFlex="10" class="checkbox-column-title">
      <mat-label translate>device-profile.lwm2m.telemetry-label</mat-label>
    </div>
    <div fxFlex="10" class="checkbox-column-title">
      <mat-label translate>device-profile.lwm2m.observe-label</mat-label>
    </div>
    <div fxFlex>
      <mat-label translate>device-profile.lwm2m.key-name</mat-label>
    </div>
  </div>
  <mat-divider></mat-divider>
  <div formArrayName="resources"
    *ngFor="let resourceLwM2M of resourcesFormArray.controls; let $index = index; trackBy: trackByParams">
    <div [formGroupName]="$index" fxLayout="row" fxLayoutAlign="start center" class="resource-list">
      <div class="resource-name" fxFlex="30">
        #{{resourceLwM2M.get('id').value}} <span class="name">{{resourceLwM2M.get('name').value}}</span>
      </div>
      <div fxFlex="10" fxLayoutAlign="center center">
        <mat-checkbox formControlName="attribute" color="warn">
        </mat-checkbox>
      </div>
      <div fxFlex="10" fxLayoutAlign="center center">
        <mat-checkbox formControlName="telemetry" color="primary">
        </mat-checkbox>
      </div>
      <div fxFlex="10" fxLayoutAlign="center center">
        <mat-checkbox fxFlex="10" formControlName="observe" color="primary"
                      matTooltip="{{ 'device-profile.lwm2m.edit-observe-select'  | translate }}"
                      [matTooltipDisabled]="disabled || !isDisabledObserve($index)"
                      matTooltipPosition="above">
        </mat-checkbox>
      </div>
      <mat-form-field fxFlex="33">
        <input matInput type="text" formControlName="keyName" required>
        <mat-error *ngIf="resourceLwM2M.get('keyName').hasError('required') ||
                            resourceLwM2M.get('keyName').hasError('pattern')">
          {{ 'device-profile.lwm2m.key-name-required' | translate }}
        </mat-error>
      </mat-form-field>
      <span fxFlex></span>
      <tb-profile-lwm2m-attributes
        formControlName="attributes"
        [isAttributeTelemetry]="isDisabledObserve($index)"
        isResource="true"
        [modelName]="getNameResourceLwm2m(resourceLwM2M.value)">
      </tb-profile-lwm2m-attributes>
    </div>
  </div>
</section>
