<!--

    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.

-->
<div class="tb-marker-image-settings-panel" [formGroup]="markerImageSettingsFormGroup">
  <div class="tb-marker-image-settings-title" translate>widgets.maps.data-layer.marker.marker-image</div>
  <div class="flex flex-row">
    <tb-toggle-select formControlName="type" class="flex-1">
      <tb-toggle-option [value]="MarkerImageType.image">
        {{ 'widgets.maps.data-layer.marker.marker-image-type-image' | translate }}
      </tb-toggle-option>
      <tb-toggle-option [value]="MarkerImageType.function">
        {{ 'widgets.maps.data-layer.marker.marker-image-type-function' | translate }}
      </tb-toggle-option>
    </tb-toggle-select>
  </div>
  <div class="tb-marker-image-settings-panel-body" [class.!hidden]="markerImageSettingsFormGroup.get('type').value !== MarkerImageType.image">
    <div class="tb-form-panel no-padding no-border">
      <tb-gallery-image-input required formControlName="image"></tb-gallery-image-input>
      <div class="tb-form-row space-between">
        <div>{{ 'widgets.maps.data-layer.marker.custom-marker-image-size' | translate }}</div>
        <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
          <input matInput formControlName="imageSize" type="number" min="1" step="1" placeholder="{{ 'widget-config.set' | translate }}">
          <div matSuffix>px</div>
        </mat-form-field>
      </div>
    </div>
  </div>
  <div class="tb-marker-image-settings-panel-body" [class.!hidden]="markerImageSettingsFormGroup.get('type').value !== MarkerImageType.function">
    <div class="tb-form-panel no-padding no-border">
      <tb-js-func formControlName="imageFunction"
                  withModules
                  [functionArgs]="['data', 'images', 'dsData']"
                  [globalVariables]="functionScopeVariables"
                  functionTitle="{{ 'widgets.maps.data-layer.marker.marker-image-function' | translate }}"
                  helpId="widget/lib/map/marker_image_fn"
                  [helpPopupStyle]="{width: '900px'}">
      </tb-js-func>
      <tb-multiple-gallery-image-input label="{{ 'widgets.maps.data-layer.marker.marker-images' | translate }}"
                                       formControlName="images">
      </tb-multiple-gallery-image-input>
    </div>
  </div>
  <div class="tb-marker-image-settings-panel-buttons">
    <span class="flex-1"></span>
    <button mat-button
            color="primary"
            type="button"
            (click)="cancel()">
      {{ 'action.cancel' | translate }}
    </button>
    <button mat-raised-button
            color="primary"
            type="button"
            (click)="applyMarkerImageSettings()"
            [disabled]="markerImageSettingsFormGroup.invalid || !markerImageSettingsFormGroup.dirty">
      {{ 'action.apply' | translate }}
    </button>
  </div>
</div>
