import { Component, Input, Optional } from '@angular/core';
import { DatePipe, MeasurementRealtimeService } from '@c8y/ngx-components';
import { AsyncPipe, DecimalPipe, NgFor, NgIf, NgStyle } from '@angular/common';
import { InfoGaugeCurrentMeasurementPipe } from '../current-measurement.pipe';
import { ContextDashboardComponent } from '@c8y/ngx-components/context-dashboard';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components/context-dashboard";
export class InfoGaugeWidgetViewComponent {
    constructor(dashboard) {
        this.dashboard = dashboard;
        this.activeDatapointLabels = [];
        this.fractionSize = '1.1-1';
    }
    ngOnChanges() {
        if (this.config?.datapointsLabels && Array.isArray(this.config?.datapointsLabels)) {
            this.config.datapointsLabels.forEach(dp => this.assignContextFromContextDashboard(dp));
            this.activeDatapointLabels = this.config?.datapointsLabels.filter(dp => dp.__active);
        }
        if (this.config?.datapointsGauge && Array.isArray(this.config?.datapointsGauge)) {
            this.config.datapointsGauge.forEach(dp => this.assignContextFromContextDashboard(dp));
            this.activeDatapointGauge = this.config?.datapointsGauge.find(dp => dp.__active);
        }
        if (typeof this.config.fractionSize === 'number' && !Number.isNaN(this.config.fractionSize)) {
            this.fractionSize = `1.${this.config.fractionSize}-${this.config.fractionSize}`;
        }
    }
    assignContextFromContextDashboard(datapoint) {
        if (!this.dashboard?.isDeviceTypeDashboard) {
            return;
        }
        const context = this.dashboard?.context;
        if (context?.id) {
            const { name, id } = context;
            datapoint.__target = { name, id };
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: InfoGaugeWidgetViewComponent, deps: [{ token: i1.ContextDashboardComponent, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: InfoGaugeWidgetViewComponent, isStandalone: true, selector: "c8y-info-gauge-widget-view", inputs: { config: "config" }, host: { classAttribute: "d-contents" }, providers: [MeasurementRealtimeService], usesOnChanges: true, ngImport: i0, template: "<div class=\"label-value-unit-gauge\">\n  <div\n    class=\"gauge-legend\"\n    *ngIf=\"activeDatapointLabels?.length\"\n  >\n    <ng-container *ngFor=\"let dp of activeDatapointLabels\">\n      <ng-container *ngIf=\"dp | infoGaugeCurrentMeasurement | async as measurement\">\n        <label\n          class=\"text-truncate\"\n          title=\"{{ dp.label }}\"\n        >\n          {{ dp.label }}\n        </label>\n        <h3\n          class=\"text-truncate\"\n          title=\"{{ measurement.value | number: fractionSize }} {{ dp.unit || measurement.unit }}\"\n          *ngIf=\"!measurement.notFound; else notFound\"\n        >\n          {{ measurement.value | number: fractionSize }} {{ dp.unit || measurement.unit }}\n        </h3>\n        <ng-template #notFound>\n          <h3>--</h3>\n        </ng-template>\n        <p class=\"text-muted m-b-8\">\n          <small>\n            <em>{{ measurement.date | c8yDate: 'short' }}</em>\n          </small>\n        </p>\n      </ng-container>\n    </ng-container>\n  </div>\n\n  <ng-container *ngIf=\"activeDatapointGauge\">\n    <div\n      class=\"gauge-svg\"\n      *ngIf=\"activeDatapointGauge | infoGaugeCurrentMeasurement: true | async as measurement\"\n    >\n      <svg\n        height=\"214px\"\n        width=\"214px\"\n        viewBox=\"0 0 214 214\"\n        version=\"1.1\"\n        xmlns=\"http://www.w3.org/2000/svg\"\n        xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n      >\n        <desc>radial gauge</desc>\n        <g\n          id=\"scale\"\n          stroke=\"none\"\n          stroke-width=\"1\"\n          fill=\"none\"\n          fill-rule=\"evenodd\"\n          stroke-dasharray=\"1,5\"\n        >\n          <circle\n            id=\"Oval\"\n            stroke=\"#CACECE\"\n            stroke-width=\"7\"\n            cx=\"107\"\n            cy=\"107\"\n            r=\"103\"\n          ></circle>\n          <rect\n            id=\"mask\"\n            height=\"214\"\n            stroke=\"none\"\n            fill-rule=\"evenodd\"\n            x=\"0\"\n            y=\"0\"\n            width=\"214\"\n            transform=\"rotate(-45 290 182)\"\n          ></rect>\n        </g>\n        <path\n          class=\"track\"\n          d=\"M 107 27 a 80 80 0 1 0.1 0 Z\"\n          transform=\"rotate(-135 107 107)\"\n        ></path>\n        <path\n          class=\"track-value\"\n          [ngStyle]=\"{\n            stroke: measurement.color,\n            'stroke-dashoffset': -measurement.strokeDashOffset\n          }\"\n          d=\"M 107 27 a 80 80 0 1 0.1 0 Z\"\n          transform=\"rotate(-135 107 107)\"\n        ></path>\n        <foreignObject\n          class=\"d-flex a-i-center j-c-center\"\n          height=\"100%\"\n          width=\"100%\"\n          requiredFeatures=\"http://www.w3.org/TR/SVG11/feature#Extensibility\"\n        >\n          <div\n            class=\"d-flex d-col fit-h a-i-center j-c-center\"\n            style=\"padding: 3rem\"\n            xmlns=\"http://www.w3.org/1999/xhtml\"\n          >\n            <p\n              class=\"text-truncate text-center\"\n              title=\"{{ activeDatapointGauge.label }}\"\n            >\n              {{ activeDatapointGauge.label }}\n            </p>\n            <p\n              class=\"center-value text-truncate\"\n              title=\"{{ measurement.value | number: fractionSize }}\"\n              *ngIf=\"!measurement.notFound; else notFoundSVG\"\n            >\n              {{ measurement.value | number: fractionSize }}\n            </p>\n            <ng-template #notFoundSVG>\n              <p class=\"center-value\">--</p>\n            </ng-template>\n            <p class=\"center-unit strong\">{{ activeDatapointGauge.unit || measurement.unit }}</p>\n            <p class=\"center-date-time\">{{ measurement.date | c8yDate: 'short' }}</p>\n          </div>\n        </foreignObject>\n      </svg>\n    </div>\n  </ng-container>\n  <div class=\"clearfix\"></div>\n</div>\n", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "pipe", type: InfoGaugeCurrentMeasurementPipe, name: "infoGaugeCurrentMeasurement" }, { kind: "pipe", type: AsyncPipe, name: "async" }, { kind: "pipe", type: DecimalPipe, name: "number" }, { kind: "pipe", type: DatePipe, name: "c8yDate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: InfoGaugeWidgetViewComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-info-gauge-widget-view', host: { class: 'd-contents' }, providers: [MeasurementRealtimeService], standalone: true, imports: [NgIf, NgFor, NgStyle, InfoGaugeCurrentMeasurementPipe, AsyncPipe, DecimalPipe, DatePipe], template: "<div class=\"label-value-unit-gauge\">\n  <div\n    class=\"gauge-legend\"\n    *ngIf=\"activeDatapointLabels?.length\"\n  >\n    <ng-container *ngFor=\"let dp of activeDatapointLabels\">\n      <ng-container *ngIf=\"dp | infoGaugeCurrentMeasurement | async as measurement\">\n        <label\n          class=\"text-truncate\"\n          title=\"{{ dp.label }}\"\n        >\n          {{ dp.label }}\n        </label>\n        <h3\n          class=\"text-truncate\"\n          title=\"{{ measurement.value | number: fractionSize }} {{ dp.unit || measurement.unit }}\"\n          *ngIf=\"!measurement.notFound; else notFound\"\n        >\n          {{ measurement.value | number: fractionSize }} {{ dp.unit || measurement.unit }}\n        </h3>\n        <ng-template #notFound>\n          <h3>--</h3>\n        </ng-template>\n        <p class=\"text-muted m-b-8\">\n          <small>\n            <em>{{ measurement.date | c8yDate: 'short' }}</em>\n          </small>\n        </p>\n      </ng-container>\n    </ng-container>\n  </div>\n\n  <ng-container *ngIf=\"activeDatapointGauge\">\n    <div\n      class=\"gauge-svg\"\n      *ngIf=\"activeDatapointGauge | infoGaugeCurrentMeasurement: true | async as measurement\"\n    >\n      <svg\n        height=\"214px\"\n        width=\"214px\"\n        viewBox=\"0 0 214 214\"\n        version=\"1.1\"\n        xmlns=\"http://www.w3.org/2000/svg\"\n        xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n      >\n        <desc>radial gauge</desc>\n        <g\n          id=\"scale\"\n          stroke=\"none\"\n          stroke-width=\"1\"\n          fill=\"none\"\n          fill-rule=\"evenodd\"\n          stroke-dasharray=\"1,5\"\n        >\n          <circle\n            id=\"Oval\"\n            stroke=\"#CACECE\"\n            stroke-width=\"7\"\n            cx=\"107\"\n            cy=\"107\"\n            r=\"103\"\n          ></circle>\n          <rect\n            id=\"mask\"\n            height=\"214\"\n            stroke=\"none\"\n            fill-rule=\"evenodd\"\n            x=\"0\"\n            y=\"0\"\n            width=\"214\"\n            transform=\"rotate(-45 290 182)\"\n          ></rect>\n        </g>\n        <path\n          class=\"track\"\n          d=\"M 107 27 a 80 80 0 1 0.1 0 Z\"\n          transform=\"rotate(-135 107 107)\"\n        ></path>\n        <path\n          class=\"track-value\"\n          [ngStyle]=\"{\n            stroke: measurement.color,\n            'stroke-dashoffset': -measurement.strokeDashOffset\n          }\"\n          d=\"M 107 27 a 80 80 0 1 0.1 0 Z\"\n          transform=\"rotate(-135 107 107)\"\n        ></path>\n        <foreignObject\n          class=\"d-flex a-i-center j-c-center\"\n          height=\"100%\"\n          width=\"100%\"\n          requiredFeatures=\"http://www.w3.org/TR/SVG11/feature#Extensibility\"\n        >\n          <div\n            class=\"d-flex d-col fit-h a-i-center j-c-center\"\n            style=\"padding: 3rem\"\n            xmlns=\"http://www.w3.org/1999/xhtml\"\n          >\n            <p\n              class=\"text-truncate text-center\"\n              title=\"{{ activeDatapointGauge.label }}\"\n            >\n              {{ activeDatapointGauge.label }}\n            </p>\n            <p\n              class=\"center-value text-truncate\"\n              title=\"{{ measurement.value | number: fractionSize }}\"\n              *ngIf=\"!measurement.notFound; else notFoundSVG\"\n            >\n              {{ measurement.value | number: fractionSize }}\n            </p>\n            <ng-template #notFoundSVG>\n              <p class=\"center-value\">--</p>\n            </ng-template>\n            <p class=\"center-unit strong\">{{ activeDatapointGauge.unit || measurement.unit }}</p>\n            <p class=\"center-date-time\">{{ measurement.date | c8yDate: 'short' }}</p>\n          </div>\n        </foreignObject>\n      </svg>\n    </div>\n  </ng-container>\n  <div class=\"clearfix\"></div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.ContextDashboardComponent, decorators: [{
                    type: Optional
                }] }], propDecorators: { config: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 