{"version":3,"file":"c8y-ngx-components-widgets-definitions-info-gauge.mjs","sources":["../../widgets/definitions/info-gauge/info-gauge.constants.ts","../../widgets/definitions/info-gauge/index.ts","../../widgets/definitions/info-gauge/c8y-ngx-components-widgets-definitions-info-gauge.ts"],"sourcesContent":["import { DatapointAttributesFormConfig } from '@c8y/ngx-components/datapoint-selector';\nimport { AbstractControl, FormGroup, ValidatorFn } from '@angular/forms';\nimport { gettext } from '@c8y/ngx-components/gettext';\n\nconst AT_LEAST_ONE_ACTIVE_ERROR_KEY = 'noActiveDataPoint';\n\nexport function atLeastOneDataPointActive(dataPointsControlNames: string[]): ValidatorFn {\n  const validatorFn = (formGroup: AbstractControl) => {\n    if (!(formGroup instanceof FormGroup)) return null;\n\n    const errorKey = AT_LEAST_ONE_ACTIVE_ERROR_KEY;\n    let anyActive = false;\n\n    for (const controlName of dataPointsControlNames) {\n      const control = formGroup.get(controlName);\n      const value = control?.value;\n      if (Array.isArray(value) && value.some(item => item?.__active)) {\n        anyActive = true;\n        break;\n      }\n    }\n\n    // If none are active\n    if (!anyActive) {\n      // Set error on all specified controls\n      for (const controlName of dataPointsControlNames) {\n        const control = formGroup.get(controlName);\n        if (control) {\n          const errors = { ...(control.errors || {}) };\n          errors[errorKey] = true;\n          control.setErrors(errors);\n        }\n      }\n      // Set error on the group\n      return { [errorKey]: true };\n    } else {\n      // Remove error from all specified controls if present\n      for (const controlName of dataPointsControlNames) {\n        const control = formGroup.get(controlName);\n        if (control?.errors?.[errorKey]) {\n          const errors = { ...control.errors };\n          delete errors[errorKey];\n          control.setErrors(Object.keys(errors).length ? errors : null);\n        }\n      }\n      // Validation passes for the group\n      return null;\n    }\n  };\n\n  // Attach metadata to the validator function\n  (validatorFn as any).controlNames = dataPointsControlNames;\n\n  return validatorFn;\n}\n\nexport const DEFAULT_FORM_CONFIG: Partial<DatapointAttributesFormConfig> = {\n  showRedRange: true,\n  showYellowRange: true,\n  showRange: true,\n  selectableChartRenderTypes: []\n};\n\nexport const DATAPOINTS_GAUGE_CONTROL_NAME = 'datapointsGauge';\nexport const DATAPOINTS_LABELS_CONTROL_NAME = 'datapointsLabels';\n\nexport const minActiveDataPointError = {\n  [AT_LEAST_ONE_ACTIVE_ERROR_KEY]: gettext(\n    'At least 1 data point must be selected and active for the gauge or the labels.'\n  )\n} as const;\n","import type { DynamicWidgetDefinition } from '@c8y/ngx-components';\nimport { gettext } from '@c8y/ngx-components/gettext';\nimport {\n  DynamicDatapointsResolver,\n  hookWidget,\n  DynamicComponentErrorStrategy\n} from '@c8y/ngx-components';\nimport { defaultWidgetIds } from '@c8y/ngx-components/widgets/definitions';\nimport {\n  exportConfigWithTargets,\n  importConfigWithTargets\n} from '@c8y/ngx-components/widgets/import-export-config';\nimport { hookWidgetConfig } from '@c8y/ngx-components/context-dashboard';\nimport {\n  DATAPOINTS_LABELS_CONTROL_NAME,\n  DEFAULT_FORM_CONFIG,\n  atLeastOneDataPointActive,\n  DATAPOINTS_GAUGE_CONTROL_NAME,\n  minActiveDataPointError\n} from './info-gauge.constants';\n\nexport const infoGaugeWidgetDefinition = {\n  id: defaultWidgetIds.INFO_GAUGE,\n  label: gettext('Info gauge'),\n  description: gettext('Radial gauge and multiple label and value pairs for data points'),\n  loadComponent: () =>\n    import('@c8y/ngx-components/widgets/implementations/info-gauge').then(\n      m => m.InfoGaugeWidgetViewComponent\n    ),\n  loadConfigComponent: () =>\n    import('@c8y/ngx-components/widgets/implementations/info-gauge').then(\n      m => m.InfoGaugeWidgetConfigComponent\n    ),\n  previewImage: 'c8y-style-assets/info-gauge-widget-pr.png',\n  resolve: {\n    datapointsLabels: DynamicDatapointsResolver,\n    datapointsGauge: DynamicDatapointsResolver\n  },\n  errorStrategy: DynamicComponentErrorStrategy.OVERLAY_ERROR,\n  data: {\n    schema: () =>\n      import(\n        'c8y-schema-loader?interfaceName=InfoGaugeWidgetConfig!@c8y/ngx-components/widgets/implementations/info-gauge'\n      ),\n    export: exportConfigWithTargets,\n    import: importConfigWithTargets,\n    settings: {\n      noNewWidgets: false,\n      widgetDefaults: {\n        _width: 4,\n        _height: 2\n      },\n      ng1: {\n        options: {\n          noDeviceTarget: true,\n          groupsSelectable: false\n        }\n      }\n    }\n  }\n} satisfies DynamicWidgetDefinition;\n\nexport const infoGaugeWidgetProviders = [\n  hookWidget(infoGaugeWidgetDefinition),\n  hookWidgetConfig({\n    widgetId: defaultWidgetIds.INFO_GAUGE,\n    label: gettext('Gauge`display`'),\n    loadComponent: () =>\n      import('@c8y/ngx-components/datapoint-selector').then(\n        m => m.WidgetDatapointsSelectorComponent\n      ),\n    initialState: {\n      minActiveCount: 0,\n      defaultFormOptions: DEFAULT_FORM_CONFIG,\n      controlName: DATAPOINTS_GAUGE_CONTROL_NAME\n    },\n    expanded: true,\n    validators: [\n      atLeastOneDataPointActive([DATAPOINTS_GAUGE_CONTROL_NAME, DATAPOINTS_LABELS_CONTROL_NAME])\n    ],\n    validationErrors: minActiveDataPointError,\n    priority: 110\n  }),\n  hookWidgetConfig({\n    widgetId: defaultWidgetIds.INFO_GAUGE,\n    label: gettext('Multiple label and value pairs'),\n    loadComponent: () =>\n      import('@c8y/ngx-components/datapoint-selector').then(\n        m => m.WidgetDatapointsSelectorComponent\n      ),\n    initialState: {\n      minActiveCount: 0,\n      defaultFormOptions: DEFAULT_FORM_CONFIG,\n      controlName: DATAPOINTS_LABELS_CONTROL_NAME\n    },\n    validators: [\n      atLeastOneDataPointActive([DATAPOINTS_GAUGE_CONTROL_NAME, DATAPOINTS_LABELS_CONTROL_NAME])\n    ],\n    validationErrors: minActiveDataPointError,\n    priority: 100\n  })\n];\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAIA,MAAM,6BAA6B,GAAG,mBAAmB;AAEnD,SAAU,yBAAyB,CAAC,sBAAgC,EAAA;AACxE,IAAA,MAAM,WAAW,GAAG,CAAC,SAA0B,KAAI;AACjD,QAAA,IAAI,EAAE,SAAS,YAAY,SAAS,C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