myio-js-library 0.1.140 → 0.1.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -568,7 +568,9 @@ var init_template_card = __esm({
568
568
  // src/index.ts
569
569
  var index_exports = {};
570
570
  __export(index_exports, {
571
+ CHART_COLORS: () => CHART_COLORS,
571
572
  ConnectionStatusType: () => ConnectionStatusType,
573
+ DEFAULT_CLAMP_RANGE: () => DEFAULT_CLAMP_RANGE,
572
574
  DeviceStatusType: () => DeviceStatusType,
573
575
  MyIOChartModal: () => MyIOChartModal,
574
576
  MyIODraggableCard: () => MyIODraggableCard,
@@ -577,6 +579,7 @@ __export(index_exports, {
577
579
  MyIOToast: () => MyIOToast,
578
580
  addDetectionContext: () => addDetectionContext,
579
581
  addNamespace: () => addNamespace,
582
+ aggregateByDay: () => aggregateByDay,
580
583
  averageByDay: () => averageByDay,
581
584
  buildListItemsThingsboardByUniqueDatasource: () => buildListItemsThingsboardByUniqueDatasource,
582
585
  buildMyioIngestionAuth: () => buildMyioIngestionAuth,
@@ -585,6 +588,8 @@ __export(index_exports, {
585
588
  calcDeltaPercent: () => calcDeltaPercent,
586
589
  calculateDeviceStatus: () => calculateDeviceStatus,
587
590
  calculateDeviceStatusWithRanges: () => calculateDeviceStatusWithRanges,
591
+ calculateStats: () => calculateStats,
592
+ clampTemperature: () => clampTemperature,
588
593
  classify: () => classify,
589
594
  classifyWaterLabel: () => classifyWaterLabel,
590
595
  classifyWaterLabels: () => classifyWaterLabels,
@@ -597,9 +602,11 @@ __export(index_exports, {
597
602
  detectDeviceType: () => detectDeviceType,
598
603
  determineInterval: () => determineInterval,
599
604
  deviceStatusIcons: () => deviceStatusIcons,
605
+ exportTemperatureCSV: () => exportTemperatureCSV,
600
606
  exportToCSV: () => exportToCSV,
601
607
  exportToCSVAll: () => exportToCSVAll,
602
608
  extractMyIOCredentials: () => extractMyIOCredentials,
609
+ fetchTemperatureData: () => fetchTemperatureData,
603
610
  fetchThingsboardCustomerAttrsFromStorage: () => fetchThingsboardCustomerAttrsFromStorage,
604
611
  fetchThingsboardCustomerServerScopeAttrs: () => fetchThingsboardCustomerServerScopeAttrs,
605
612
  findValue: () => findValue,
@@ -613,6 +620,7 @@ __export(index_exports, {
613
620
  formatEnergy: () => formatEnergy,
614
621
  formatNumberReadable: () => formatNumberReadable,
615
622
  formatTankHeadFromCm: () => formatTankHeadFromCm,
623
+ formatTemperature: () => formatTemperature,
616
624
  formatWaterByGroup: () => formatWaterByGroup,
617
625
  formatWaterVolumeM3: () => formatWaterVolumeM3,
618
626
  getAuthCacheStats: () => getAuthCacheStats,
@@ -627,6 +635,7 @@ __export(index_exports, {
627
635
  getValueByDatakeyLegacy: () => getValueByDatakeyLegacy,
628
636
  getWaterCategories: () => getWaterCategories,
629
637
  groupByDay: () => groupByDay,
638
+ interpolateTemperature: () => interpolateTemperature,
630
639
  isDeviceOffline: () => isDeviceOffline,
631
640
  isValidConnectionStatus: () => isValidConnectionStatus,
632
641
  isValidDeviceStatus: () => isValidDeviceStatus,
@@ -644,6 +653,9 @@ __export(index_exports, {
644
653
  openDemandModal: () => openDemandModal,
645
654
  openGoalsPanel: () => openGoalsPanel,
646
655
  openRealTimeTelemetryModal: () => openRealTimeTelemetryModal,
656
+ openTemperatureComparisonModal: () => openTemperatureComparisonModal,
657
+ openTemperatureModal: () => openTemperatureModal,
658
+ openTemperatureSettingsModal: () => openTemperatureSettingsModal,
647
659
  parseInputDateToDate: () => parseInputDateToDate,
648
660
  renderCardComponent: () => renderCardComponent,
649
661
  renderCardComponentEnhanced: () => renderCardComponent2,
@@ -18244,13 +18256,13 @@ function openGoalsPanel(params) {
18244
18256
  function initializeModal() {
18245
18257
  if (data) {
18246
18258
  modalState.goalsData = data;
18247
- renderModal();
18259
+ renderModal4();
18248
18260
  } else {
18249
- renderModal();
18261
+ renderModal4();
18250
18262
  loadGoalsData();
18251
18263
  }
18252
18264
  }
18253
- function renderModal() {
18265
+ function renderModal4() {
18254
18266
  const existing = document.getElementById("myio-goals-panel-modal");
18255
18267
  if (existing) {
18256
18268
  existing.remove();
@@ -19638,9 +19650,2333 @@ function openGoalsPanel(params) {
19638
19650
  };
19639
19651
  }
19640
19652
  }
19653
+
19654
+ // src/components/temperature/utils.ts
19655
+ var DAY_PERIODS = [
19656
+ { id: "madrugada", label: "Madrugada (00h-06h)", startHour: 0, endHour: 6 },
19657
+ { id: "manha", label: "Manh\xE3 (06h-12h)", startHour: 6, endHour: 12 },
19658
+ { id: "tarde", label: "Tarde (12h-18h)", startHour: 12, endHour: 18 },
19659
+ { id: "noite", label: "Noite (18h-24h)", startHour: 18, endHour: 24 }
19660
+ ];
19661
+ var DEFAULT_CLAMP_RANGE = { min: 15, max: 40 };
19662
+ function getTodaySoFar() {
19663
+ const now = /* @__PURE__ */ new Date();
19664
+ const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
19665
+ return {
19666
+ startTs: startOfDay.getTime(),
19667
+ endTs: now.getTime()
19668
+ };
19669
+ }
19670
+ var CHART_COLORS = [
19671
+ "#1976d2",
19672
+ // Blue
19673
+ "#FF6B6B",
19674
+ // Red
19675
+ "#4CAF50",
19676
+ // Green
19677
+ "#FF9800",
19678
+ // Orange
19679
+ "#9C27B0",
19680
+ // Purple
19681
+ "#00BCD4",
19682
+ // Cyan
19683
+ "#E91E63",
19684
+ // Pink
19685
+ "#795548"
19686
+ // Brown
19687
+ ];
19688
+ async function fetchTemperatureData(token, deviceId, startTs, endTs) {
19689
+ const url = `/api/plugins/telemetry/DEVICE/${deviceId}/values/timeseries?keys=temperature&startTs=${encodeURIComponent(startTs)}&endTs=${encodeURIComponent(endTs)}&limit=50000&agg=NONE`;
19690
+ const response = await fetch(url, {
19691
+ headers: {
19692
+ "X-Authorization": `Bearer ${token}`,
19693
+ "Content-Type": "application/json"
19694
+ }
19695
+ });
19696
+ if (!response.ok) {
19697
+ throw new Error(`Failed to fetch temperature data: ${response.status}`);
19698
+ }
19699
+ const data = await response.json();
19700
+ return data?.temperature || [];
19701
+ }
19702
+ function clampTemperature(value, range = DEFAULT_CLAMP_RANGE) {
19703
+ const num = Number(value || 0);
19704
+ if (num < range.min) return range.min;
19705
+ if (num > range.max) return range.max;
19706
+ return num;
19707
+ }
19708
+ function calculateStats(data, clampRange = DEFAULT_CLAMP_RANGE) {
19709
+ if (data.length === 0) {
19710
+ return { avg: 0, min: 0, max: 0, count: 0 };
19711
+ }
19712
+ const values = data.map((item) => clampTemperature(item.value, clampRange));
19713
+ const sum = values.reduce((acc, v) => acc + v, 0);
19714
+ return {
19715
+ avg: sum / values.length,
19716
+ min: Math.min(...values),
19717
+ max: Math.max(...values),
19718
+ count: values.length
19719
+ };
19720
+ }
19721
+ function interpolateTemperature(data, options) {
19722
+ const { intervalMinutes, startTs, endTs, clampRange = DEFAULT_CLAMP_RANGE } = options;
19723
+ const intervalMs = intervalMinutes * 60 * 1e3;
19724
+ if (data.length === 0) {
19725
+ return [];
19726
+ }
19727
+ const sortedData = [...data].sort((a, b) => a.ts - b.ts);
19728
+ const result = [];
19729
+ let lastKnownValue = clampTemperature(sortedData[0].value, clampRange);
19730
+ let dataIndex = 0;
19731
+ for (let ts = startTs; ts <= endTs; ts += intervalMs) {
19732
+ while (dataIndex < sortedData.length - 1 && sortedData[dataIndex + 1].ts <= ts) {
19733
+ dataIndex++;
19734
+ }
19735
+ const currentData = sortedData[dataIndex];
19736
+ if (currentData && Math.abs(currentData.ts - ts) < intervalMs) {
19737
+ lastKnownValue = clampTemperature(currentData.value, clampRange);
19738
+ }
19739
+ result.push({
19740
+ ts,
19741
+ value: lastKnownValue
19742
+ });
19743
+ }
19744
+ return result;
19745
+ }
19746
+ function aggregateByDay(data, clampRange = DEFAULT_CLAMP_RANGE) {
19747
+ if (data.length === 0) {
19748
+ return [];
19749
+ }
19750
+ const dayMap = /* @__PURE__ */ new Map();
19751
+ data.forEach((item) => {
19752
+ const date = new Date(item.ts);
19753
+ const dateKey = date.toISOString().split("T")[0];
19754
+ if (!dayMap.has(dateKey)) {
19755
+ dayMap.set(dateKey, []);
19756
+ }
19757
+ dayMap.get(dateKey).push(item);
19758
+ });
19759
+ const result = [];
19760
+ dayMap.forEach((dayData, dateKey) => {
19761
+ const values = dayData.map((item) => clampTemperature(item.value, clampRange));
19762
+ const sum = values.reduce((acc, v) => acc + v, 0);
19763
+ result.push({
19764
+ date: dateKey,
19765
+ dateTs: new Date(dateKey).getTime(),
19766
+ avg: sum / values.length,
19767
+ min: Math.min(...values),
19768
+ max: Math.max(...values),
19769
+ count: values.length
19770
+ });
19771
+ });
19772
+ return result.sort((a, b) => a.dateTs - b.dateTs);
19773
+ }
19774
+ function filterByDayPeriods(data, selectedPeriods) {
19775
+ if (selectedPeriods.length === 0 || selectedPeriods.length === DAY_PERIODS.length) {
19776
+ return data;
19777
+ }
19778
+ return data.filter((item) => {
19779
+ const date = new Date(item.ts);
19780
+ const hour = date.getHours();
19781
+ return selectedPeriods.some((periodId) => {
19782
+ const period = DAY_PERIODS.find((p) => p.id === periodId);
19783
+ if (!period) return false;
19784
+ return hour >= period.startHour && hour < period.endHour;
19785
+ });
19786
+ });
19787
+ }
19788
+ function getSelectedPeriodsLabel(selectedPeriods) {
19789
+ if (selectedPeriods.length === 0 || selectedPeriods.length === DAY_PERIODS.length) {
19790
+ return "Todos os per\xEDodos";
19791
+ }
19792
+ if (selectedPeriods.length === 1) {
19793
+ const period = DAY_PERIODS.find((p) => p.id === selectedPeriods[0]);
19794
+ return period?.label || "";
19795
+ }
19796
+ return `${selectedPeriods.length} per\xEDodos selecionados`;
19797
+ }
19798
+ function formatTemperature(value, decimals = 1) {
19799
+ return `${value.toFixed(decimals)}\xB0C`;
19800
+ }
19801
+ function exportTemperatureCSV(data, deviceLabel, stats, startDate, endDate) {
19802
+ if (data.length === 0) {
19803
+ console.warn("No data to export");
19804
+ return;
19805
+ }
19806
+ const BOM = "\uFEFF";
19807
+ let csvContent = BOM;
19808
+ csvContent += `Relat\xF3rio de Temperatura - ${deviceLabel}
19809
+ `;
19810
+ csvContent += `Per\xEDodo: ${startDate} at\xE9 ${endDate}
19811
+ `;
19812
+ csvContent += `M\xE9dia: ${formatTemperature(stats.avg)}
19813
+ `;
19814
+ csvContent += `M\xEDnima: ${formatTemperature(stats.min)}
19815
+ `;
19816
+ csvContent += `M\xE1xima: ${formatTemperature(stats.max)}
19817
+ `;
19818
+ csvContent += `Total de leituras: ${stats.count}
19819
+ `;
19820
+ csvContent += "\n";
19821
+ csvContent += "Data/Hora,Temperatura (\xB0C)\n";
19822
+ data.forEach((item) => {
19823
+ const date = new Date(item.ts).toLocaleString("pt-BR");
19824
+ const temp = Number(item.value).toFixed(2);
19825
+ csvContent += `"${date}",${temp}
19826
+ `;
19827
+ });
19828
+ const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
19829
+ const url = URL.createObjectURL(blob);
19830
+ const link = document.createElement("a");
19831
+ link.href = url;
19832
+ link.download = `temperatura_${deviceLabel.replace(/\s+/g, "_")}_${startDate}_${endDate}.csv`;
19833
+ document.body.appendChild(link);
19834
+ link.click();
19835
+ document.body.removeChild(link);
19836
+ URL.revokeObjectURL(url);
19837
+ }
19838
+ var DARK_THEME = {
19839
+ background: "rgba(0, 0, 0, 0.85)",
19840
+ surface: "#1a1f28",
19841
+ text: "#ffffff",
19842
+ textMuted: "rgba(255, 255, 255, 0.7)",
19843
+ border: "rgba(255, 255, 255, 0.1)",
19844
+ primary: "#1976d2",
19845
+ success: "#4CAF50",
19846
+ warning: "#FF9800",
19847
+ danger: "#f44336",
19848
+ chartLine: "#1976d2",
19849
+ chartGrid: "rgba(255, 255, 255, 0.1)"
19850
+ };
19851
+ var LIGHT_THEME = {
19852
+ background: "rgba(0, 0, 0, 0.6)",
19853
+ surface: "#ffffff",
19854
+ text: "#333333",
19855
+ textMuted: "#666666",
19856
+ border: "#e0e0e0",
19857
+ primary: "#1976d2",
19858
+ success: "#4CAF50",
19859
+ warning: "#FF9800",
19860
+ danger: "#f44336",
19861
+ chartLine: "#1976d2",
19862
+ chartGrid: "#e0e0e0"
19863
+ };
19864
+ function getThemeColors(theme) {
19865
+ return theme === "dark" ? DARK_THEME : LIGHT_THEME;
19866
+ }
19867
+
19868
+ // src/components/temperature/TemperatureModal.ts
19869
+ async function openTemperatureModal(params) {
19870
+ const modalId = `myio-temp-modal-${Date.now()}`;
19871
+ const defaultDateRange = getTodaySoFar();
19872
+ const startTs = params.startDate ? new Date(params.startDate).getTime() : defaultDateRange.startTs;
19873
+ const endTs = params.endDate ? new Date(params.endDate).getTime() : defaultDateRange.endTs;
19874
+ const state = {
19875
+ token: params.token,
19876
+ deviceId: params.deviceId,
19877
+ label: params.label || "Sensor de Temperatura",
19878
+ currentTemperature: params.currentTemperature ?? null,
19879
+ temperatureMin: params.temperatureMin ?? null,
19880
+ temperatureMax: params.temperatureMax ?? null,
19881
+ temperatureStatus: params.temperatureStatus ?? null,
19882
+ startTs,
19883
+ endTs,
19884
+ granularity: params.granularity || "hour",
19885
+ theme: params.theme || "light",
19886
+ clampRange: params.clampRange || DEFAULT_CLAMP_RANGE,
19887
+ locale: params.locale || "pt-BR",
19888
+ data: [],
19889
+ stats: { avg: 0, min: 0, max: 0, count: 0 },
19890
+ isLoading: true,
19891
+ dateRangePicker: null,
19892
+ selectedPeriods: ["madrugada", "manha", "tarde", "noite"]
19893
+ // All periods selected by default
19894
+ };
19895
+ const savedGranularity = localStorage.getItem("myio-temp-modal-granularity");
19896
+ const savedTheme = localStorage.getItem("myio-temp-modal-theme");
19897
+ if (savedGranularity) state.granularity = savedGranularity;
19898
+ if (savedTheme) state.theme = savedTheme;
19899
+ const modalContainer = document.createElement("div");
19900
+ modalContainer.id = modalId;
19901
+ document.body.appendChild(modalContainer);
19902
+ renderModal(modalContainer, state, modalId);
19903
+ try {
19904
+ state.data = await fetchTemperatureData(state.token, state.deviceId, state.startTs, state.endTs);
19905
+ state.stats = calculateStats(state.data, state.clampRange);
19906
+ state.isLoading = false;
19907
+ renderModal(modalContainer, state, modalId);
19908
+ drawChart(modalId, state);
19909
+ } catch (error) {
19910
+ console.error("[TemperatureModal] Error fetching data:", error);
19911
+ state.isLoading = false;
19912
+ renderModal(modalContainer, state, modalId, error);
19913
+ }
19914
+ await setupEventListeners(modalContainer, state, modalId, params.onClose);
19915
+ return {
19916
+ destroy: () => {
19917
+ modalContainer.remove();
19918
+ params.onClose?.();
19919
+ },
19920
+ updateData: async (startDate, endDate, granularity) => {
19921
+ state.startTs = new Date(startDate).getTime();
19922
+ state.endTs = new Date(endDate).getTime();
19923
+ if (granularity) state.granularity = granularity;
19924
+ state.isLoading = true;
19925
+ renderModal(modalContainer, state, modalId);
19926
+ try {
19927
+ state.data = await fetchTemperatureData(state.token, state.deviceId, state.startTs, state.endTs);
19928
+ state.stats = calculateStats(state.data, state.clampRange);
19929
+ state.isLoading = false;
19930
+ renderModal(modalContainer, state, modalId);
19931
+ drawChart(modalId, state);
19932
+ } catch (error) {
19933
+ console.error("[TemperatureModal] Error updating data:", error);
19934
+ state.isLoading = false;
19935
+ renderModal(modalContainer, state, modalId, error);
19936
+ }
19937
+ }
19938
+ };
19939
+ }
19940
+ function renderModal(container, state, modalId, error) {
19941
+ const colors = getThemeColors(state.theme);
19942
+ const startDateStr = new Date(state.startTs).toLocaleDateString(state.locale);
19943
+ const endDateStr = new Date(state.endTs).toLocaleDateString(state.locale);
19944
+ const statusText = state.temperatureStatus === "ok" ? "Dentro da faixa" : state.temperatureStatus === "above" ? "Acima do limite" : state.temperatureStatus === "below" ? "Abaixo do limite" : "N/A";
19945
+ const statusColor = state.temperatureStatus === "ok" ? colors.success : state.temperatureStatus === "above" ? colors.danger : state.temperatureStatus === "below" ? colors.primary : colors.textMuted;
19946
+ const rangeText = state.temperatureMin !== null && state.temperatureMax !== null ? `${state.temperatureMin}\xB0C - ${state.temperatureMax}\xB0C` : "N\xE3o definida";
19947
+ const startDateInput = new Date(state.startTs).toISOString().slice(0, 16);
19948
+ const endDateInput = new Date(state.endTs).toISOString().slice(0, 16);
19949
+ const isMaximized = container.__isMaximized || false;
19950
+ const contentMaxWidth = isMaximized ? "100%" : "900px";
19951
+ const contentMaxHeight = isMaximized ? "100vh" : "95vh";
19952
+ const contentBorderRadius = isMaximized ? "0" : "10px";
19953
+ container.innerHTML = `
19954
+ <div class="myio-temp-modal-overlay" style="
19955
+ position: fixed; top: 0; left: 0; width: 100%; height: 100%;
19956
+ background: rgba(0, 0, 0, 0.5); z-index: 9998;
19957
+ display: flex; justify-content: center; align-items: center;
19958
+ backdrop-filter: blur(2px);
19959
+ ">
19960
+ <div class="myio-temp-modal-content" style="
19961
+ background: ${colors.surface}; border-radius: ${contentBorderRadius};
19962
+ max-width: ${contentMaxWidth}; width: ${isMaximized ? "100%" : "95%"};
19963
+ max-height: ${contentMaxHeight}; height: ${isMaximized ? "100%" : "auto"};
19964
+ overflow: hidden; display: flex; flex-direction: column;
19965
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
19966
+ font-family: 'Roboto', Arial, sans-serif;
19967
+ ">
19968
+ <!-- Header - MyIO Premium Style -->
19969
+ <div style="
19970
+ padding: 4px 8px; display: flex; align-items: center; justify-content: space-between;
19971
+ background: #3e1a7d; color: white; border-radius: ${isMaximized ? "0" : "10px 10px 0 0"};
19972
+ min-height: 20px;
19973
+ ">
19974
+ <h2 style="margin: 6px; font-size: 18px; font-weight: 600; color: white; line-height: 2;">
19975
+ \u{1F321}\uFE0F ${state.label} - Hist\xF3rico de Temperatura
19976
+ </h2>
19977
+ <div style="display: flex; gap: 4px; align-items: center;">
19978
+ <!-- Theme Toggle -->
19979
+ <button id="${modalId}-theme-toggle" title="Alternar tema" style="
19980
+ background: none; border: none; font-size: 16px; cursor: pointer;
19981
+ padding: 4px 8px; border-radius: 6px; color: rgba(255,255,255,0.8);
19982
+ transition: background-color 0.2s;
19983
+ ">${state.theme === "dark" ? "\u2600\uFE0F" : "\u{1F319}"}</button>
19984
+ <!-- Maximize Button -->
19985
+ <button id="${modalId}-maximize" title="${isMaximized ? "Restaurar" : "Maximizar"}" style="
19986
+ background: none; border: none; font-size: 16px; cursor: pointer;
19987
+ padding: 4px 8px; border-radius: 6px; color: rgba(255,255,255,0.8);
19988
+ transition: background-color 0.2s;
19989
+ ">${isMaximized ? "\u{1F5D7}" : "\u{1F5D6}"}</button>
19990
+ <!-- Close Button -->
19991
+ <button id="${modalId}-close" title="Fechar" style="
19992
+ background: none; border: none; font-size: 20px; cursor: pointer;
19993
+ padding: 4px 8px; border-radius: 6px; color: rgba(255,255,255,0.8);
19994
+ transition: background-color 0.2s;
19995
+ ">\xD7</button>
19996
+ </div>
19997
+ </div>
19998
+
19999
+ <!-- Body -->
20000
+ <div style="flex: 1; overflow-y: auto; padding: 16px;">
20001
+
20002
+ <!-- Controls Row -->
20003
+ <div style="
20004
+ display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
20005
+ margin-bottom: 16px; padding: 16px; background: ${state.theme === "dark" ? "rgba(255,255,255,0.05)" : "#f7f7f7"};
20006
+ border-radius: 6px; border: 1px solid ${colors.border};
20007
+ ">
20008
+ <!-- Granularity Select -->
20009
+ <div>
20010
+ <label style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500; display: block; margin-bottom: 4px;">
20011
+ Granularidade
20012
+ </label>
20013
+ <select id="${modalId}-granularity" style="
20014
+ padding: 8px 12px; border: 1px solid ${colors.border}; border-radius: 6px;
20015
+ font-size: 14px; color: ${colors.text}; background: ${colors.surface};
20016
+ cursor: pointer; min-width: 130px;
20017
+ ">
20018
+ <option value="hour" ${state.granularity === "hour" ? "selected" : ""}>Hora (30 min)</option>
20019
+ <option value="day" ${state.granularity === "day" ? "selected" : ""}>Dia (m\xE9dia)</option>
20020
+ </select>
20021
+ </div>
20022
+ <!-- Day Period Filter (Multiselect) -->
20023
+ <div style="position: relative;">
20024
+ <label style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500; display: block; margin-bottom: 4px;">
20025
+ Per\xEDodos do Dia
20026
+ </label>
20027
+ <button id="${modalId}-period-btn" type="button" style="
20028
+ padding: 8px 12px; border: 1px solid ${colors.border}; border-radius: 6px;
20029
+ font-size: 14px; color: ${colors.text}; background: ${colors.surface};
20030
+ cursor: pointer; min-width: 180px; text-align: left;
20031
+ display: flex; align-items: center; justify-content: space-between; gap: 8px;
20032
+ ">
20033
+ <span>${getSelectedPeriodsLabel(state.selectedPeriods)}</span>
20034
+ <span style="font-size: 10px;">\u25BC</span>
20035
+ </button>
20036
+ <div id="${modalId}-period-dropdown" style="
20037
+ display: none; position: absolute; top: 100%; left: 0; z-index: 1000;
20038
+ background: ${colors.surface}; border: 1px solid ${colors.border};
20039
+ border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
20040
+ min-width: 200px; margin-top: 4px; padding: 8px 0;
20041
+ ">
20042
+ ${DAY_PERIODS.map((period) => `
20043
+ <label style="
20044
+ display: flex; align-items: center; gap: 8px; padding: 8px 12px;
20045
+ cursor: pointer; font-size: 13px; color: ${colors.text};
20046
+ " onmouseover="this.style.background='${state.theme === "dark" ? "rgba(255,255,255,0.1)" : "#f0f0f0"}'"
20047
+ onmouseout="this.style.background='transparent'">
20048
+ <input type="checkbox"
20049
+ name="${modalId}-period"
20050
+ value="${period.id}"
20051
+ ${state.selectedPeriods.includes(period.id) ? "checked" : ""}
20052
+ style="width: 16px; height: 16px; cursor: pointer; accent-color: #3e1a7d;">
20053
+ ${period.label}
20054
+ </label>
20055
+ `).join("")}
20056
+ <div style="border-top: 1px solid ${colors.border}; margin-top: 8px; padding-top: 8px;">
20057
+ <button id="${modalId}-period-select-all" type="button" style="
20058
+ width: calc(100% - 16px); margin: 0 8px 4px; padding: 6px;
20059
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.1)" : "#f0f0f0"};
20060
+ border: none; border-radius: 4px; cursor: pointer;
20061
+ font-size: 12px; color: ${colors.text};
20062
+ ">Selecionar Todos</button>
20063
+ <button id="${modalId}-period-clear" type="button" style="
20064
+ width: calc(100% - 16px); margin: 0 8px; padding: 6px;
20065
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.1)" : "#f0f0f0"};
20066
+ border: none; border-radius: 4px; cursor: pointer;
20067
+ font-size: 12px; color: ${colors.text};
20068
+ ">Limpar Sele\xE7\xE3o</button>
20069
+ </div>
20070
+ </div>
20071
+ </div>
20072
+ <!-- Date Range Picker -->
20073
+ <div style="flex: 1; min-width: 220px;">
20074
+ <label style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500; display: block; margin-bottom: 4px;">
20075
+ Per\xEDodo
20076
+ </label>
20077
+ <input type="text" id="${modalId}-date-range" readonly placeholder="Selecione o per\xEDodo..." style="
20078
+ padding: 8px 12px; border: 1px solid ${colors.border}; border-radius: 6px;
20079
+ font-size: 14px; color: ${colors.text}; background: ${colors.surface};
20080
+ width: 100%; cursor: pointer; box-sizing: border-box;
20081
+ "/>
20082
+ </div>
20083
+ <!-- Query Button -->
20084
+ <button id="${modalId}-query" style="
20085
+ background: #3e1a7d; color: white; border: none;
20086
+ padding: 8px 16px; border-radius: 6px; cursor: pointer;
20087
+ font-size: 14px; font-weight: 500; height: 38px;
20088
+ display: flex; align-items: center; gap: 8px;
20089
+ font-family: 'Roboto', Arial, sans-serif;
20090
+ " ${state.isLoading ? "disabled" : ""}>
20091
+ ${state.isLoading ? '<span style="animation: spin 1s linear infinite; display: inline-block;">\u21BB</span> Carregando...' : "Carregar"}
20092
+ </button>
20093
+ </div>
20094
+
20095
+ <!-- Stats Cards -->
20096
+ <div style="
20097
+ display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
20098
+ gap: 12px; margin-bottom: 16px;
20099
+ ">
20100
+ <!-- Current Temperature -->
20101
+ <div style="
20102
+ padding: 16px; background: ${state.theme === "dark" ? "rgba(255,255,255,0.05)" : "#fafafa"};
20103
+ border-radius: 12px; border: 1px solid ${colors.border};
20104
+ ">
20105
+ <span style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500;">Temperatura Atual</span>
20106
+ <div style="font-weight: 700; font-size: 24px; color: ${statusColor}; margin-top: 4px;">
20107
+ ${state.currentTemperature !== null ? formatTemperature(state.currentTemperature) : "N/A"}
20108
+ </div>
20109
+ <div style="font-size: 11px; color: ${statusColor}; margin-top: 2px;">${statusText}</div>
20110
+ </div>
20111
+ <!-- Average -->
20112
+ <div style="
20113
+ padding: 16px; background: ${state.theme === "dark" ? "rgba(255,255,255,0.05)" : "#fafafa"};
20114
+ border-radius: 12px; border: 1px solid ${colors.border};
20115
+ ">
20116
+ <span style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500;">M\xE9dia do Per\xEDodo</span>
20117
+ <div id="${modalId}-avg" style="font-weight: 600; font-size: 20px; color: ${colors.text}; margin-top: 4px;">
20118
+ ${state.stats.count > 0 ? formatTemperature(state.stats.avg) : "N/A"}
20119
+ </div>
20120
+ <div style="font-size: 11px; color: ${colors.textMuted}; margin-top: 2px;">${startDateStr} - ${endDateStr}</div>
20121
+ </div>
20122
+ <!-- Min/Max -->
20123
+ <div style="
20124
+ padding: 16px; background: ${state.theme === "dark" ? "rgba(255,255,255,0.05)" : "#fafafa"};
20125
+ border-radius: 12px; border: 1px solid ${colors.border};
20126
+ ">
20127
+ <span style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500;">Min / Max</span>
20128
+ <div id="${modalId}-minmax" style="font-weight: 600; font-size: 20px; color: ${colors.text}; margin-top: 4px;">
20129
+ ${state.stats.count > 0 ? `${formatTemperature(state.stats.min)} / ${formatTemperature(state.stats.max)}` : "N/A"}
20130
+ </div>
20131
+ <div style="font-size: 11px; color: ${colors.textMuted}; margin-top: 2px;">${state.stats.count} leituras</div>
20132
+ </div>
20133
+ <!-- Ideal Range -->
20134
+ <div style="
20135
+ padding: 16px; background: ${state.theme === "dark" ? "rgba(255,255,255,0.05)" : "#fafafa"};
20136
+ border-radius: 12px; border: 1px solid ${colors.border};
20137
+ ">
20138
+ <span style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500;">Faixa Ideal</span>
20139
+ <div style="font-weight: 600; font-size: 20px; color: ${colors.success}; margin-top: 4px;">
20140
+ ${rangeText}
20141
+ </div>
20142
+ </div>
20143
+ </div>
20144
+
20145
+ <!-- Chart Container -->
20146
+ <div style="margin-bottom: 20px;">
20147
+ <h3 style="margin: 0 0 12px 0; font-size: 14px; color: ${colors.textMuted}; font-weight: 500;">
20148
+ Hist\xF3rico de Temperatura
20149
+ </h3>
20150
+ <div id="${modalId}-chart" style="
20151
+ height: 320px; background: ${state.theme === "dark" ? "rgba(255,255,255,0.03)" : "#fafafa"};
20152
+ border-radius: 12px; display: flex; justify-content: center; align-items: center;
20153
+ border: 1px solid ${colors.border}; position: relative;
20154
+ ">
20155
+ ${state.isLoading ? `<div style="text-align: center; color: ${colors.textMuted};">
20156
+ <div style="animation: spin 1s linear infinite; font-size: 32px; margin-bottom: 8px;">\u21BB</div>
20157
+ <div>Carregando dados...</div>
20158
+ </div>` : error ? `<div style="text-align: center; color: ${colors.danger};">
20159
+ <div style="font-size: 32px; margin-bottom: 8px;">\u26A0\uFE0F</div>
20160
+ <div>Erro ao carregar dados</div>
20161
+ <div style="font-size: 12px; margin-top: 4px;">${error.message}</div>
20162
+ </div>` : state.data.length === 0 ? `<div style="text-align: center; color: ${colors.textMuted};">
20163
+ <div style="font-size: 32px; margin-bottom: 8px;">\u{1F4ED}</div>
20164
+ <div>Sem dados para o per\xEDodo selecionado</div>
20165
+ </div>` : `<canvas id="${modalId}-canvas" style="width: 100%; height: 100%;"></canvas>`}
20166
+ </div>
20167
+ </div>
20168
+
20169
+ <!-- Actions -->
20170
+ <div style="display: flex; justify-content: flex-end; gap: 12px;">
20171
+ <button id="${modalId}-export" style="
20172
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.1)" : "#f7f7f7"};
20173
+ color: ${colors.text}; border: 1px solid ${colors.border};
20174
+ padding: 8px 16px; border-radius: 6px; cursor: pointer;
20175
+ font-size: 14px; display: flex; align-items: center; gap: 8px;
20176
+ font-family: 'Roboto', Arial, sans-serif;
20177
+ " ${state.data.length === 0 ? "disabled" : ""}>
20178
+ \u{1F4E5} Exportar CSV
20179
+ </button>
20180
+ <button id="${modalId}-close-btn" style="
20181
+ background: #3e1a7d; color: white; border: none;
20182
+ padding: 8px 16px; border-radius: 6px; cursor: pointer;
20183
+ font-size: 14px; font-weight: 500;
20184
+ font-family: 'Roboto', Arial, sans-serif;
20185
+ ">
20186
+ Fechar
20187
+ </button>
20188
+ </div>
20189
+ </div><!-- End Body -->
20190
+ </div>
20191
+ </div>
20192
+ <style>
20193
+ @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
20194
+ #${modalId} select:focus, #${modalId} input:focus {
20195
+ outline: 2px solid #3e1a7d;
20196
+ outline-offset: 2px;
20197
+ }
20198
+ #${modalId} button:hover:not(:disabled) {
20199
+ opacity: 0.9;
20200
+ }
20201
+ #${modalId} button:disabled {
20202
+ opacity: 0.5;
20203
+ cursor: not-allowed;
20204
+ }
20205
+ #${modalId} .myio-temp-modal-content > div:first-child button:hover {
20206
+ background: rgba(255, 255, 255, 0.1) !important;
20207
+ color: white !important;
20208
+ }
20209
+ </style>
20210
+ `;
20211
+ }
20212
+ function drawChart(modalId, state) {
20213
+ const chartContainer = document.getElementById(`${modalId}-chart`);
20214
+ const canvas = document.getElementById(`${modalId}-canvas`);
20215
+ if (!chartContainer || !canvas || state.data.length === 0) return;
20216
+ const ctx = canvas.getContext("2d");
20217
+ if (!ctx) return;
20218
+ const colors = getThemeColors(state.theme);
20219
+ const filteredData = filterByDayPeriods(state.data, state.selectedPeriods);
20220
+ if (filteredData.length === 0) {
20221
+ canvas.width = chartContainer.clientWidth;
20222
+ canvas.height = chartContainer.clientHeight;
20223
+ ctx.fillStyle = colors.textMuted;
20224
+ ctx.font = "14px Roboto, Arial, sans-serif";
20225
+ ctx.textAlign = "center";
20226
+ ctx.fillText("Nenhum dado para os per\xEDodos selecionados", canvas.width / 2, canvas.height / 2);
20227
+ return;
20228
+ }
20229
+ let chartData;
20230
+ if (state.granularity === "hour") {
20231
+ const interpolated = interpolateTemperature(filteredData, {
20232
+ intervalMinutes: 30,
20233
+ startTs: state.startTs,
20234
+ endTs: state.endTs,
20235
+ clampRange: state.clampRange
20236
+ });
20237
+ const filteredInterpolated = filterByDayPeriods(interpolated, state.selectedPeriods);
20238
+ chartData = filteredInterpolated.map((item) => ({
20239
+ x: item.ts,
20240
+ y: Number(item.value),
20241
+ screenX: 0,
20242
+ screenY: 0
20243
+ }));
20244
+ } else {
20245
+ const daily = aggregateByDay(filteredData, state.clampRange);
20246
+ chartData = daily.map((item) => ({
20247
+ x: item.dateTs,
20248
+ y: item.avg,
20249
+ screenX: 0,
20250
+ screenY: 0,
20251
+ label: item.date
20252
+ }));
20253
+ }
20254
+ if (chartData.length === 0) return;
20255
+ const width = chartContainer.clientWidth - 2;
20256
+ const height = 320;
20257
+ canvas.width = width;
20258
+ canvas.height = height;
20259
+ const paddingLeft = 60;
20260
+ const paddingRight = 20;
20261
+ const paddingTop = 20;
20262
+ const paddingBottom = 55;
20263
+ const isPeriodsFiltered = state.selectedPeriods.length < 4 && state.selectedPeriods.length > 0;
20264
+ const values = chartData.map((d) => d.y);
20265
+ const dataMin = Math.min(...values);
20266
+ const dataMax = Math.max(...values);
20267
+ const thresholdMin = state.temperatureMin !== null ? state.temperatureMin : dataMin;
20268
+ const thresholdMax = state.temperatureMax !== null ? state.temperatureMax : dataMax;
20269
+ const minY = Math.min(dataMin, thresholdMin) - 1;
20270
+ const maxY = Math.max(dataMax, thresholdMax) + 1;
20271
+ const chartWidth = width - paddingLeft - paddingRight;
20272
+ const chartHeight = height - paddingTop - paddingBottom;
20273
+ const scaleY = chartHeight / (maxY - minY || 1);
20274
+ if (isPeriodsFiltered) {
20275
+ const pointSpacing = chartWidth / Math.max(1, chartData.length - 1);
20276
+ chartData.forEach((point, index) => {
20277
+ point.screenX = paddingLeft + index * pointSpacing;
20278
+ point.screenY = height - paddingBottom - (point.y - minY) * scaleY;
20279
+ });
20280
+ } else {
20281
+ const minX = chartData[0].x;
20282
+ const maxX = chartData[chartData.length - 1].x;
20283
+ const timeRange = maxX - minX || 1;
20284
+ const scaleX = chartWidth / timeRange;
20285
+ chartData.forEach((point) => {
20286
+ point.screenX = paddingLeft + (point.x - minX) * scaleX;
20287
+ point.screenY = height - paddingBottom - (point.y - minY) * scaleY;
20288
+ });
20289
+ }
20290
+ ctx.clearRect(0, 0, width, height);
20291
+ ctx.strokeStyle = colors.chartGrid;
20292
+ ctx.lineWidth = 1;
20293
+ for (let i = 0; i <= 4; i++) {
20294
+ const y = paddingTop + chartHeight * i / 4;
20295
+ ctx.beginPath();
20296
+ ctx.moveTo(paddingLeft, y);
20297
+ ctx.lineTo(width - paddingRight, y);
20298
+ ctx.stroke();
20299
+ }
20300
+ if (state.temperatureMin !== null && state.temperatureMax !== null) {
20301
+ const rangeMinY = height - paddingBottom - (state.temperatureMin - minY) * scaleY;
20302
+ const rangeMaxY = height - paddingBottom - (state.temperatureMax - minY) * scaleY;
20303
+ ctx.fillStyle = "rgba(76, 175, 80, 0.1)";
20304
+ ctx.fillRect(paddingLeft, rangeMaxY, chartWidth, rangeMinY - rangeMaxY);
20305
+ ctx.strokeStyle = colors.success;
20306
+ ctx.setLineDash([5, 5]);
20307
+ ctx.beginPath();
20308
+ ctx.moveTo(paddingLeft, rangeMinY);
20309
+ ctx.lineTo(width - paddingRight, rangeMinY);
20310
+ ctx.moveTo(paddingLeft, rangeMaxY);
20311
+ ctx.lineTo(width - paddingRight, rangeMaxY);
20312
+ ctx.stroke();
20313
+ ctx.setLineDash([]);
20314
+ }
20315
+ ctx.strokeStyle = colors.chartLine;
20316
+ ctx.lineWidth = 2;
20317
+ ctx.beginPath();
20318
+ chartData.forEach((point, i) => {
20319
+ if (i === 0) ctx.moveTo(point.screenX, point.screenY);
20320
+ else ctx.lineTo(point.screenX, point.screenY);
20321
+ });
20322
+ ctx.stroke();
20323
+ ctx.fillStyle = colors.chartLine;
20324
+ chartData.forEach((point) => {
20325
+ ctx.beginPath();
20326
+ ctx.arc(point.screenX, point.screenY, 4, 0, Math.PI * 2);
20327
+ ctx.fill();
20328
+ });
20329
+ ctx.fillStyle = colors.textMuted;
20330
+ ctx.font = "11px system-ui, sans-serif";
20331
+ ctx.textAlign = "right";
20332
+ for (let i = 0; i <= 4; i++) {
20333
+ const val = minY + (maxY - minY) * (4 - i) / 4;
20334
+ const y = paddingTop + chartHeight * i / 4;
20335
+ ctx.fillText(val.toFixed(1) + "\xB0C", paddingLeft - 8, y + 4);
20336
+ }
20337
+ ctx.textAlign = "center";
20338
+ const numLabels = Math.min(8, chartData.length);
20339
+ const labelInterval = Math.max(1, Math.floor(chartData.length / numLabels));
20340
+ for (let i = 0; i < chartData.length; i += labelInterval) {
20341
+ const point = chartData[i];
20342
+ const date = new Date(point.x);
20343
+ let label;
20344
+ if (state.granularity === "hour") {
20345
+ label = date.toLocaleTimeString(state.locale, { hour: "2-digit", minute: "2-digit" });
20346
+ } else {
20347
+ label = date.toLocaleDateString(state.locale, { day: "2-digit", month: "2-digit" });
20348
+ }
20349
+ ctx.strokeStyle = colors.chartGrid;
20350
+ ctx.lineWidth = 1;
20351
+ ctx.beginPath();
20352
+ ctx.moveTo(point.screenX, paddingTop);
20353
+ ctx.lineTo(point.screenX, height - paddingBottom);
20354
+ ctx.stroke();
20355
+ ctx.fillStyle = colors.textMuted;
20356
+ ctx.fillText(label, point.screenX, height - paddingBottom + 18);
20357
+ }
20358
+ ctx.strokeStyle = colors.border;
20359
+ ctx.lineWidth = 1;
20360
+ ctx.beginPath();
20361
+ ctx.moveTo(paddingLeft, paddingTop);
20362
+ ctx.lineTo(paddingLeft, height - paddingBottom);
20363
+ ctx.lineTo(width - paddingRight, height - paddingBottom);
20364
+ ctx.stroke();
20365
+ setupChartTooltip(canvas, chartContainer, chartData, state, colors);
20366
+ }
20367
+ function setupChartTooltip(canvas, container, chartData, state, colors) {
20368
+ const existingTooltip = container.querySelector(".myio-chart-tooltip");
20369
+ if (existingTooltip) existingTooltip.remove();
20370
+ const tooltip = document.createElement("div");
20371
+ tooltip.className = "myio-chart-tooltip";
20372
+ tooltip.style.cssText = `
20373
+ position: absolute;
20374
+ background: ${state.theme === "dark" ? "rgba(30, 30, 40, 0.95)" : "rgba(255, 255, 255, 0.98)"};
20375
+ border: 1px solid ${colors.border};
20376
+ border-radius: 8px;
20377
+ padding: 10px 14px;
20378
+ font-size: 13px;
20379
+ color: ${colors.text};
20380
+ pointer-events: none;
20381
+ opacity: 0;
20382
+ transition: opacity 0.15s;
20383
+ z-index: 1000;
20384
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
20385
+ min-width: 140px;
20386
+ `;
20387
+ container.appendChild(tooltip);
20388
+ const findNearestPoint = (mouseX, mouseY) => {
20389
+ const threshold = 20;
20390
+ let nearest = null;
20391
+ let minDist = Infinity;
20392
+ for (const point of chartData) {
20393
+ const dist = Math.sqrt(
20394
+ Math.pow(mouseX - point.screenX, 2) + Math.pow(mouseY - point.screenY, 2)
20395
+ );
20396
+ if (dist < minDist && dist < threshold) {
20397
+ minDist = dist;
20398
+ nearest = point;
20399
+ }
20400
+ }
20401
+ return nearest;
20402
+ };
20403
+ canvas.addEventListener("mousemove", (e) => {
20404
+ const rect = canvas.getBoundingClientRect();
20405
+ const mouseX = e.clientX - rect.left;
20406
+ const mouseY = e.clientY - rect.top;
20407
+ const point = findNearestPoint(mouseX, mouseY);
20408
+ if (point) {
20409
+ const date = new Date(point.x);
20410
+ let dateStr;
20411
+ if (state.granularity === "hour") {
20412
+ dateStr = date.toLocaleDateString(state.locale, {
20413
+ day: "2-digit",
20414
+ month: "2-digit",
20415
+ year: "numeric"
20416
+ }) + " " + date.toLocaleTimeString(state.locale, {
20417
+ hour: "2-digit",
20418
+ minute: "2-digit"
20419
+ });
20420
+ } else {
20421
+ dateStr = date.toLocaleDateString(state.locale, {
20422
+ day: "2-digit",
20423
+ month: "2-digit",
20424
+ year: "numeric"
20425
+ });
20426
+ }
20427
+ tooltip.innerHTML = `
20428
+ <div style="font-weight: 600; margin-bottom: 6px; color: ${colors.primary};">
20429
+ ${formatTemperature(point.y)}
20430
+ </div>
20431
+ <div style="font-size: 11px; color: ${colors.textMuted};">
20432
+ \u{1F4C5} ${dateStr}
20433
+ </div>
20434
+ `;
20435
+ let tooltipX = point.screenX + 15;
20436
+ let tooltipY = point.screenY - 15;
20437
+ const tooltipRect = tooltip.getBoundingClientRect();
20438
+ const containerRect = container.getBoundingClientRect();
20439
+ if (tooltipX + tooltipRect.width > containerRect.width - 10) {
20440
+ tooltipX = point.screenX - tooltipRect.width - 15;
20441
+ }
20442
+ if (tooltipY < 10) {
20443
+ tooltipY = point.screenY + 15;
20444
+ }
20445
+ tooltip.style.left = `${tooltipX}px`;
20446
+ tooltip.style.top = `${tooltipY}px`;
20447
+ tooltip.style.opacity = "1";
20448
+ canvas.style.cursor = "pointer";
20449
+ } else {
20450
+ tooltip.style.opacity = "0";
20451
+ canvas.style.cursor = "default";
20452
+ }
20453
+ });
20454
+ canvas.addEventListener("mouseleave", () => {
20455
+ tooltip.style.opacity = "0";
20456
+ canvas.style.cursor = "default";
20457
+ });
20458
+ }
20459
+ async function setupEventListeners(container, state, modalId, onClose) {
20460
+ const closeModal = () => {
20461
+ container.remove();
20462
+ onClose?.();
20463
+ };
20464
+ container.querySelector(".myio-temp-modal-overlay")?.addEventListener("click", (e) => {
20465
+ if (e.target === e.currentTarget) closeModal();
20466
+ });
20467
+ document.getElementById(`${modalId}-close`)?.addEventListener("click", closeModal);
20468
+ document.getElementById(`${modalId}-close-btn`)?.addEventListener("click", closeModal);
20469
+ const dateRangeInput = document.getElementById(`${modalId}-date-range`);
20470
+ if (dateRangeInput && !state.dateRangePicker) {
20471
+ try {
20472
+ state.dateRangePicker = await createDateRangePicker2(dateRangeInput, {
20473
+ presetStart: new Date(state.startTs).toISOString(),
20474
+ presetEnd: new Date(state.endTs).toISOString(),
20475
+ includeTime: true,
20476
+ timePrecision: "minute",
20477
+ maxRangeDays: 90,
20478
+ locale: state.locale,
20479
+ parentEl: container.querySelector(".myio-temp-modal-content"),
20480
+ onApply: (result) => {
20481
+ state.startTs = new Date(result.startISO).getTime();
20482
+ state.endTs = new Date(result.endISO).getTime();
20483
+ console.log("[TemperatureModal] Date range applied:", result);
20484
+ }
20485
+ });
20486
+ } catch (error) {
20487
+ console.warn("[TemperatureModal] DateRangePicker initialization failed:", error);
20488
+ }
20489
+ }
20490
+ document.getElementById(`${modalId}-theme-toggle`)?.addEventListener("click", async () => {
20491
+ state.theme = state.theme === "dark" ? "light" : "dark";
20492
+ localStorage.setItem("myio-temp-modal-theme", state.theme);
20493
+ state.dateRangePicker = null;
20494
+ renderModal(container, state, modalId);
20495
+ if (state.data.length > 0) drawChart(modalId, state);
20496
+ await setupEventListeners(container, state, modalId, onClose);
20497
+ });
20498
+ document.getElementById(`${modalId}-maximize`)?.addEventListener("click", async () => {
20499
+ container.__isMaximized = !container.__isMaximized;
20500
+ state.dateRangePicker = null;
20501
+ renderModal(container, state, modalId);
20502
+ if (state.data.length > 0) drawChart(modalId, state);
20503
+ await setupEventListeners(container, state, modalId, onClose);
20504
+ });
20505
+ const periodBtn = document.getElementById(`${modalId}-period-btn`);
20506
+ const periodDropdown = document.getElementById(`${modalId}-period-dropdown`);
20507
+ periodBtn?.addEventListener("click", (e) => {
20508
+ e.stopPropagation();
20509
+ if (periodDropdown) {
20510
+ periodDropdown.style.display = periodDropdown.style.display === "none" ? "block" : "none";
20511
+ }
20512
+ });
20513
+ document.addEventListener("click", (e) => {
20514
+ if (periodDropdown && !periodDropdown.contains(e.target) && e.target !== periodBtn) {
20515
+ periodDropdown.style.display = "none";
20516
+ }
20517
+ });
20518
+ const periodCheckboxes = document.querySelectorAll(`input[name="${modalId}-period"]`);
20519
+ periodCheckboxes.forEach((checkbox) => {
20520
+ checkbox.addEventListener("change", () => {
20521
+ const checked = Array.from(periodCheckboxes).filter((cb) => cb.checked).map((cb) => cb.value);
20522
+ state.selectedPeriods = checked;
20523
+ const btnLabel = periodBtn?.querySelector("span:first-child");
20524
+ if (btnLabel) {
20525
+ btnLabel.textContent = getSelectedPeriodsLabel(state.selectedPeriods);
20526
+ }
20527
+ if (state.data.length > 0) drawChart(modalId, state);
20528
+ });
20529
+ });
20530
+ document.getElementById(`${modalId}-period-select-all`)?.addEventListener("click", () => {
20531
+ periodCheckboxes.forEach((cb) => {
20532
+ cb.checked = true;
20533
+ });
20534
+ state.selectedPeriods = ["madrugada", "manha", "tarde", "noite"];
20535
+ const btnLabel = periodBtn?.querySelector("span:first-child");
20536
+ if (btnLabel) {
20537
+ btnLabel.textContent = getSelectedPeriodsLabel(state.selectedPeriods);
20538
+ }
20539
+ if (state.data.length > 0) drawChart(modalId, state);
20540
+ });
20541
+ document.getElementById(`${modalId}-period-clear`)?.addEventListener("click", () => {
20542
+ periodCheckboxes.forEach((cb) => {
20543
+ cb.checked = false;
20544
+ });
20545
+ state.selectedPeriods = [];
20546
+ const btnLabel = periodBtn?.querySelector("span:first-child");
20547
+ if (btnLabel) {
20548
+ btnLabel.textContent = getSelectedPeriodsLabel(state.selectedPeriods);
20549
+ }
20550
+ if (state.data.length > 0) drawChart(modalId, state);
20551
+ });
20552
+ document.getElementById(`${modalId}-granularity`)?.addEventListener("change", (e) => {
20553
+ state.granularity = e.target.value;
20554
+ localStorage.setItem("myio-temp-modal-granularity", state.granularity);
20555
+ if (state.data.length > 0) drawChart(modalId, state);
20556
+ });
20557
+ document.getElementById(`${modalId}-query`)?.addEventListener("click", async () => {
20558
+ if (state.startTs >= state.endTs) {
20559
+ alert("Por favor, selecione um per\xEDodo v\xE1lido");
20560
+ return;
20561
+ }
20562
+ state.isLoading = true;
20563
+ state.dateRangePicker = null;
20564
+ renderModal(container, state, modalId);
20565
+ try {
20566
+ state.data = await fetchTemperatureData(state.token, state.deviceId, state.startTs, state.endTs);
20567
+ state.stats = calculateStats(state.data, state.clampRange);
20568
+ state.isLoading = false;
20569
+ renderModal(container, state, modalId);
20570
+ drawChart(modalId, state);
20571
+ await setupEventListeners(container, state, modalId, onClose);
20572
+ } catch (error) {
20573
+ console.error("[TemperatureModal] Error fetching data:", error);
20574
+ state.isLoading = false;
20575
+ renderModal(container, state, modalId, error);
20576
+ await setupEventListeners(container, state, modalId, onClose);
20577
+ }
20578
+ });
20579
+ document.getElementById(`${modalId}-export`)?.addEventListener("click", () => {
20580
+ if (state.data.length === 0) return;
20581
+ const startDateStr = new Date(state.startTs).toLocaleDateString(state.locale).replace(/\//g, "-");
20582
+ const endDateStr = new Date(state.endTs).toLocaleDateString(state.locale).replace(/\//g, "-");
20583
+ exportTemperatureCSV(
20584
+ state.data,
20585
+ state.label,
20586
+ state.stats,
20587
+ startDateStr,
20588
+ endDateStr
20589
+ );
20590
+ });
20591
+ }
20592
+
20593
+ // src/components/temperature/TemperatureComparisonModal.ts
20594
+ async function openTemperatureComparisonModal(params) {
20595
+ const modalId = `myio-temp-comparison-modal-${Date.now()}`;
20596
+ const defaultDateRange = getTodaySoFar();
20597
+ const startTs = params.startDate ? new Date(params.startDate).getTime() : defaultDateRange.startTs;
20598
+ const endTs = params.endDate ? new Date(params.endDate).getTime() : defaultDateRange.endTs;
20599
+ const state = {
20600
+ token: params.token,
20601
+ devices: params.devices,
20602
+ startTs,
20603
+ endTs,
20604
+ granularity: params.granularity || "hour",
20605
+ theme: params.theme || "dark",
20606
+ clampRange: params.clampRange || DEFAULT_CLAMP_RANGE,
20607
+ locale: params.locale || "pt-BR",
20608
+ deviceData: [],
20609
+ isLoading: true,
20610
+ dateRangePicker: null,
20611
+ selectedPeriods: ["madrugada", "manha", "tarde", "noite"],
20612
+ // All periods selected by default
20613
+ temperatureMin: params.temperatureMin ?? null,
20614
+ temperatureMax: params.temperatureMax ?? null
20615
+ };
20616
+ const savedGranularity = localStorage.getItem("myio-temp-comparison-granularity");
20617
+ const savedTheme = localStorage.getItem("myio-temp-comparison-theme");
20618
+ if (savedGranularity) state.granularity = savedGranularity;
20619
+ if (savedTheme) state.theme = savedTheme;
20620
+ const modalContainer = document.createElement("div");
20621
+ modalContainer.id = modalId;
20622
+ document.body.appendChild(modalContainer);
20623
+ renderModal2(modalContainer, state, modalId);
20624
+ await fetchAllDevicesData(state);
20625
+ renderModal2(modalContainer, state, modalId);
20626
+ drawComparisonChart(modalId, state);
20627
+ await setupEventListeners2(modalContainer, state, modalId, params.onClose);
20628
+ return {
20629
+ destroy: () => {
20630
+ modalContainer.remove();
20631
+ params.onClose?.();
20632
+ },
20633
+ updateData: async (startDate, endDate, granularity) => {
20634
+ state.startTs = new Date(startDate).getTime();
20635
+ state.endTs = new Date(endDate).getTime();
20636
+ if (granularity) state.granularity = granularity;
20637
+ state.isLoading = true;
20638
+ renderModal2(modalContainer, state, modalId);
20639
+ await fetchAllDevicesData(state);
20640
+ renderModal2(modalContainer, state, modalId);
20641
+ drawComparisonChart(modalId, state);
20642
+ setupEventListeners2(modalContainer, state, modalId, params.onClose);
20643
+ }
20644
+ };
20645
+ }
20646
+ async function fetchAllDevicesData(state) {
20647
+ state.isLoading = true;
20648
+ state.deviceData = [];
20649
+ try {
20650
+ const results = await Promise.all(
20651
+ state.devices.map(async (device, index) => {
20652
+ const deviceId = device.tbId || device.id;
20653
+ try {
20654
+ const data = await fetchTemperatureData(state.token, deviceId, state.startTs, state.endTs);
20655
+ const stats = calculateStats(data, state.clampRange);
20656
+ return {
20657
+ device,
20658
+ data,
20659
+ stats,
20660
+ color: CHART_COLORS[index % CHART_COLORS.length]
20661
+ };
20662
+ } catch (error) {
20663
+ console.error(`[TemperatureComparisonModal] Error fetching data for ${device.label}:`, error);
20664
+ return {
20665
+ device,
20666
+ data: [],
20667
+ stats: { avg: 0, min: 0, max: 0, count: 0 },
20668
+ color: CHART_COLORS[index % CHART_COLORS.length]
20669
+ };
20670
+ }
20671
+ })
20672
+ );
20673
+ state.deviceData = results;
20674
+ } catch (error) {
20675
+ console.error("[TemperatureComparisonModal] Error fetching data:", error);
20676
+ }
20677
+ state.isLoading = false;
20678
+ }
20679
+ function renderModal2(container, state, modalId) {
20680
+ const colors = getThemeColors(state.theme);
20681
+ const startDateStr = new Date(state.startTs).toLocaleDateString(state.locale);
20682
+ const endDateStr = new Date(state.endTs).toLocaleDateString(state.locale);
20683
+ const startDateInput = new Date(state.startTs).toISOString().slice(0, 16);
20684
+ const endDateInput = new Date(state.endTs).toISOString().slice(0, 16);
20685
+ const legendHTML = state.deviceData.map((dd) => `
20686
+ <div style="display: flex; align-items: center; gap: 8px; padding: 8px 12px;
20687
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.05)" : "rgba(0,0,0,0.03)"};
20688
+ border-radius: 8px;">
20689
+ <span style="width: 12px; height: 12px; border-radius: 50%; background: ${dd.color};"></span>
20690
+ <span style="color: ${colors.text}; font-size: 13px;">${dd.device.label}</span>
20691
+ <span style="color: ${colors.textMuted}; font-size: 11px; margin-left: auto;">
20692
+ ${dd.stats.count > 0 ? formatTemperature(dd.stats.avg) : "N/A"}
20693
+ </span>
20694
+ </div>
20695
+ `).join("");
20696
+ const statsHTML = state.deviceData.map((dd) => `
20697
+ <div style="
20698
+ padding: 12px; background: ${state.theme === "dark" ? "rgba(255,255,255,0.05)" : "#fafafa"};
20699
+ border-radius: 10px; border-left: 4px solid ${dd.color};
20700
+ min-width: 150px;
20701
+ ">
20702
+ <div style="font-weight: 600; color: ${colors.text}; font-size: 13px; margin-bottom: 8px;">
20703
+ ${dd.device.label}
20704
+ </div>
20705
+ <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 4px; font-size: 11px;">
20706
+ <span style="color: ${colors.textMuted};">M\xE9dia:</span>
20707
+ <span style="color: ${colors.text}; font-weight: 500;">
20708
+ ${dd.stats.count > 0 ? formatTemperature(dd.stats.avg) : "N/A"}
20709
+ </span>
20710
+ <span style="color: ${colors.textMuted};">Min:</span>
20711
+ <span style="color: ${colors.text};">
20712
+ ${dd.stats.count > 0 ? formatTemperature(dd.stats.min) : "N/A"}
20713
+ </span>
20714
+ <span style="color: ${colors.textMuted};">Max:</span>
20715
+ <span style="color: ${colors.text};">
20716
+ ${dd.stats.count > 0 ? formatTemperature(dd.stats.max) : "N/A"}
20717
+ </span>
20718
+ <span style="color: ${colors.textMuted};">Leituras:</span>
20719
+ <span style="color: ${colors.text};">${dd.stats.count}</span>
20720
+ </div>
20721
+ </div>
20722
+ `).join("");
20723
+ const isMaximized = container.__isMaximized || false;
20724
+ const contentMaxWidth = isMaximized ? "100%" : "1100px";
20725
+ const contentMaxHeight = isMaximized ? "100vh" : "95vh";
20726
+ const contentBorderRadius = isMaximized ? "0" : "10px";
20727
+ container.innerHTML = `
20728
+ <div class="myio-temp-comparison-overlay" style="
20729
+ position: fixed; top: 0; left: 0; width: 100%; height: 100%;
20730
+ background: rgba(0, 0, 0, 0.5); z-index: 9998;
20731
+ display: flex; justify-content: center; align-items: center;
20732
+ backdrop-filter: blur(2px);
20733
+ ">
20734
+ <div class="myio-temp-comparison-content" style="
20735
+ background: ${colors.surface}; border-radius: ${contentBorderRadius};
20736
+ max-width: ${contentMaxWidth}; width: ${isMaximized ? "100%" : "95%"};
20737
+ max-height: ${contentMaxHeight}; height: ${isMaximized ? "100%" : "auto"};
20738
+ overflow: hidden; display: flex; flex-direction: column;
20739
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
20740
+ font-family: 'Roboto', Arial, sans-serif;
20741
+ ">
20742
+ <!-- Header - MyIO Premium Style -->
20743
+ <div style="
20744
+ padding: 4px 8px; display: flex; align-items: center; justify-content: space-between;
20745
+ background: #3e1a7d; color: white; border-radius: ${isMaximized ? "0" : "10px 10px 0 0"};
20746
+ min-height: 20px;
20747
+ ">
20748
+ <h2 style="margin: 6px; font-size: 18px; font-weight: 600; color: white; line-height: 2;">
20749
+ \u{1F321}\uFE0F Compara\xE7\xE3o de Temperatura - ${state.devices.length} sensores
20750
+ </h2>
20751
+ <div style="display: flex; gap: 4px; align-items: center;">
20752
+ <!-- Theme Toggle -->
20753
+ <button id="${modalId}-theme-toggle" title="Alternar tema" style="
20754
+ background: none; border: none; font-size: 16px; cursor: pointer;
20755
+ padding: 4px 8px; border-radius: 6px; color: rgba(255,255,255,0.8);
20756
+ transition: background-color 0.2s;
20757
+ ">${state.theme === "dark" ? "\u2600\uFE0F" : "\u{1F319}"}</button>
20758
+ <!-- Maximize Button -->
20759
+ <button id="${modalId}-maximize" title="${isMaximized ? "Restaurar" : "Maximizar"}" style="
20760
+ background: none; border: none; font-size: 16px; cursor: pointer;
20761
+ padding: 4px 8px; border-radius: 6px; color: rgba(255,255,255,0.8);
20762
+ transition: background-color 0.2s;
20763
+ ">${isMaximized ? "\u{1F5D7}" : "\u{1F5D6}"}</button>
20764
+ <!-- Close Button -->
20765
+ <button id="${modalId}-close" title="Fechar" style="
20766
+ background: none; border: none; font-size: 20px; cursor: pointer;
20767
+ padding: 4px 8px; border-radius: 6px; color: rgba(255,255,255,0.8);
20768
+ transition: background-color 0.2s;
20769
+ ">\xD7</button>
20770
+ </div>
20771
+ </div>
20772
+
20773
+ <!-- Body -->
20774
+ <div style="flex: 1; overflow-y: auto; padding: 16px;">
20775
+
20776
+ <!-- Controls Row -->
20777
+ <div style="
20778
+ display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
20779
+ margin-bottom: 16px; padding: 16px;
20780
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.05)" : "#f7f7f7"};
20781
+ border-radius: 6px; border: 1px solid ${colors.border};
20782
+ ">
20783
+ <!-- Granularity Select -->
20784
+ <div>
20785
+ <label style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500; display: block; margin-bottom: 4px;">
20786
+ Granularidade
20787
+ </label>
20788
+ <select id="${modalId}-granularity" style="
20789
+ padding: 8px 12px; border: 1px solid ${colors.border}; border-radius: 6px;
20790
+ font-size: 14px; color: ${colors.text}; background: ${colors.surface};
20791
+ cursor: pointer; min-width: 130px;
20792
+ ">
20793
+ <option value="hour" ${state.granularity === "hour" ? "selected" : ""}>Hora (30 min)</option>
20794
+ <option value="day" ${state.granularity === "day" ? "selected" : ""}>Dia (m\xE9dia)</option>
20795
+ </select>
20796
+ </div>
20797
+ <!-- Day Period Filter (Multiselect) -->
20798
+ <div style="position: relative;">
20799
+ <label style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500; display: block; margin-bottom: 4px;">
20800
+ Per\xEDodos do Dia
20801
+ </label>
20802
+ <button id="${modalId}-period-btn" type="button" style="
20803
+ padding: 8px 12px; border: 1px solid ${colors.border}; border-radius: 6px;
20804
+ font-size: 14px; color: ${colors.text}; background: ${colors.surface};
20805
+ cursor: pointer; min-width: 180px; text-align: left;
20806
+ display: flex; align-items: center; justify-content: space-between; gap: 8px;
20807
+ ">
20808
+ <span>${getSelectedPeriodsLabel(state.selectedPeriods)}</span>
20809
+ <span style="font-size: 10px;">\u25BC</span>
20810
+ </button>
20811
+ <div id="${modalId}-period-dropdown" style="
20812
+ display: none; position: absolute; top: 100%; left: 0; z-index: 1000;
20813
+ background: ${colors.surface}; border: 1px solid ${colors.border};
20814
+ border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
20815
+ min-width: 200px; margin-top: 4px; padding: 8px 0;
20816
+ ">
20817
+ ${DAY_PERIODS.map((period) => `
20818
+ <label style="
20819
+ display: flex; align-items: center; gap: 8px; padding: 8px 12px;
20820
+ cursor: pointer; font-size: 13px; color: ${colors.text};
20821
+ " onmouseover="this.style.background='${state.theme === "dark" ? "rgba(255,255,255,0.1)" : "#f0f0f0"}'"
20822
+ onmouseout="this.style.background='transparent'">
20823
+ <input type="checkbox"
20824
+ name="${modalId}-period"
20825
+ value="${period.id}"
20826
+ ${state.selectedPeriods.includes(period.id) ? "checked" : ""}
20827
+ style="width: 16px; height: 16px; cursor: pointer; accent-color: #3e1a7d;">
20828
+ ${period.label}
20829
+ </label>
20830
+ `).join("")}
20831
+ <div style="border-top: 1px solid ${colors.border}; margin-top: 8px; padding-top: 8px;">
20832
+ <button id="${modalId}-period-select-all" type="button" style="
20833
+ width: calc(100% - 16px); margin: 0 8px 4px; padding: 6px;
20834
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.1)" : "#f0f0f0"};
20835
+ border: none; border-radius: 4px; cursor: pointer;
20836
+ font-size: 12px; color: ${colors.text};
20837
+ ">Selecionar Todos</button>
20838
+ <button id="${modalId}-period-clear" type="button" style="
20839
+ width: calc(100% - 16px); margin: 0 8px; padding: 6px;
20840
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.1)" : "#f0f0f0"};
20841
+ border: none; border-radius: 4px; cursor: pointer;
20842
+ font-size: 12px; color: ${colors.text};
20843
+ ">Limpar Sele\xE7\xE3o</button>
20844
+ </div>
20845
+ </div>
20846
+ </div>
20847
+ <!-- Date Range Picker -->
20848
+ <div style="flex: 1; min-width: 220px;">
20849
+ <label style="color: ${colors.textMuted}; font-size: 12px; font-weight: 500; display: block; margin-bottom: 4px;">
20850
+ Per\xEDodo
20851
+ </label>
20852
+ <input type="text" id="${modalId}-date-range" readonly placeholder="Selecione o per\xEDodo..." style="
20853
+ padding: 8px 12px; border: 1px solid ${colors.border}; border-radius: 6px;
20854
+ font-size: 14px; color: ${colors.text}; background: ${colors.surface};
20855
+ width: 100%; cursor: pointer; box-sizing: border-box;
20856
+ "/>
20857
+ </div>
20858
+ <!-- Query Button -->
20859
+ <button id="${modalId}-query" style="
20860
+ background: #3e1a7d; color: white; border: none;
20861
+ padding: 8px 16px; border-radius: 6px; cursor: pointer;
20862
+ font-size: 14px; font-weight: 500; height: 38px;
20863
+ display: flex; align-items: center; gap: 8px;
20864
+ font-family: 'Roboto', Arial, sans-serif;
20865
+ " ${state.isLoading ? "disabled" : ""}>
20866
+ ${state.isLoading ? '<span style="animation: spin 1s linear infinite; display: inline-block;">\u21BB</span> Carregando...' : "Carregar"}
20867
+ </button>
20868
+ </div>
20869
+
20870
+ <!-- Legend -->
20871
+ <div style="
20872
+ display: flex; flex-wrap: wrap; gap: 10px;
20873
+ margin-bottom: 20px;
20874
+ ">
20875
+ ${legendHTML}
20876
+ </div>
20877
+
20878
+ <!-- Chart Container -->
20879
+ <div style="margin-bottom: 24px;">
20880
+ <div id="${modalId}-chart" style="
20881
+ height: 380px;
20882
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.03)" : "#fafafa"};
20883
+ border-radius: 14px; display: flex; justify-content: center; align-items: center;
20884
+ border: 1px solid ${colors.border}; position: relative;
20885
+ ">
20886
+ ${state.isLoading ? `<div style="text-align: center; color: ${colors.textMuted};">
20887
+ <div style="animation: spin 1s linear infinite; font-size: 36px; margin-bottom: 12px;">\u21BB</div>
20888
+ <div style="font-size: 15px;">Carregando dados de ${state.devices.length} sensores...</div>
20889
+ </div>` : state.deviceData.every((dd) => dd.data.length === 0) ? `<div style="text-align: center; color: ${colors.textMuted};">
20890
+ <div style="font-size: 48px; margin-bottom: 12px;">\u{1F4ED}</div>
20891
+ <div style="font-size: 16px;">Sem dados para o per\xEDodo selecionado</div>
20892
+ </div>` : `<canvas id="${modalId}-canvas" style="width: 100%; height: 100%;"></canvas>`}
20893
+ </div>
20894
+ </div>
20895
+
20896
+ <!-- Stats Cards -->
20897
+ <div style="
20898
+ display: flex; flex-wrap: wrap; gap: 12px;
20899
+ margin-bottom: 24px;
20900
+ ">
20901
+ ${statsHTML}
20902
+ </div>
20903
+
20904
+ <!-- Actions -->
20905
+ <div style="display: flex; justify-content: flex-end; gap: 12px;">
20906
+ <button id="${modalId}-export" style="
20907
+ background: ${state.theme === "dark" ? "rgba(255,255,255,0.1)" : "#f7f7f7"};
20908
+ color: ${colors.text}; border: 1px solid ${colors.border};
20909
+ padding: 8px 16px; border-radius: 6px; cursor: pointer;
20910
+ font-size: 14px; display: flex; align-items: center; gap: 8px;
20911
+ font-family: 'Roboto', Arial, sans-serif;
20912
+ " ${state.deviceData.every((dd) => dd.data.length === 0) ? "disabled" : ""}>
20913
+ \u{1F4E5} Exportar CSV
20914
+ </button>
20915
+ <button id="${modalId}-close-btn" style="
20916
+ background: #3e1a7d; color: white; border: none;
20917
+ padding: 8px 16px; border-radius: 6px; cursor: pointer;
20918
+ font-size: 14px; font-weight: 500;
20919
+ font-family: 'Roboto', Arial, sans-serif;
20920
+ ">
20921
+ Fechar
20922
+ </button>
20923
+ </div>
20924
+ </div><!-- End Body -->
20925
+ </div>
20926
+ </div>
20927
+ <style>
20928
+ @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
20929
+ #${modalId} select:focus, #${modalId} input:focus {
20930
+ outline: 2px solid #3e1a7d;
20931
+ outline-offset: 2px;
20932
+ }
20933
+ #${modalId} button:hover:not(:disabled) {
20934
+ opacity: 0.9;
20935
+ }
20936
+ #${modalId} button:disabled {
20937
+ opacity: 0.5;
20938
+ cursor: not-allowed;
20939
+ }
20940
+ #${modalId} .myio-temp-comparison-content > div:first-child button:hover {
20941
+ background: rgba(255, 255, 255, 0.1) !important;
20942
+ color: white !important;
20943
+ }
20944
+ </style>
20945
+ `;
20946
+ }
20947
+ function drawComparisonChart(modalId, state) {
20948
+ const chartContainer = document.getElementById(`${modalId}-chart`);
20949
+ const canvas = document.getElementById(`${modalId}-canvas`);
20950
+ if (!chartContainer || !canvas) return;
20951
+ const hasData = state.deviceData.some((dd) => dd.data.length > 0);
20952
+ if (!hasData) return;
20953
+ const ctx = canvas.getContext("2d");
20954
+ if (!ctx) return;
20955
+ const colors = getThemeColors(state.theme);
20956
+ const width = chartContainer.clientWidth - 2;
20957
+ const height = 380;
20958
+ canvas.width = width;
20959
+ canvas.height = height;
20960
+ const paddingLeft = 65;
20961
+ const paddingRight = 25;
20962
+ const paddingTop = 25;
20963
+ const paddingBottom = 55;
20964
+ ctx.clearRect(0, 0, width, height);
20965
+ const processedData = [];
20966
+ state.deviceData.forEach((dd) => {
20967
+ if (dd.data.length === 0) return;
20968
+ const filteredData = filterByDayPeriods(dd.data, state.selectedPeriods);
20969
+ if (filteredData.length === 0) return;
20970
+ let points;
20971
+ if (state.granularity === "hour") {
20972
+ const interpolated = interpolateTemperature(filteredData, {
20973
+ intervalMinutes: 30,
20974
+ startTs: state.startTs,
20975
+ endTs: state.endTs,
20976
+ clampRange: state.clampRange
20977
+ });
20978
+ const filteredInterpolated = filterByDayPeriods(interpolated, state.selectedPeriods);
20979
+ points = filteredInterpolated.map((item) => ({
20980
+ x: item.ts,
20981
+ y: Number(item.value),
20982
+ screenX: 0,
20983
+ screenY: 0,
20984
+ deviceLabel: dd.device.label,
20985
+ deviceColor: dd.color
20986
+ }));
20987
+ } else {
20988
+ const daily = aggregateByDay(filteredData, state.clampRange);
20989
+ points = daily.map((item) => ({
20990
+ x: item.dateTs,
20991
+ y: item.avg,
20992
+ screenX: 0,
20993
+ screenY: 0,
20994
+ deviceLabel: dd.device.label,
20995
+ deviceColor: dd.color
20996
+ }));
20997
+ }
20998
+ if (points.length > 0) {
20999
+ processedData.push({ device: dd, points });
21000
+ }
21001
+ });
21002
+ if (processedData.length === 0) {
21003
+ ctx.fillStyle = colors.textMuted;
21004
+ ctx.font = "14px Roboto, Arial, sans-serif";
21005
+ ctx.textAlign = "center";
21006
+ ctx.fillText("Nenhum dado para os per\xEDodos selecionados", width / 2, height / 2);
21007
+ return;
21008
+ }
21009
+ const isPeriodsFiltered = state.selectedPeriods.length < 4 && state.selectedPeriods.length > 0;
21010
+ let dataMinY = Infinity;
21011
+ let dataMaxY = -Infinity;
21012
+ processedData.forEach(({ points }) => {
21013
+ points.forEach((point) => {
21014
+ if (point.y < dataMinY) dataMinY = point.y;
21015
+ if (point.y > dataMaxY) dataMaxY = point.y;
21016
+ });
21017
+ });
21018
+ const rangeMap = /* @__PURE__ */ new Map();
21019
+ state.deviceData.forEach((dd, index) => {
21020
+ const device = dd.device;
21021
+ const min = device.temperatureMin;
21022
+ const max = device.temperatureMax;
21023
+ if (min !== void 0 && min !== null && max !== void 0 && max !== null) {
21024
+ const key = `${min}-${max}`;
21025
+ if (!rangeMap.has(key)) {
21026
+ rangeMap.set(key, {
21027
+ min,
21028
+ max,
21029
+ customerName: device.customerName || "",
21030
+ color: CHART_COLORS[index % CHART_COLORS.length],
21031
+ deviceLabels: [device.label]
21032
+ });
21033
+ } else {
21034
+ rangeMap.get(key).deviceLabels.push(device.label);
21035
+ }
21036
+ }
21037
+ });
21038
+ if (rangeMap.size === 0 && state.temperatureMin !== null && state.temperatureMax !== null) {
21039
+ rangeMap.set("global", {
21040
+ min: state.temperatureMin,
21041
+ max: state.temperatureMax,
21042
+ customerName: "Global",
21043
+ color: colors.success,
21044
+ deviceLabels: []
21045
+ });
21046
+ }
21047
+ const temperatureRanges = Array.from(rangeMap.values());
21048
+ let thresholdMinY = dataMinY;
21049
+ let thresholdMaxY = dataMaxY;
21050
+ temperatureRanges.forEach((range) => {
21051
+ if (range.min < thresholdMinY) thresholdMinY = range.min;
21052
+ if (range.max > thresholdMaxY) thresholdMaxY = range.max;
21053
+ });
21054
+ const globalMinY = Math.floor(Math.min(dataMinY, thresholdMinY)) - 1;
21055
+ const globalMaxY = Math.ceil(Math.max(dataMaxY, thresholdMaxY)) + 1;
21056
+ const chartWidth = width - paddingLeft - paddingRight;
21057
+ const chartHeight = height - paddingTop - paddingBottom;
21058
+ const scaleY = chartHeight / (globalMaxY - globalMinY || 1);
21059
+ if (isPeriodsFiltered) {
21060
+ const maxPoints = Math.max(...processedData.map(({ points }) => points.length));
21061
+ const pointSpacing = chartWidth / Math.max(1, maxPoints - 1);
21062
+ processedData.forEach(({ points }) => {
21063
+ points.forEach((point, index) => {
21064
+ point.screenX = paddingLeft + index * pointSpacing;
21065
+ point.screenY = height - paddingBottom - (point.y - globalMinY) * scaleY;
21066
+ });
21067
+ });
21068
+ } else {
21069
+ let globalMinX = Infinity;
21070
+ let globalMaxX = -Infinity;
21071
+ processedData.forEach(({ points }) => {
21072
+ points.forEach((point) => {
21073
+ if (point.x < globalMinX) globalMinX = point.x;
21074
+ if (point.x > globalMaxX) globalMaxX = point.x;
21075
+ });
21076
+ });
21077
+ const timeRange = globalMaxX - globalMinX || 1;
21078
+ const scaleX = chartWidth / timeRange;
21079
+ processedData.forEach(({ points }) => {
21080
+ points.forEach((point) => {
21081
+ point.screenX = paddingLeft + (point.x - globalMinX) * scaleX;
21082
+ point.screenY = height - paddingBottom - (point.y - globalMinY) * scaleY;
21083
+ });
21084
+ });
21085
+ }
21086
+ ctx.strokeStyle = colors.chartGrid;
21087
+ ctx.lineWidth = 1;
21088
+ for (let i = 0; i <= 5; i++) {
21089
+ const y = paddingTop + chartHeight * i / 5;
21090
+ ctx.beginPath();
21091
+ ctx.moveTo(paddingLeft, y);
21092
+ ctx.lineTo(width - paddingRight, y);
21093
+ ctx.stroke();
21094
+ }
21095
+ const rangeColors = [
21096
+ { fill: "rgba(76, 175, 80, 0.12)", stroke: "#4CAF50" },
21097
+ // Green
21098
+ { fill: "rgba(33, 150, 243, 0.12)", stroke: "#2196F3" },
21099
+ // Blue
21100
+ { fill: "rgba(255, 152, 0, 0.12)", stroke: "#FF9800" },
21101
+ // Orange
21102
+ { fill: "rgba(156, 39, 176, 0.12)", stroke: "#9C27B0" }
21103
+ // Purple
21104
+ ];
21105
+ temperatureRanges.forEach((range, index) => {
21106
+ const rangeMinY = height - paddingBottom - (range.min - globalMinY) * scaleY;
21107
+ const rangeMaxY = height - paddingBottom - (range.max - globalMinY) * scaleY;
21108
+ const colorSet = rangeColors[index % rangeColors.length];
21109
+ ctx.fillStyle = colorSet.fill;
21110
+ ctx.fillRect(paddingLeft, rangeMaxY, chartWidth, rangeMinY - rangeMaxY);
21111
+ ctx.strokeStyle = colorSet.stroke;
21112
+ ctx.lineWidth = 1.5;
21113
+ ctx.setLineDash([6, 4]);
21114
+ ctx.beginPath();
21115
+ ctx.moveTo(paddingLeft, rangeMinY);
21116
+ ctx.lineTo(width - paddingRight, rangeMinY);
21117
+ ctx.moveTo(paddingLeft, rangeMaxY);
21118
+ ctx.lineTo(width - paddingRight, rangeMaxY);
21119
+ ctx.stroke();
21120
+ ctx.setLineDash([]);
21121
+ if (temperatureRanges.length > 1 || range.customerName) {
21122
+ ctx.fillStyle = colorSet.stroke;
21123
+ ctx.font = "10px system-ui, sans-serif";
21124
+ ctx.textAlign = "left";
21125
+ const labelY = (rangeMinY + rangeMaxY) / 2;
21126
+ const labelText = range.customerName || `${range.min}\xB0-${range.max}\xB0C`;
21127
+ ctx.fillText(labelText, width - paddingRight + 5, labelY + 3);
21128
+ }
21129
+ });
21130
+ processedData.forEach(({ device, points }) => {
21131
+ ctx.strokeStyle = device.color;
21132
+ ctx.lineWidth = 2.5;
21133
+ ctx.beginPath();
21134
+ points.forEach((point, i) => {
21135
+ if (i === 0) ctx.moveTo(point.screenX, point.screenY);
21136
+ else ctx.lineTo(point.screenX, point.screenY);
21137
+ });
21138
+ ctx.stroke();
21139
+ ctx.fillStyle = device.color;
21140
+ points.forEach((point) => {
21141
+ ctx.beginPath();
21142
+ ctx.arc(point.screenX, point.screenY, 4, 0, Math.PI * 2);
21143
+ ctx.fill();
21144
+ });
21145
+ });
21146
+ ctx.fillStyle = colors.textMuted;
21147
+ ctx.font = "12px system-ui, sans-serif";
21148
+ ctx.textAlign = "right";
21149
+ for (let i = 0; i <= 5; i++) {
21150
+ const val = globalMinY + (globalMaxY - globalMinY) * (5 - i) / 5;
21151
+ const y = paddingTop + chartHeight * i / 5;
21152
+ ctx.fillText(val.toFixed(1) + "\xB0C", paddingLeft - 10, y + 4);
21153
+ }
21154
+ ctx.textAlign = "center";
21155
+ const xAxisPoints = processedData[0]?.points || [];
21156
+ const numLabels = Math.min(8, xAxisPoints.length);
21157
+ const labelInterval = Math.max(1, Math.floor(xAxisPoints.length / numLabels));
21158
+ for (let i = 0; i < xAxisPoints.length; i += labelInterval) {
21159
+ const point = xAxisPoints[i];
21160
+ const date = new Date(point.x);
21161
+ let label;
21162
+ if (state.granularity === "hour") {
21163
+ label = date.toLocaleTimeString(state.locale, { hour: "2-digit", minute: "2-digit" });
21164
+ } else {
21165
+ label = date.toLocaleDateString(state.locale, { day: "2-digit", month: "2-digit" });
21166
+ }
21167
+ ctx.strokeStyle = colors.chartGrid;
21168
+ ctx.lineWidth = 1;
21169
+ ctx.beginPath();
21170
+ ctx.moveTo(point.screenX, paddingTop);
21171
+ ctx.lineTo(point.screenX, height - paddingBottom);
21172
+ ctx.stroke();
21173
+ ctx.fillStyle = colors.textMuted;
21174
+ ctx.fillText(label, point.screenX, height - paddingBottom + 18);
21175
+ }
21176
+ ctx.strokeStyle = colors.border;
21177
+ ctx.lineWidth = 1;
21178
+ ctx.beginPath();
21179
+ ctx.moveTo(paddingLeft, paddingTop);
21180
+ ctx.lineTo(paddingLeft, height - paddingBottom);
21181
+ ctx.lineTo(width - paddingRight, height - paddingBottom);
21182
+ ctx.stroke();
21183
+ const allChartPoints = processedData.flatMap((pd) => pd.points);
21184
+ setupComparisonChartTooltip(canvas, chartContainer, allChartPoints, state, colors);
21185
+ }
21186
+ function setupComparisonChartTooltip(canvas, container, chartData, state, colors) {
21187
+ const existingTooltip = container.querySelector(".myio-chart-tooltip");
21188
+ if (existingTooltip) existingTooltip.remove();
21189
+ const tooltip = document.createElement("div");
21190
+ tooltip.className = "myio-chart-tooltip";
21191
+ tooltip.style.cssText = `
21192
+ position: absolute;
21193
+ background: ${state.theme === "dark" ? "rgba(30, 30, 40, 0.95)" : "rgba(255, 255, 255, 0.98)"};
21194
+ border: 1px solid ${colors.border};
21195
+ border-radius: 8px;
21196
+ padding: 10px 14px;
21197
+ font-size: 13px;
21198
+ color: ${colors.text};
21199
+ pointer-events: none;
21200
+ opacity: 0;
21201
+ transition: opacity 0.15s;
21202
+ z-index: 1000;
21203
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
21204
+ min-width: 160px;
21205
+ `;
21206
+ container.appendChild(tooltip);
21207
+ const findNearestPoint = (mouseX, mouseY) => {
21208
+ const threshold = 20;
21209
+ let nearest = null;
21210
+ let minDist = Infinity;
21211
+ for (const point of chartData) {
21212
+ const dist = Math.sqrt(
21213
+ Math.pow(mouseX - point.screenX, 2) + Math.pow(mouseY - point.screenY, 2)
21214
+ );
21215
+ if (dist < minDist && dist < threshold) {
21216
+ minDist = dist;
21217
+ nearest = point;
21218
+ }
21219
+ }
21220
+ return nearest;
21221
+ };
21222
+ canvas.addEventListener("mousemove", (e) => {
21223
+ const rect = canvas.getBoundingClientRect();
21224
+ const mouseX = e.clientX - rect.left;
21225
+ const mouseY = e.clientY - rect.top;
21226
+ const point = findNearestPoint(mouseX, mouseY);
21227
+ if (point) {
21228
+ const date = new Date(point.x);
21229
+ let dateStr;
21230
+ if (state.granularity === "hour") {
21231
+ dateStr = date.toLocaleDateString(state.locale, {
21232
+ day: "2-digit",
21233
+ month: "2-digit",
21234
+ year: "numeric"
21235
+ }) + " " + date.toLocaleTimeString(state.locale, {
21236
+ hour: "2-digit",
21237
+ minute: "2-digit"
21238
+ });
21239
+ } else {
21240
+ dateStr = date.toLocaleDateString(state.locale, {
21241
+ day: "2-digit",
21242
+ month: "2-digit",
21243
+ year: "numeric"
21244
+ });
21245
+ }
21246
+ tooltip.innerHTML = `
21247
+ <div style="display: flex; align-items: center; gap: 8px; margin-bottom: 6px;">
21248
+ <span style="width: 10px; height: 10px; border-radius: 50%; background: ${point.deviceColor};"></span>
21249
+ <span style="font-weight: 600;">${point.deviceLabel}</span>
21250
+ </div>
21251
+ <div style="font-weight: 600; font-size: 16px; color: ${point.deviceColor}; margin-bottom: 4px;">
21252
+ ${formatTemperature(point.y)}
21253
+ </div>
21254
+ <div style="font-size: 11px; color: ${colors.textMuted};">
21255
+ \u{1F4C5} ${dateStr}
21256
+ </div>
21257
+ `;
21258
+ let tooltipX = point.screenX + 15;
21259
+ let tooltipY = point.screenY - 15;
21260
+ const tooltipRect = tooltip.getBoundingClientRect();
21261
+ const containerRect = container.getBoundingClientRect();
21262
+ if (tooltipX + tooltipRect.width > containerRect.width - 10) {
21263
+ tooltipX = point.screenX - tooltipRect.width - 15;
21264
+ }
21265
+ if (tooltipY < 10) {
21266
+ tooltipY = point.screenY + 15;
21267
+ }
21268
+ tooltip.style.left = `${tooltipX}px`;
21269
+ tooltip.style.top = `${tooltipY}px`;
21270
+ tooltip.style.opacity = "1";
21271
+ canvas.style.cursor = "pointer";
21272
+ } else {
21273
+ tooltip.style.opacity = "0";
21274
+ canvas.style.cursor = "default";
21275
+ }
21276
+ });
21277
+ canvas.addEventListener("mouseleave", () => {
21278
+ tooltip.style.opacity = "0";
21279
+ canvas.style.cursor = "default";
21280
+ });
21281
+ }
21282
+ async function setupEventListeners2(container, state, modalId, onClose) {
21283
+ const closeModal = () => {
21284
+ container.remove();
21285
+ onClose?.();
21286
+ };
21287
+ container.querySelector(".myio-temp-comparison-overlay")?.addEventListener("click", (e) => {
21288
+ if (e.target === e.currentTarget) closeModal();
21289
+ });
21290
+ document.getElementById(`${modalId}-close`)?.addEventListener("click", closeModal);
21291
+ document.getElementById(`${modalId}-close-btn`)?.addEventListener("click", closeModal);
21292
+ const dateRangeInput = document.getElementById(`${modalId}-date-range`);
21293
+ if (dateRangeInput && !state.dateRangePicker) {
21294
+ try {
21295
+ state.dateRangePicker = await createDateRangePicker2(dateRangeInput, {
21296
+ presetStart: new Date(state.startTs).toISOString(),
21297
+ presetEnd: new Date(state.endTs).toISOString(),
21298
+ includeTime: true,
21299
+ timePrecision: "minute",
21300
+ maxRangeDays: 90,
21301
+ locale: state.locale,
21302
+ parentEl: container.querySelector(".myio-temp-comparison-content"),
21303
+ onApply: (result) => {
21304
+ state.startTs = new Date(result.startISO).getTime();
21305
+ state.endTs = new Date(result.endISO).getTime();
21306
+ console.log("[TemperatureComparisonModal] Date range applied:", result);
21307
+ }
21308
+ });
21309
+ } catch (error) {
21310
+ console.warn("[TemperatureComparisonModal] DateRangePicker initialization failed:", error);
21311
+ }
21312
+ }
21313
+ document.getElementById(`${modalId}-theme-toggle`)?.addEventListener("click", async () => {
21314
+ state.theme = state.theme === "dark" ? "light" : "dark";
21315
+ localStorage.setItem("myio-temp-comparison-theme", state.theme);
21316
+ state.dateRangePicker = null;
21317
+ renderModal2(container, state, modalId);
21318
+ if (state.deviceData.some((dd) => dd.data.length > 0)) {
21319
+ drawComparisonChart(modalId, state);
21320
+ }
21321
+ await setupEventListeners2(container, state, modalId, onClose);
21322
+ });
21323
+ document.getElementById(`${modalId}-maximize`)?.addEventListener("click", async () => {
21324
+ container.__isMaximized = !container.__isMaximized;
21325
+ state.dateRangePicker = null;
21326
+ renderModal2(container, state, modalId);
21327
+ if (state.deviceData.some((dd) => dd.data.length > 0)) {
21328
+ drawComparisonChart(modalId, state);
21329
+ }
21330
+ await setupEventListeners2(container, state, modalId, onClose);
21331
+ });
21332
+ const periodBtn = document.getElementById(`${modalId}-period-btn`);
21333
+ const periodDropdown = document.getElementById(`${modalId}-period-dropdown`);
21334
+ periodBtn?.addEventListener("click", (e) => {
21335
+ e.stopPropagation();
21336
+ if (periodDropdown) {
21337
+ periodDropdown.style.display = periodDropdown.style.display === "none" ? "block" : "none";
21338
+ }
21339
+ });
21340
+ document.addEventListener("click", (e) => {
21341
+ if (periodDropdown && !periodDropdown.contains(e.target) && e.target !== periodBtn) {
21342
+ periodDropdown.style.display = "none";
21343
+ }
21344
+ });
21345
+ const periodCheckboxes = document.querySelectorAll(`input[name="${modalId}-period"]`);
21346
+ periodCheckboxes.forEach((checkbox) => {
21347
+ checkbox.addEventListener("change", () => {
21348
+ const checked = Array.from(periodCheckboxes).filter((cb) => cb.checked).map((cb) => cb.value);
21349
+ state.selectedPeriods = checked;
21350
+ const btnLabel = periodBtn?.querySelector("span:first-child");
21351
+ if (btnLabel) {
21352
+ btnLabel.textContent = getSelectedPeriodsLabel(state.selectedPeriods);
21353
+ }
21354
+ if (state.deviceData.some((dd) => dd.data.length > 0)) {
21355
+ drawComparisonChart(modalId, state);
21356
+ }
21357
+ });
21358
+ });
21359
+ document.getElementById(`${modalId}-period-select-all`)?.addEventListener("click", () => {
21360
+ periodCheckboxes.forEach((cb) => {
21361
+ cb.checked = true;
21362
+ });
21363
+ state.selectedPeriods = ["madrugada", "manha", "tarde", "noite"];
21364
+ const btnLabel = periodBtn?.querySelector("span:first-child");
21365
+ if (btnLabel) {
21366
+ btnLabel.textContent = getSelectedPeriodsLabel(state.selectedPeriods);
21367
+ }
21368
+ if (state.deviceData.some((dd) => dd.data.length > 0)) {
21369
+ drawComparisonChart(modalId, state);
21370
+ }
21371
+ });
21372
+ document.getElementById(`${modalId}-period-clear`)?.addEventListener("click", () => {
21373
+ periodCheckboxes.forEach((cb) => {
21374
+ cb.checked = false;
21375
+ });
21376
+ state.selectedPeriods = [];
21377
+ const btnLabel = periodBtn?.querySelector("span:first-child");
21378
+ if (btnLabel) {
21379
+ btnLabel.textContent = getSelectedPeriodsLabel(state.selectedPeriods);
21380
+ }
21381
+ if (state.deviceData.some((dd) => dd.data.length > 0)) {
21382
+ drawComparisonChart(modalId, state);
21383
+ }
21384
+ });
21385
+ document.getElementById(`${modalId}-granularity`)?.addEventListener("change", (e) => {
21386
+ state.granularity = e.target.value;
21387
+ localStorage.setItem("myio-temp-comparison-granularity", state.granularity);
21388
+ if (state.deviceData.some((dd) => dd.data.length > 0)) {
21389
+ drawComparisonChart(modalId, state);
21390
+ }
21391
+ });
21392
+ document.getElementById(`${modalId}-query`)?.addEventListener("click", async () => {
21393
+ if (state.startTs >= state.endTs) {
21394
+ alert("Por favor, selecione um per\xEDodo v\xE1lido");
21395
+ return;
21396
+ }
21397
+ state.isLoading = true;
21398
+ state.dateRangePicker = null;
21399
+ renderModal2(container, state, modalId);
21400
+ await fetchAllDevicesData(state);
21401
+ renderModal2(container, state, modalId);
21402
+ drawComparisonChart(modalId, state);
21403
+ await setupEventListeners2(container, state, modalId, onClose);
21404
+ });
21405
+ document.getElementById(`${modalId}-export`)?.addEventListener("click", () => {
21406
+ if (state.deviceData.every((dd) => dd.data.length === 0)) return;
21407
+ exportComparisonCSV(state);
21408
+ });
21409
+ }
21410
+ function exportComparisonCSV(state) {
21411
+ const startDateStr = new Date(state.startTs).toLocaleDateString(state.locale).replace(/\//g, "-");
21412
+ const endDateStr = new Date(state.endTs).toLocaleDateString(state.locale).replace(/\//g, "-");
21413
+ const BOM = "\uFEFF";
21414
+ let csvContent = BOM;
21415
+ csvContent += `Compara\xE7\xE3o de Temperatura
21416
+ `;
21417
+ csvContent += `Per\xEDodo: ${startDateStr} at\xE9 ${endDateStr}
21418
+ `;
21419
+ csvContent += `Sensores: ${state.devices.map((d) => d.label).join(", ")}
21420
+ `;
21421
+ csvContent += "\n";
21422
+ csvContent += "Estat\xEDsticas por Sensor:\n";
21423
+ csvContent += "Sensor,M\xE9dia (\xB0C),Min (\xB0C),Max (\xB0C),Leituras\n";
21424
+ state.deviceData.forEach((dd) => {
21425
+ csvContent += `"${dd.device.label}",${dd.stats.avg.toFixed(2)},${dd.stats.min.toFixed(2)},${dd.stats.max.toFixed(2)},${dd.stats.count}
21426
+ `;
21427
+ });
21428
+ csvContent += "\n";
21429
+ csvContent += "Dados Detalhados:\n";
21430
+ csvContent += "Data/Hora,Sensor,Temperatura (\xB0C)\n";
21431
+ state.deviceData.forEach((dd) => {
21432
+ dd.data.forEach((item) => {
21433
+ const date = new Date(item.ts).toLocaleString(state.locale);
21434
+ const temp = Number(item.value).toFixed(2);
21435
+ csvContent += `"${date}","${dd.device.label}",${temp}
21436
+ `;
21437
+ });
21438
+ });
21439
+ const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
21440
+ const url = URL.createObjectURL(blob);
21441
+ const link = document.createElement("a");
21442
+ link.href = url;
21443
+ link.download = `comparacao_temperatura_${startDateStr}_${endDateStr}.csv`;
21444
+ document.body.appendChild(link);
21445
+ link.click();
21446
+ document.body.removeChild(link);
21447
+ URL.revokeObjectURL(url);
21448
+ }
21449
+
21450
+ // src/components/temperature/TemperatureSettingsModal.ts
21451
+ var DARK_THEME2 = {
21452
+ modalBg: "linear-gradient(180deg, #1e1e2e 0%, #151521 100%)",
21453
+ headerBg: "#3e1a7d",
21454
+ textPrimary: "#ffffff",
21455
+ textSecondary: "rgba(255, 255, 255, 0.7)",
21456
+ textMuted: "rgba(255, 255, 255, 0.5)",
21457
+ inputBg: "rgba(255, 255, 255, 0.08)",
21458
+ inputBorder: "rgba(255, 255, 255, 0.2)",
21459
+ inputText: "#ffffff",
21460
+ buttonPrimary: "#3e1a7d",
21461
+ buttonPrimaryHover: "#5a2da8",
21462
+ buttonSecondary: "rgba(255, 255, 255, 0.1)",
21463
+ success: "#4CAF50",
21464
+ error: "#f44336",
21465
+ overlay: "rgba(0, 0, 0, 0.85)"
21466
+ };
21467
+ var LIGHT_THEME2 = {
21468
+ modalBg: "#ffffff",
21469
+ headerBg: "#3e1a7d",
21470
+ textPrimary: "#1a1a2e",
21471
+ textSecondary: "rgba(0, 0, 0, 0.7)",
21472
+ textMuted: "rgba(0, 0, 0, 0.5)",
21473
+ inputBg: "#f5f5f5",
21474
+ inputBorder: "rgba(0, 0, 0, 0.2)",
21475
+ inputText: "#1a1a2e",
21476
+ buttonPrimary: "#3e1a7d",
21477
+ buttonPrimaryHover: "#5a2da8",
21478
+ buttonSecondary: "rgba(0, 0, 0, 0.05)",
21479
+ success: "#4CAF50",
21480
+ error: "#f44336",
21481
+ overlay: "rgba(0, 0, 0, 0.5)"
21482
+ };
21483
+ function getColors(theme) {
21484
+ return theme === "dark" ? DARK_THEME2 : LIGHT_THEME2;
21485
+ }
21486
+ async function fetchCustomerAttributes(customerId, token) {
21487
+ const url = `/api/plugins/telemetry/CUSTOMER/${customerId}/values/attributes/SERVER_SCOPE`;
21488
+ const response = await fetch(url, {
21489
+ method: "GET",
21490
+ headers: {
21491
+ "Content-Type": "application/json",
21492
+ "X-Authorization": `Bearer ${token}`
21493
+ }
21494
+ });
21495
+ if (!response.ok) {
21496
+ if (response.status === 404 || response.status === 400) {
21497
+ return { minTemperature: null, maxTemperature: null };
21498
+ }
21499
+ throw new Error(`Failed to fetch attributes: ${response.status}`);
21500
+ }
21501
+ const attributes = await response.json();
21502
+ let minTemperature = null;
21503
+ let maxTemperature = null;
21504
+ if (Array.isArray(attributes)) {
21505
+ for (const attr of attributes) {
21506
+ if (attr.key === "minTemperature") {
21507
+ minTemperature = Number(attr.value);
21508
+ } else if (attr.key === "maxTemperature") {
21509
+ maxTemperature = Number(attr.value);
21510
+ }
21511
+ }
21512
+ }
21513
+ return { minTemperature, maxTemperature };
21514
+ }
21515
+ async function saveCustomerAttributes(customerId, token, minTemperature, maxTemperature) {
21516
+ const url = `/api/plugins/telemetry/CUSTOMER/${customerId}/SERVER_SCOPE`;
21517
+ const attributes = {
21518
+ minTemperature,
21519
+ maxTemperature
21520
+ };
21521
+ const response = await fetch(url, {
21522
+ method: "POST",
21523
+ headers: {
21524
+ "Content-Type": "application/json",
21525
+ "X-Authorization": `Bearer ${token}`
21526
+ },
21527
+ body: JSON.stringify(attributes)
21528
+ });
21529
+ if (!response.ok) {
21530
+ throw new Error(`Failed to save attributes: ${response.status}`);
21531
+ }
21532
+ }
21533
+ function renderModal3(container, state, modalId, onClose, onSave) {
21534
+ const colors = getColors(state.theme);
21535
+ const minValue = state.minTemperature !== null ? state.minTemperature : "";
21536
+ const maxValue = state.maxTemperature !== null ? state.maxTemperature : "";
21537
+ container.innerHTML = `
21538
+ <style>
21539
+ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
21540
+ @keyframes slideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
21541
+ @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
21542
+
21543
+ #${modalId} {
21544
+ position: fixed;
21545
+ top: 0;
21546
+ left: 0;
21547
+ width: 100%;
21548
+ height: 100%;
21549
+ background: ${colors.overlay};
21550
+ z-index: 10000;
21551
+ display: flex;
21552
+ align-items: center;
21553
+ justify-content: center;
21554
+ animation: fadeIn 0.2s ease-out;
21555
+ }
21556
+
21557
+ #${modalId} .modal-content {
21558
+ background: ${colors.modalBg};
21559
+ border-radius: 16px;
21560
+ width: 90%;
21561
+ max-width: 480px;
21562
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
21563
+ border: 1px solid rgba(255, 255, 255, 0.1);
21564
+ animation: slideIn 0.3s ease-out;
21565
+ overflow: hidden;
21566
+ }
21567
+
21568
+ #${modalId} .modal-header {
21569
+ background: ${colors.headerBg};
21570
+ padding: 20px 24px;
21571
+ display: flex;
21572
+ align-items: center;
21573
+ justify-content: space-between;
21574
+ }
21575
+
21576
+ #${modalId} .modal-title {
21577
+ margin: 0;
21578
+ font-size: 18px;
21579
+ font-weight: 600;
21580
+ color: #fff;
21581
+ font-family: 'Roboto', sans-serif;
21582
+ display: flex;
21583
+ align-items: center;
21584
+ gap: 10px;
21585
+ }
21586
+
21587
+ #${modalId} .close-btn {
21588
+ width: 32px;
21589
+ height: 32px;
21590
+ background: rgba(255, 255, 255, 0.1);
21591
+ border: 1px solid rgba(255, 255, 255, 0.2);
21592
+ border-radius: 8px;
21593
+ cursor: pointer;
21594
+ display: flex;
21595
+ align-items: center;
21596
+ justify-content: center;
21597
+ transition: all 0.2s;
21598
+ color: #fff;
21599
+ font-size: 18px;
21600
+ }
21601
+
21602
+ #${modalId} .close-btn:hover {
21603
+ background: rgba(255, 68, 68, 0.25);
21604
+ border-color: rgba(255, 68, 68, 0.5);
21605
+ }
21606
+
21607
+ #${modalId} .modal-body {
21608
+ padding: 24px;
21609
+ }
21610
+
21611
+ #${modalId} .customer-info {
21612
+ margin-bottom: 24px;
21613
+ padding: 12px 16px;
21614
+ background: ${colors.inputBg};
21615
+ border-radius: 8px;
21616
+ border: 1px solid ${colors.inputBorder};
21617
+ }
21618
+
21619
+ #${modalId} .customer-label {
21620
+ font-size: 12px;
21621
+ color: ${colors.textMuted};
21622
+ margin-bottom: 4px;
21623
+ }
21624
+
21625
+ #${modalId} .customer-name {
21626
+ font-size: 16px;
21627
+ font-weight: 500;
21628
+ color: ${colors.textPrimary};
21629
+ }
21630
+
21631
+ #${modalId} .form-group {
21632
+ margin-bottom: 20px;
21633
+ }
21634
+
21635
+ #${modalId} .form-label {
21636
+ display: block;
21637
+ font-size: 14px;
21638
+ font-weight: 500;
21639
+ color: ${colors.textSecondary};
21640
+ margin-bottom: 8px;
21641
+ }
21642
+
21643
+ #${modalId} .form-input {
21644
+ width: 100%;
21645
+ padding: 12px 16px;
21646
+ font-size: 16px;
21647
+ background: ${colors.inputBg};
21648
+ border: 1px solid ${colors.inputBorder};
21649
+ border-radius: 8px;
21650
+ color: ${colors.inputText};
21651
+ outline: none;
21652
+ transition: border-color 0.2s;
21653
+ box-sizing: border-box;
21654
+ }
21655
+
21656
+ #${modalId} .form-input:focus {
21657
+ border-color: ${colors.buttonPrimary};
21658
+ }
21659
+
21660
+ #${modalId} .form-input::placeholder {
21661
+ color: ${colors.textMuted};
21662
+ }
21663
+
21664
+ #${modalId} .form-hint {
21665
+ font-size: 12px;
21666
+ color: ${colors.textMuted};
21667
+ margin-top: 6px;
21668
+ }
21669
+
21670
+ #${modalId} .temperature-range {
21671
+ display: grid;
21672
+ grid-template-columns: 1fr 1fr;
21673
+ gap: 16px;
21674
+ }
21675
+
21676
+ #${modalId} .range-preview {
21677
+ margin-top: 20px;
21678
+ padding: 16px;
21679
+ background: rgba(76, 175, 80, 0.1);
21680
+ border: 1px dashed ${colors.success};
21681
+ border-radius: 8px;
21682
+ text-align: center;
21683
+ }
21684
+
21685
+ #${modalId} .range-preview-label {
21686
+ font-size: 12px;
21687
+ color: ${colors.textMuted};
21688
+ margin-bottom: 8px;
21689
+ }
21690
+
21691
+ #${modalId} .range-preview-value {
21692
+ font-size: 24px;
21693
+ font-weight: 600;
21694
+ color: ${colors.success};
21695
+ }
21696
+
21697
+ #${modalId} .modal-footer {
21698
+ padding: 16px 24px;
21699
+ border-top: 1px solid ${colors.inputBorder};
21700
+ display: flex;
21701
+ justify-content: flex-end;
21702
+ gap: 12px;
21703
+ }
21704
+
21705
+ #${modalId} .btn {
21706
+ padding: 10px 24px;
21707
+ font-size: 14px;
21708
+ font-weight: 500;
21709
+ border-radius: 8px;
21710
+ cursor: pointer;
21711
+ transition: all 0.2s;
21712
+ border: none;
21713
+ display: flex;
21714
+ align-items: center;
21715
+ gap: 8px;
21716
+ }
21717
+
21718
+ #${modalId} .btn-secondary {
21719
+ background: ${colors.buttonSecondary};
21720
+ color: ${colors.textSecondary};
21721
+ border: 1px solid ${colors.inputBorder};
21722
+ }
21723
+
21724
+ #${modalId} .btn-secondary:hover {
21725
+ background: ${colors.inputBg};
21726
+ }
21727
+
21728
+ #${modalId} .btn-primary {
21729
+ background: ${colors.buttonPrimary};
21730
+ color: #fff;
21731
+ }
21732
+
21733
+ #${modalId} .btn-primary:hover {
21734
+ background: ${colors.buttonPrimaryHover};
21735
+ }
21736
+
21737
+ #${modalId} .btn-primary:disabled {
21738
+ opacity: 0.6;
21739
+ cursor: not-allowed;
21740
+ }
21741
+
21742
+ #${modalId} .spinner {
21743
+ width: 16px;
21744
+ height: 16px;
21745
+ border: 2px solid rgba(255,255,255,0.3);
21746
+ border-top-color: #fff;
21747
+ border-radius: 50%;
21748
+ animation: spin 1s linear infinite;
21749
+ }
21750
+
21751
+ #${modalId} .message {
21752
+ padding: 12px 16px;
21753
+ border-radius: 8px;
21754
+ margin-bottom: 16px;
21755
+ font-size: 14px;
21756
+ }
21757
+
21758
+ #${modalId} .message-error {
21759
+ background: rgba(244, 67, 54, 0.1);
21760
+ border: 1px solid ${colors.error};
21761
+ color: ${colors.error};
21762
+ }
21763
+
21764
+ #${modalId} .message-success {
21765
+ background: rgba(76, 175, 80, 0.1);
21766
+ border: 1px solid ${colors.success};
21767
+ color: ${colors.success};
21768
+ }
21769
+
21770
+ #${modalId} .loading-overlay {
21771
+ display: flex;
21772
+ flex-direction: column;
21773
+ align-items: center;
21774
+ justify-content: center;
21775
+ padding: 48px;
21776
+ color: ${colors.textSecondary};
21777
+ }
21778
+
21779
+ #${modalId} .loading-spinner {
21780
+ width: 40px;
21781
+ height: 40px;
21782
+ border: 3px solid ${colors.inputBorder};
21783
+ border-top-color: ${colors.buttonPrimary};
21784
+ border-radius: 50%;
21785
+ animation: spin 1s linear infinite;
21786
+ margin-bottom: 16px;
21787
+ }
21788
+ </style>
21789
+
21790
+ <div id="${modalId}" class="modal-overlay">
21791
+ <div class="modal-content">
21792
+ <div class="modal-header">
21793
+ <h2 class="modal-title">
21794
+ <span>\u{1F321}\uFE0F</span>
21795
+ Configurar Temperatura
21796
+ </h2>
21797
+ <button class="close-btn" id="${modalId}-close">&times;</button>
21798
+ </div>
21799
+
21800
+ <div class="modal-body">
21801
+ ${state.isLoading ? `
21802
+ <div class="loading-overlay">
21803
+ <div class="loading-spinner"></div>
21804
+ <div>Carregando configura\xE7\xF5es...</div>
21805
+ </div>
21806
+ ` : `
21807
+ ${state.error ? `
21808
+ <div class="message message-error">${state.error}</div>
21809
+ ` : ""}
21810
+
21811
+ ${state.successMessage ? `
21812
+ <div class="message message-success">${state.successMessage}</div>
21813
+ ` : ""}
21814
+
21815
+ <div class="customer-info">
21816
+ <div class="customer-label">Shopping / Cliente</div>
21817
+ <div class="customer-name">${state.customerName || "N\xE3o identificado"}</div>
21818
+ </div>
21819
+
21820
+ <div class="form-group">
21821
+ <label class="form-label">Faixa de Temperatura Ideal</label>
21822
+ <div class="temperature-range">
21823
+ <div>
21824
+ <input
21825
+ type="number"
21826
+ id="${modalId}-min"
21827
+ class="form-input"
21828
+ placeholder="M\xEDnima"
21829
+ value="${minValue}"
21830
+ step="0.5"
21831
+ min="0"
21832
+ max="50"
21833
+ />
21834
+ <div class="form-hint">Temperatura m\xEDnima (\xB0C)</div>
21835
+ </div>
21836
+ <div>
21837
+ <input
21838
+ type="number"
21839
+ id="${modalId}-max"
21840
+ class="form-input"
21841
+ placeholder="M\xE1xima"
21842
+ value="${maxValue}"
21843
+ step="0.5"
21844
+ min="0"
21845
+ max="50"
21846
+ />
21847
+ <div class="form-hint">Temperatura m\xE1xima (\xB0C)</div>
21848
+ </div>
21849
+ </div>
21850
+ </div>
21851
+
21852
+ <div class="range-preview" id="${modalId}-preview">
21853
+ <div class="range-preview-label">Faixa configurada</div>
21854
+ <div class="range-preview-value" id="${modalId}-preview-value">
21855
+ ${minValue && maxValue ? `${minValue}\xB0C - ${maxValue}\xB0C` : "N\xE3o definida"}
21856
+ </div>
21857
+ </div>
21858
+ `}
21859
+ </div>
21860
+
21861
+ ${!state.isLoading ? `
21862
+ <div class="modal-footer">
21863
+ <button class="btn btn-secondary" id="${modalId}-cancel">Cancelar</button>
21864
+ <button class="btn btn-primary" id="${modalId}-save" ${state.isSaving ? "disabled" : ""}>
21865
+ ${state.isSaving ? '<div class="spinner"></div> Salvando...' : "Salvar"}
21866
+ </button>
21867
+ </div>
21868
+ ` : ""}
21869
+ </div>
21870
+ </div>
21871
+ `;
21872
+ const closeBtn = document.getElementById(`${modalId}-close`);
21873
+ const cancelBtn = document.getElementById(`${modalId}-cancel`);
21874
+ const saveBtn = document.getElementById(`${modalId}-save`);
21875
+ const minInput = document.getElementById(`${modalId}-min`);
21876
+ const maxInput = document.getElementById(`${modalId}-max`);
21877
+ const previewValue = document.getElementById(`${modalId}-preview-value`);
21878
+ const overlay = document.getElementById(modalId);
21879
+ closeBtn?.addEventListener("click", onClose);
21880
+ cancelBtn?.addEventListener("click", onClose);
21881
+ overlay?.addEventListener("click", (e) => {
21882
+ if (e.target === overlay) onClose();
21883
+ });
21884
+ const updatePreview = () => {
21885
+ if (previewValue && minInput && maxInput) {
21886
+ const min = minInput.value;
21887
+ const max = maxInput.value;
21888
+ if (min && max) {
21889
+ previewValue.textContent = `${min}\xB0C - ${max}\xB0C`;
21890
+ } else {
21891
+ previewValue.textContent = "N\xE3o definida";
21892
+ }
21893
+ }
21894
+ };
21895
+ minInput?.addEventListener("input", updatePreview);
21896
+ maxInput?.addEventListener("input", updatePreview);
21897
+ saveBtn?.addEventListener("click", async () => {
21898
+ if (!minInput || !maxInput) return;
21899
+ const min = parseFloat(minInput.value);
21900
+ const max = parseFloat(maxInput.value);
21901
+ if (isNaN(min) || isNaN(max)) {
21902
+ state.error = "Por favor, preencha ambos os valores.";
21903
+ renderModal3(container, state, modalId, onClose, onSave);
21904
+ return;
21905
+ }
21906
+ if (min >= max) {
21907
+ state.error = "A temperatura m\xEDnima deve ser menor que a m\xE1xima.";
21908
+ renderModal3(container, state, modalId, onClose, onSave);
21909
+ return;
21910
+ }
21911
+ if (min < 0 || max > 50) {
21912
+ state.error = "Os valores devem estar entre 0\xB0C e 50\xB0C.";
21913
+ renderModal3(container, state, modalId, onClose, onSave);
21914
+ return;
21915
+ }
21916
+ await onSave(min, max);
21917
+ });
21918
+ }
21919
+ function openTemperatureSettingsModal(params) {
21920
+ const modalId = `myio-temp-settings-${Date.now()}`;
21921
+ const state = {
21922
+ customerId: params.customerId,
21923
+ customerName: params.customerName || "",
21924
+ token: params.token,
21925
+ theme: params.theme || "dark",
21926
+ minTemperature: null,
21927
+ maxTemperature: null,
21928
+ isLoading: true,
21929
+ isSaving: false,
21930
+ error: null,
21931
+ successMessage: null
21932
+ };
21933
+ const container = document.createElement("div");
21934
+ container.id = `${modalId}-container`;
21935
+ document.body.appendChild(container);
21936
+ const destroy = () => {
21937
+ container.remove();
21938
+ params.onClose?.();
21939
+ };
21940
+ const handleSave = async (min, max) => {
21941
+ state.isSaving = true;
21942
+ state.error = null;
21943
+ state.successMessage = null;
21944
+ renderModal3(container, state, modalId, destroy, handleSave);
21945
+ try {
21946
+ await saveCustomerAttributes(state.customerId, state.token, min, max);
21947
+ state.minTemperature = min;
21948
+ state.maxTemperature = max;
21949
+ state.isSaving = false;
21950
+ state.successMessage = "Configura\xE7\xF5es salvas com sucesso!";
21951
+ renderModal3(container, state, modalId, destroy, handleSave);
21952
+ params.onSave?.({ minTemperature: min, maxTemperature: max });
21953
+ setTimeout(() => {
21954
+ destroy();
21955
+ }, 1500);
21956
+ } catch (error) {
21957
+ state.isSaving = false;
21958
+ state.error = `Erro ao salvar: ${error.message}`;
21959
+ renderModal3(container, state, modalId, destroy, handleSave);
21960
+ }
21961
+ };
21962
+ renderModal3(container, state, modalId, destroy, handleSave);
21963
+ fetchCustomerAttributes(state.customerId, state.token).then(({ minTemperature, maxTemperature }) => {
21964
+ state.minTemperature = minTemperature;
21965
+ state.maxTemperature = maxTemperature;
21966
+ state.isLoading = false;
21967
+ renderModal3(container, state, modalId, destroy, handleSave);
21968
+ }).catch((error) => {
21969
+ state.isLoading = false;
21970
+ state.error = `Erro ao carregar: ${error.message}`;
21971
+ renderModal3(container, state, modalId, destroy, handleSave);
21972
+ });
21973
+ return { destroy };
21974
+ }
19641
21975
  // Annotate the CommonJS export names for ESM import in node:
19642
21976
  0 && (module.exports = {
21977
+ CHART_COLORS,
19643
21978
  ConnectionStatusType,
21979
+ DEFAULT_CLAMP_RANGE,
19644
21980
  DeviceStatusType,
19645
21981
  MyIOChartModal,
19646
21982
  MyIODraggableCard,
@@ -19649,6 +21985,7 @@ function openGoalsPanel(params) {
19649
21985
  MyIOToast,
19650
21986
  addDetectionContext,
19651
21987
  addNamespace,
21988
+ aggregateByDay,
19652
21989
  averageByDay,
19653
21990
  buildListItemsThingsboardByUniqueDatasource,
19654
21991
  buildMyioIngestionAuth,
@@ -19657,6 +21994,8 @@ function openGoalsPanel(params) {
19657
21994
  calcDeltaPercent,
19658
21995
  calculateDeviceStatus,
19659
21996
  calculateDeviceStatusWithRanges,
21997
+ calculateStats,
21998
+ clampTemperature,
19660
21999
  classify,
19661
22000
  classifyWaterLabel,
19662
22001
  classifyWaterLabels,
@@ -19669,9 +22008,11 @@ function openGoalsPanel(params) {
19669
22008
  detectDeviceType,
19670
22009
  determineInterval,
19671
22010
  deviceStatusIcons,
22011
+ exportTemperatureCSV,
19672
22012
  exportToCSV,
19673
22013
  exportToCSVAll,
19674
22014
  extractMyIOCredentials,
22015
+ fetchTemperatureData,
19675
22016
  fetchThingsboardCustomerAttrsFromStorage,
19676
22017
  fetchThingsboardCustomerServerScopeAttrs,
19677
22018
  findValue,
@@ -19685,6 +22026,7 @@ function openGoalsPanel(params) {
19685
22026
  formatEnergy,
19686
22027
  formatNumberReadable,
19687
22028
  formatTankHeadFromCm,
22029
+ formatTemperature,
19688
22030
  formatWaterByGroup,
19689
22031
  formatWaterVolumeM3,
19690
22032
  getAuthCacheStats,
@@ -19699,6 +22041,7 @@ function openGoalsPanel(params) {
19699
22041
  getValueByDatakeyLegacy,
19700
22042
  getWaterCategories,
19701
22043
  groupByDay,
22044
+ interpolateTemperature,
19702
22045
  isDeviceOffline,
19703
22046
  isValidConnectionStatus,
19704
22047
  isValidDeviceStatus,
@@ -19716,6 +22059,9 @@ function openGoalsPanel(params) {
19716
22059
  openDemandModal,
19717
22060
  openGoalsPanel,
19718
22061
  openRealTimeTelemetryModal,
22062
+ openTemperatureComparisonModal,
22063
+ openTemperatureModal,
22064
+ openTemperatureSettingsModal,
19719
22065
  parseInputDateToDate,
19720
22066
  renderCardComponent,
19721
22067
  renderCardComponentEnhanced,