<!--

    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 style="padding-bottom: 16px; margin: 0">
  <mat-tab-group dynamicHeight>
    <mat-tab label="{{ 'device-profile.lwm2m.model-tab' | translate }}">
      <ng-template matTabContent>
        <section [formGroup]="lwm2mDeviceProfileFormGroup">
          <tb-profile-lwm2m-object-list
            (addList)="addObjectsList($event)"
            (removeList)="removeObjectsList($event)"
            formControlName="objectIds">
          </tb-profile-lwm2m-object-list>
          <tb-profile-lwm2m-observe-attr-telemetry
            formControlName="observeAttrTelemetry">
          </tb-profile-lwm2m-observe-attr-telemetry>
        </section>
      </ng-template>
    </mat-tab>
    <mat-tab label="{{ 'device-profile.lwm2m.bootstrap-tab' | translate }}">
      <section [formGroup]="lwm2mDeviceProfileFormGroup">
        <div *ngIf="!isTransportWasRunWithBootstrap" style="padding:16px 0 0 8px;" fxLayout="row" fxLayoutAlign="start end">
          <mat-icon color="warn" class="material-icons" style="margin-right:8px;">warning</mat-icon>
          <span style="font-weight:500">LwM2M transport was run without bootstrap server</span>
        </div>
        <mat-checkbox formControlName="bootstrapServerUpdateEnable" style="margin-left:8px;margin-top:20px">
          {{ 'device-profile.lwm2m.include-bootstrap-server' | translate }}
        </mat-checkbox>
        <section style="padding: 20px 2px">
          <tb-profile-lwm2m-bootstrap-config-servers formControlName="bootstrap"
                                                     [isBootstrapServerUpdateEnable]="isBootstrapServerUpdateEnable"
                                                     [(isTransportWasRunWithBootstrap)]="isTransportWasRunWithBootstrap">
          </tb-profile-lwm2m-bootstrap-config-servers>
        </section>
      </section>
    </mat-tab>
    <mat-tab label="{{ 'device-profile.lwm2m.others-tab' | translate }}">
      <ng-template matTabContent [formGroup]="lwm2mDeviceProfileFormGroup">
        <section formGroupName="clientLwM2mSettings">
          <fieldset class="fields-group">
            <legend class="group-title" translate>device-profile.lwm2m.fw-update</legend>
            <mat-form-field class="mat-block" fxFlex>
              <mat-label>{{ 'device-profile.lwm2m.fw-update-strategy' | translate }}</mat-label>
              <mat-select formControlName="fwUpdateStrategy">
                <mat-option [value]=1>{{ 'device-profile.lwm2m.fw-update-strategy-package' | translate }}</mat-option>
                <mat-option [value]=2>{{ 'device-profile.lwm2m.fw-update-strategy-package-uri' | translate }}</mat-option>
                <mat-option [value]=3>{{ 'device-profile.lwm2m.fw-update-strategy-data' | translate }}</mat-option>
              </mat-select>
            </mat-form-field>
            <mat-form-field class="mat-block" fxFlex *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateStrategy').value === 2">
              <mat-label>{{ 'device-profile.lwm2m.fw-update-resource' | translate }}</mat-label>
              <input matInput formControlName="fwUpdateResource" required>
              <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').hasError('required')">
                {{ 'device-profile.lwm2m.fw-update-resource-required' | translate }}
              </mat-error>
            </mat-form-field>
          </fieldset>
          <fieldset class="fields-group">
            <legend class="group-title" translate>device-profile.lwm2m.sw-update</legend>
            <mat-form-field class="mat-block" fxFlex>
              <mat-label>{{ 'device-profile.lwm2m.sw-update-strategy' | translate }}</mat-label>
              <mat-select formControlName="swUpdateStrategy">
                <mat-option [value]=1>{{ 'device-profile.lwm2m.sw-update-strategy-package' | translate }}</mat-option>
                <mat-option [value]=2>{{ 'device-profile.lwm2m.sw-update-strategy-package-uri' | translate }}</mat-option>
              </mat-select>
            </mat-form-field>
            <mat-form-field class="mat-block" fxFlex *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateStrategy').value === 2">
              <mat-label>{{ 'device-profile.lwm2m.sw-update-resource' | translate }}</mat-label>
              <input matInput formControlName="swUpdateResource" required>
              <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').hasError('required')">
                {{ 'device-profile.lwm2m.sw-update-resource-required' | translate }}
              </mat-error>
            </mat-form-field>
          </fieldset>
          <fieldset class="fields-group">
            <legend class="group-title" translate>device-profile.power-saving-mode</legend>
            <tb-power-mode-settings [parentForm]="clientSettingsFormGroup">
            </tb-power-mode-settings>
          </fieldset>
          <mat-slide-toggle class="mat-slider"
           formControlName="compositeOperationsSupport">{{ 'device-profile.lwm2m.composite-operations-support' | translate }}</mat-slide-toggle>
<!--          <mat-accordion multi="true">-->
<!--            <div *ngIf="false">-->
<!--              <mat-expansion-panel>-->
<!--                <mat-expansion-panel-header>-->
<!--                  <mat-panel-title>{{ 'device-profile.lwm2m.client-strategy' | translate }}</mat-panel-title>-->
<!--                </mat-expansion-panel-header>-->
<!--                <ng-template matExpansionPanelContent>-->
<!--                  <div fxLayout="column">-->
<!--                    <mat-form-field class="mat-block">-->
<!--                      <mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label>-->
<!--                      <mat-select formControlName="clientOnlyObserveAfterConnect">-->
<!--                        <mat-option value=1>{{ 'device-profile.lwm2m.client-strategy-only-observe' | translate }}</mat-option>-->
<!--                        <mat-option value=2>{{ 'device-profile.lwm2m.client-strategy-read-all' | translate }}</mat-option>-->
<!--                      </mat-select>-->
<!--                    </mat-form-field>-->
<!--                  </div>-->
<!--                </ng-template>-->
<!--              </mat-expansion-panel>-->
<!--            </div>-->
<!--          </mat-accordion>-->
        </section>
      </ng-template>
    </mat-tab>
    <mat-tab label="{{ 'device-profile.lwm2m.config-json-tab' | translate }}">
      <ng-template matTabContent>
        <section style="padding: 8px 0">
          <tb-json-object-edit
            readonly
            [sort]="sortFunction"
            label="{{ 'device-profile.transport-type-lwm2m' | translate }}"
            [ngModel]="configurationValue">
          </tb-json-object-edit>
        </section>
      </ng-template>
    </mat-tab>
  </mat-tab-group>
</section>
