myio-js-library 0.1.141 → 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.js CHANGED
@@ -18148,13 +18148,13 @@ function openGoalsPanel(params) {
18148
18148
  function initializeModal() {
18149
18149
  if (data) {
18150
18150
  modalState.goalsData = data;
18151
- renderModal3();
18151
+ renderModal4();
18152
18152
  } else {
18153
- renderModal3();
18153
+ renderModal4();
18154
18154
  loadGoalsData();
18155
18155
  }
18156
18156
  }
18157
- function renderModal3() {
18157
+ function renderModal4() {
18158
18158
  const existing = document.getElementById("myio-goals-panel-modal");
18159
18159
  if (existing) {
18160
18160
  existing.remove();
@@ -20154,8 +20154,12 @@ function drawChart(modalId, state) {
20154
20154
  const paddingBottom = 55;
20155
20155
  const isPeriodsFiltered = state.selectedPeriods.length < 4 && state.selectedPeriods.length > 0;
20156
20156
  const values = chartData.map((d) => d.y);
20157
- const minY = Math.min(...values) - 1;
20158
- const maxY = Math.max(...values) + 1;
20157
+ const dataMin = Math.min(...values);
20158
+ const dataMax = Math.max(...values);
20159
+ const thresholdMin = state.temperatureMin !== null ? state.temperatureMin : dataMin;
20160
+ const thresholdMax = state.temperatureMax !== null ? state.temperatureMax : dataMax;
20161
+ const minY = Math.min(dataMin, thresholdMin) - 1;
20162
+ const maxY = Math.max(dataMax, thresholdMax) + 1;
20159
20163
  const chartWidth = width - paddingLeft - paddingRight;
20160
20164
  const chartHeight = height - paddingTop - paddingBottom;
20161
20165
  const scaleY = chartHeight / (maxY - minY || 1);
@@ -20496,8 +20500,10 @@ async function openTemperatureComparisonModal(params) {
20496
20500
  deviceData: [],
20497
20501
  isLoading: true,
20498
20502
  dateRangePicker: null,
20499
- selectedPeriods: ["madrugada", "manha", "tarde", "noite"]
20503
+ selectedPeriods: ["madrugada", "manha", "tarde", "noite"],
20500
20504
  // All periods selected by default
20505
+ temperatureMin: params.temperatureMin ?? null,
20506
+ temperatureMax: params.temperatureMax ?? null
20501
20507
  };
20502
20508
  const savedGranularity = localStorage.getItem("myio-temp-comparison-granularity");
20503
20509
  const savedTheme = localStorage.getItem("myio-temp-comparison-theme");
@@ -20893,16 +20899,52 @@ function drawComparisonChart(modalId, state) {
20893
20899
  return;
20894
20900
  }
20895
20901
  const isPeriodsFiltered = state.selectedPeriods.length < 4 && state.selectedPeriods.length > 0;
20896
- let globalMinY = Infinity;
20897
- let globalMaxY = -Infinity;
20902
+ let dataMinY = Infinity;
20903
+ let dataMaxY = -Infinity;
20898
20904
  processedData.forEach(({ points }) => {
20899
20905
  points.forEach((point) => {
20900
- if (point.y < globalMinY) globalMinY = point.y;
20901
- if (point.y > globalMaxY) globalMaxY = point.y;
20906
+ if (point.y < dataMinY) dataMinY = point.y;
20907
+ if (point.y > dataMaxY) dataMaxY = point.y;
20908
+ });
20909
+ });
20910
+ const rangeMap = /* @__PURE__ */ new Map();
20911
+ state.deviceData.forEach((dd, index) => {
20912
+ const device = dd.device;
20913
+ const min = device.temperatureMin;
20914
+ const max = device.temperatureMax;
20915
+ if (min !== void 0 && min !== null && max !== void 0 && max !== null) {
20916
+ const key = `${min}-${max}`;
20917
+ if (!rangeMap.has(key)) {
20918
+ rangeMap.set(key, {
20919
+ min,
20920
+ max,
20921
+ customerName: device.customerName || "",
20922
+ color: CHART_COLORS[index % CHART_COLORS.length],
20923
+ deviceLabels: [device.label]
20924
+ });
20925
+ } else {
20926
+ rangeMap.get(key).deviceLabels.push(device.label);
20927
+ }
20928
+ }
20929
+ });
20930
+ if (rangeMap.size === 0 && state.temperatureMin !== null && state.temperatureMax !== null) {
20931
+ rangeMap.set("global", {
20932
+ min: state.temperatureMin,
20933
+ max: state.temperatureMax,
20934
+ customerName: "Global",
20935
+ color: colors.success,
20936
+ deviceLabels: []
20902
20937
  });
20938
+ }
20939
+ const temperatureRanges = Array.from(rangeMap.values());
20940
+ let thresholdMinY = dataMinY;
20941
+ let thresholdMaxY = dataMaxY;
20942
+ temperatureRanges.forEach((range) => {
20943
+ if (range.min < thresholdMinY) thresholdMinY = range.min;
20944
+ if (range.max > thresholdMaxY) thresholdMaxY = range.max;
20903
20945
  });
20904
- globalMinY = Math.floor(globalMinY) - 1;
20905
- globalMaxY = Math.ceil(globalMaxY) + 1;
20946
+ const globalMinY = Math.floor(Math.min(dataMinY, thresholdMinY)) - 1;
20947
+ const globalMaxY = Math.ceil(Math.max(dataMaxY, thresholdMaxY)) + 1;
20906
20948
  const chartWidth = width - paddingLeft - paddingRight;
20907
20949
  const chartHeight = height - paddingTop - paddingBottom;
20908
20950
  const scaleY = chartHeight / (globalMaxY - globalMinY || 1);
@@ -20942,6 +20984,41 @@ function drawComparisonChart(modalId, state) {
20942
20984
  ctx.lineTo(width - paddingRight, y);
20943
20985
  ctx.stroke();
20944
20986
  }
20987
+ const rangeColors = [
20988
+ { fill: "rgba(76, 175, 80, 0.12)", stroke: "#4CAF50" },
20989
+ // Green
20990
+ { fill: "rgba(33, 150, 243, 0.12)", stroke: "#2196F3" },
20991
+ // Blue
20992
+ { fill: "rgba(255, 152, 0, 0.12)", stroke: "#FF9800" },
20993
+ // Orange
20994
+ { fill: "rgba(156, 39, 176, 0.12)", stroke: "#9C27B0" }
20995
+ // Purple
20996
+ ];
20997
+ temperatureRanges.forEach((range, index) => {
20998
+ const rangeMinY = height - paddingBottom - (range.min - globalMinY) * scaleY;
20999
+ const rangeMaxY = height - paddingBottom - (range.max - globalMinY) * scaleY;
21000
+ const colorSet = rangeColors[index % rangeColors.length];
21001
+ ctx.fillStyle = colorSet.fill;
21002
+ ctx.fillRect(paddingLeft, rangeMaxY, chartWidth, rangeMinY - rangeMaxY);
21003
+ ctx.strokeStyle = colorSet.stroke;
21004
+ ctx.lineWidth = 1.5;
21005
+ ctx.setLineDash([6, 4]);
21006
+ ctx.beginPath();
21007
+ ctx.moveTo(paddingLeft, rangeMinY);
21008
+ ctx.lineTo(width - paddingRight, rangeMinY);
21009
+ ctx.moveTo(paddingLeft, rangeMaxY);
21010
+ ctx.lineTo(width - paddingRight, rangeMaxY);
21011
+ ctx.stroke();
21012
+ ctx.setLineDash([]);
21013
+ if (temperatureRanges.length > 1 || range.customerName) {
21014
+ ctx.fillStyle = colorSet.stroke;
21015
+ ctx.font = "10px system-ui, sans-serif";
21016
+ ctx.textAlign = "left";
21017
+ const labelY = (rangeMinY + rangeMaxY) / 2;
21018
+ const labelText = range.customerName || `${range.min}\xB0-${range.max}\xB0C`;
21019
+ ctx.fillText(labelText, width - paddingRight + 5, labelY + 3);
21020
+ }
21021
+ });
20945
21022
  processedData.forEach(({ device, points }) => {
20946
21023
  ctx.strokeStyle = device.color;
20947
21024
  ctx.lineWidth = 2.5;
@@ -21261,6 +21338,532 @@ function exportComparisonCSV(state) {
21261
21338
  document.body.removeChild(link);
21262
21339
  URL.revokeObjectURL(url);
21263
21340
  }
21341
+
21342
+ // src/components/temperature/TemperatureSettingsModal.ts
21343
+ var DARK_THEME2 = {
21344
+ modalBg: "linear-gradient(180deg, #1e1e2e 0%, #151521 100%)",
21345
+ headerBg: "#3e1a7d",
21346
+ textPrimary: "#ffffff",
21347
+ textSecondary: "rgba(255, 255, 255, 0.7)",
21348
+ textMuted: "rgba(255, 255, 255, 0.5)",
21349
+ inputBg: "rgba(255, 255, 255, 0.08)",
21350
+ inputBorder: "rgba(255, 255, 255, 0.2)",
21351
+ inputText: "#ffffff",
21352
+ buttonPrimary: "#3e1a7d",
21353
+ buttonPrimaryHover: "#5a2da8",
21354
+ buttonSecondary: "rgba(255, 255, 255, 0.1)",
21355
+ success: "#4CAF50",
21356
+ error: "#f44336",
21357
+ overlay: "rgba(0, 0, 0, 0.85)"
21358
+ };
21359
+ var LIGHT_THEME2 = {
21360
+ modalBg: "#ffffff",
21361
+ headerBg: "#3e1a7d",
21362
+ textPrimary: "#1a1a2e",
21363
+ textSecondary: "rgba(0, 0, 0, 0.7)",
21364
+ textMuted: "rgba(0, 0, 0, 0.5)",
21365
+ inputBg: "#f5f5f5",
21366
+ inputBorder: "rgba(0, 0, 0, 0.2)",
21367
+ inputText: "#1a1a2e",
21368
+ buttonPrimary: "#3e1a7d",
21369
+ buttonPrimaryHover: "#5a2da8",
21370
+ buttonSecondary: "rgba(0, 0, 0, 0.05)",
21371
+ success: "#4CAF50",
21372
+ error: "#f44336",
21373
+ overlay: "rgba(0, 0, 0, 0.5)"
21374
+ };
21375
+ function getColors(theme) {
21376
+ return theme === "dark" ? DARK_THEME2 : LIGHT_THEME2;
21377
+ }
21378
+ async function fetchCustomerAttributes(customerId, token) {
21379
+ const url = `/api/plugins/telemetry/CUSTOMER/${customerId}/values/attributes/SERVER_SCOPE`;
21380
+ const response = await fetch(url, {
21381
+ method: "GET",
21382
+ headers: {
21383
+ "Content-Type": "application/json",
21384
+ "X-Authorization": `Bearer ${token}`
21385
+ }
21386
+ });
21387
+ if (!response.ok) {
21388
+ if (response.status === 404 || response.status === 400) {
21389
+ return { minTemperature: null, maxTemperature: null };
21390
+ }
21391
+ throw new Error(`Failed to fetch attributes: ${response.status}`);
21392
+ }
21393
+ const attributes = await response.json();
21394
+ let minTemperature = null;
21395
+ let maxTemperature = null;
21396
+ if (Array.isArray(attributes)) {
21397
+ for (const attr of attributes) {
21398
+ if (attr.key === "minTemperature") {
21399
+ minTemperature = Number(attr.value);
21400
+ } else if (attr.key === "maxTemperature") {
21401
+ maxTemperature = Number(attr.value);
21402
+ }
21403
+ }
21404
+ }
21405
+ return { minTemperature, maxTemperature };
21406
+ }
21407
+ async function saveCustomerAttributes(customerId, token, minTemperature, maxTemperature) {
21408
+ const url = `/api/plugins/telemetry/CUSTOMER/${customerId}/SERVER_SCOPE`;
21409
+ const attributes = {
21410
+ minTemperature,
21411
+ maxTemperature
21412
+ };
21413
+ const response = await fetch(url, {
21414
+ method: "POST",
21415
+ headers: {
21416
+ "Content-Type": "application/json",
21417
+ "X-Authorization": `Bearer ${token}`
21418
+ },
21419
+ body: JSON.stringify(attributes)
21420
+ });
21421
+ if (!response.ok) {
21422
+ throw new Error(`Failed to save attributes: ${response.status}`);
21423
+ }
21424
+ }
21425
+ function renderModal3(container, state, modalId, onClose, onSave) {
21426
+ const colors = getColors(state.theme);
21427
+ const minValue = state.minTemperature !== null ? state.minTemperature : "";
21428
+ const maxValue = state.maxTemperature !== null ? state.maxTemperature : "";
21429
+ container.innerHTML = `
21430
+ <style>
21431
+ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
21432
+ @keyframes slideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
21433
+ @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
21434
+
21435
+ #${modalId} {
21436
+ position: fixed;
21437
+ top: 0;
21438
+ left: 0;
21439
+ width: 100%;
21440
+ height: 100%;
21441
+ background: ${colors.overlay};
21442
+ z-index: 10000;
21443
+ display: flex;
21444
+ align-items: center;
21445
+ justify-content: center;
21446
+ animation: fadeIn 0.2s ease-out;
21447
+ }
21448
+
21449
+ #${modalId} .modal-content {
21450
+ background: ${colors.modalBg};
21451
+ border-radius: 16px;
21452
+ width: 90%;
21453
+ max-width: 480px;
21454
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
21455
+ border: 1px solid rgba(255, 255, 255, 0.1);
21456
+ animation: slideIn 0.3s ease-out;
21457
+ overflow: hidden;
21458
+ }
21459
+
21460
+ #${modalId} .modal-header {
21461
+ background: ${colors.headerBg};
21462
+ padding: 20px 24px;
21463
+ display: flex;
21464
+ align-items: center;
21465
+ justify-content: space-between;
21466
+ }
21467
+
21468
+ #${modalId} .modal-title {
21469
+ margin: 0;
21470
+ font-size: 18px;
21471
+ font-weight: 600;
21472
+ color: #fff;
21473
+ font-family: 'Roboto', sans-serif;
21474
+ display: flex;
21475
+ align-items: center;
21476
+ gap: 10px;
21477
+ }
21478
+
21479
+ #${modalId} .close-btn {
21480
+ width: 32px;
21481
+ height: 32px;
21482
+ background: rgba(255, 255, 255, 0.1);
21483
+ border: 1px solid rgba(255, 255, 255, 0.2);
21484
+ border-radius: 8px;
21485
+ cursor: pointer;
21486
+ display: flex;
21487
+ align-items: center;
21488
+ justify-content: center;
21489
+ transition: all 0.2s;
21490
+ color: #fff;
21491
+ font-size: 18px;
21492
+ }
21493
+
21494
+ #${modalId} .close-btn:hover {
21495
+ background: rgba(255, 68, 68, 0.25);
21496
+ border-color: rgba(255, 68, 68, 0.5);
21497
+ }
21498
+
21499
+ #${modalId} .modal-body {
21500
+ padding: 24px;
21501
+ }
21502
+
21503
+ #${modalId} .customer-info {
21504
+ margin-bottom: 24px;
21505
+ padding: 12px 16px;
21506
+ background: ${colors.inputBg};
21507
+ border-radius: 8px;
21508
+ border: 1px solid ${colors.inputBorder};
21509
+ }
21510
+
21511
+ #${modalId} .customer-label {
21512
+ font-size: 12px;
21513
+ color: ${colors.textMuted};
21514
+ margin-bottom: 4px;
21515
+ }
21516
+
21517
+ #${modalId} .customer-name {
21518
+ font-size: 16px;
21519
+ font-weight: 500;
21520
+ color: ${colors.textPrimary};
21521
+ }
21522
+
21523
+ #${modalId} .form-group {
21524
+ margin-bottom: 20px;
21525
+ }
21526
+
21527
+ #${modalId} .form-label {
21528
+ display: block;
21529
+ font-size: 14px;
21530
+ font-weight: 500;
21531
+ color: ${colors.textSecondary};
21532
+ margin-bottom: 8px;
21533
+ }
21534
+
21535
+ #${modalId} .form-input {
21536
+ width: 100%;
21537
+ padding: 12px 16px;
21538
+ font-size: 16px;
21539
+ background: ${colors.inputBg};
21540
+ border: 1px solid ${colors.inputBorder};
21541
+ border-radius: 8px;
21542
+ color: ${colors.inputText};
21543
+ outline: none;
21544
+ transition: border-color 0.2s;
21545
+ box-sizing: border-box;
21546
+ }
21547
+
21548
+ #${modalId} .form-input:focus {
21549
+ border-color: ${colors.buttonPrimary};
21550
+ }
21551
+
21552
+ #${modalId} .form-input::placeholder {
21553
+ color: ${colors.textMuted};
21554
+ }
21555
+
21556
+ #${modalId} .form-hint {
21557
+ font-size: 12px;
21558
+ color: ${colors.textMuted};
21559
+ margin-top: 6px;
21560
+ }
21561
+
21562
+ #${modalId} .temperature-range {
21563
+ display: grid;
21564
+ grid-template-columns: 1fr 1fr;
21565
+ gap: 16px;
21566
+ }
21567
+
21568
+ #${modalId} .range-preview {
21569
+ margin-top: 20px;
21570
+ padding: 16px;
21571
+ background: rgba(76, 175, 80, 0.1);
21572
+ border: 1px dashed ${colors.success};
21573
+ border-radius: 8px;
21574
+ text-align: center;
21575
+ }
21576
+
21577
+ #${modalId} .range-preview-label {
21578
+ font-size: 12px;
21579
+ color: ${colors.textMuted};
21580
+ margin-bottom: 8px;
21581
+ }
21582
+
21583
+ #${modalId} .range-preview-value {
21584
+ font-size: 24px;
21585
+ font-weight: 600;
21586
+ color: ${colors.success};
21587
+ }
21588
+
21589
+ #${modalId} .modal-footer {
21590
+ padding: 16px 24px;
21591
+ border-top: 1px solid ${colors.inputBorder};
21592
+ display: flex;
21593
+ justify-content: flex-end;
21594
+ gap: 12px;
21595
+ }
21596
+
21597
+ #${modalId} .btn {
21598
+ padding: 10px 24px;
21599
+ font-size: 14px;
21600
+ font-weight: 500;
21601
+ border-radius: 8px;
21602
+ cursor: pointer;
21603
+ transition: all 0.2s;
21604
+ border: none;
21605
+ display: flex;
21606
+ align-items: center;
21607
+ gap: 8px;
21608
+ }
21609
+
21610
+ #${modalId} .btn-secondary {
21611
+ background: ${colors.buttonSecondary};
21612
+ color: ${colors.textSecondary};
21613
+ border: 1px solid ${colors.inputBorder};
21614
+ }
21615
+
21616
+ #${modalId} .btn-secondary:hover {
21617
+ background: ${colors.inputBg};
21618
+ }
21619
+
21620
+ #${modalId} .btn-primary {
21621
+ background: ${colors.buttonPrimary};
21622
+ color: #fff;
21623
+ }
21624
+
21625
+ #${modalId} .btn-primary:hover {
21626
+ background: ${colors.buttonPrimaryHover};
21627
+ }
21628
+
21629
+ #${modalId} .btn-primary:disabled {
21630
+ opacity: 0.6;
21631
+ cursor: not-allowed;
21632
+ }
21633
+
21634
+ #${modalId} .spinner {
21635
+ width: 16px;
21636
+ height: 16px;
21637
+ border: 2px solid rgba(255,255,255,0.3);
21638
+ border-top-color: #fff;
21639
+ border-radius: 50%;
21640
+ animation: spin 1s linear infinite;
21641
+ }
21642
+
21643
+ #${modalId} .message {
21644
+ padding: 12px 16px;
21645
+ border-radius: 8px;
21646
+ margin-bottom: 16px;
21647
+ font-size: 14px;
21648
+ }
21649
+
21650
+ #${modalId} .message-error {
21651
+ background: rgba(244, 67, 54, 0.1);
21652
+ border: 1px solid ${colors.error};
21653
+ color: ${colors.error};
21654
+ }
21655
+
21656
+ #${modalId} .message-success {
21657
+ background: rgba(76, 175, 80, 0.1);
21658
+ border: 1px solid ${colors.success};
21659
+ color: ${colors.success};
21660
+ }
21661
+
21662
+ #${modalId} .loading-overlay {
21663
+ display: flex;
21664
+ flex-direction: column;
21665
+ align-items: center;
21666
+ justify-content: center;
21667
+ padding: 48px;
21668
+ color: ${colors.textSecondary};
21669
+ }
21670
+
21671
+ #${modalId} .loading-spinner {
21672
+ width: 40px;
21673
+ height: 40px;
21674
+ border: 3px solid ${colors.inputBorder};
21675
+ border-top-color: ${colors.buttonPrimary};
21676
+ border-radius: 50%;
21677
+ animation: spin 1s linear infinite;
21678
+ margin-bottom: 16px;
21679
+ }
21680
+ </style>
21681
+
21682
+ <div id="${modalId}" class="modal-overlay">
21683
+ <div class="modal-content">
21684
+ <div class="modal-header">
21685
+ <h2 class="modal-title">
21686
+ <span>\u{1F321}\uFE0F</span>
21687
+ Configurar Temperatura
21688
+ </h2>
21689
+ <button class="close-btn" id="${modalId}-close">&times;</button>
21690
+ </div>
21691
+
21692
+ <div class="modal-body">
21693
+ ${state.isLoading ? `
21694
+ <div class="loading-overlay">
21695
+ <div class="loading-spinner"></div>
21696
+ <div>Carregando configura\xE7\xF5es...</div>
21697
+ </div>
21698
+ ` : `
21699
+ ${state.error ? `
21700
+ <div class="message message-error">${state.error}</div>
21701
+ ` : ""}
21702
+
21703
+ ${state.successMessage ? `
21704
+ <div class="message message-success">${state.successMessage}</div>
21705
+ ` : ""}
21706
+
21707
+ <div class="customer-info">
21708
+ <div class="customer-label">Shopping / Cliente</div>
21709
+ <div class="customer-name">${state.customerName || "N\xE3o identificado"}</div>
21710
+ </div>
21711
+
21712
+ <div class="form-group">
21713
+ <label class="form-label">Faixa de Temperatura Ideal</label>
21714
+ <div class="temperature-range">
21715
+ <div>
21716
+ <input
21717
+ type="number"
21718
+ id="${modalId}-min"
21719
+ class="form-input"
21720
+ placeholder="M\xEDnima"
21721
+ value="${minValue}"
21722
+ step="0.5"
21723
+ min="0"
21724
+ max="50"
21725
+ />
21726
+ <div class="form-hint">Temperatura m\xEDnima (\xB0C)</div>
21727
+ </div>
21728
+ <div>
21729
+ <input
21730
+ type="number"
21731
+ id="${modalId}-max"
21732
+ class="form-input"
21733
+ placeholder="M\xE1xima"
21734
+ value="${maxValue}"
21735
+ step="0.5"
21736
+ min="0"
21737
+ max="50"
21738
+ />
21739
+ <div class="form-hint">Temperatura m\xE1xima (\xB0C)</div>
21740
+ </div>
21741
+ </div>
21742
+ </div>
21743
+
21744
+ <div class="range-preview" id="${modalId}-preview">
21745
+ <div class="range-preview-label">Faixa configurada</div>
21746
+ <div class="range-preview-value" id="${modalId}-preview-value">
21747
+ ${minValue && maxValue ? `${minValue}\xB0C - ${maxValue}\xB0C` : "N\xE3o definida"}
21748
+ </div>
21749
+ </div>
21750
+ `}
21751
+ </div>
21752
+
21753
+ ${!state.isLoading ? `
21754
+ <div class="modal-footer">
21755
+ <button class="btn btn-secondary" id="${modalId}-cancel">Cancelar</button>
21756
+ <button class="btn btn-primary" id="${modalId}-save" ${state.isSaving ? "disabled" : ""}>
21757
+ ${state.isSaving ? '<div class="spinner"></div> Salvando...' : "Salvar"}
21758
+ </button>
21759
+ </div>
21760
+ ` : ""}
21761
+ </div>
21762
+ </div>
21763
+ `;
21764
+ const closeBtn = document.getElementById(`${modalId}-close`);
21765
+ const cancelBtn = document.getElementById(`${modalId}-cancel`);
21766
+ const saveBtn = document.getElementById(`${modalId}-save`);
21767
+ const minInput = document.getElementById(`${modalId}-min`);
21768
+ const maxInput = document.getElementById(`${modalId}-max`);
21769
+ const previewValue = document.getElementById(`${modalId}-preview-value`);
21770
+ const overlay = document.getElementById(modalId);
21771
+ closeBtn?.addEventListener("click", onClose);
21772
+ cancelBtn?.addEventListener("click", onClose);
21773
+ overlay?.addEventListener("click", (e) => {
21774
+ if (e.target === overlay) onClose();
21775
+ });
21776
+ const updatePreview = () => {
21777
+ if (previewValue && minInput && maxInput) {
21778
+ const min = minInput.value;
21779
+ const max = maxInput.value;
21780
+ if (min && max) {
21781
+ previewValue.textContent = `${min}\xB0C - ${max}\xB0C`;
21782
+ } else {
21783
+ previewValue.textContent = "N\xE3o definida";
21784
+ }
21785
+ }
21786
+ };
21787
+ minInput?.addEventListener("input", updatePreview);
21788
+ maxInput?.addEventListener("input", updatePreview);
21789
+ saveBtn?.addEventListener("click", async () => {
21790
+ if (!minInput || !maxInput) return;
21791
+ const min = parseFloat(minInput.value);
21792
+ const max = parseFloat(maxInput.value);
21793
+ if (isNaN(min) || isNaN(max)) {
21794
+ state.error = "Por favor, preencha ambos os valores.";
21795
+ renderModal3(container, state, modalId, onClose, onSave);
21796
+ return;
21797
+ }
21798
+ if (min >= max) {
21799
+ state.error = "A temperatura m\xEDnima deve ser menor que a m\xE1xima.";
21800
+ renderModal3(container, state, modalId, onClose, onSave);
21801
+ return;
21802
+ }
21803
+ if (min < 0 || max > 50) {
21804
+ state.error = "Os valores devem estar entre 0\xB0C e 50\xB0C.";
21805
+ renderModal3(container, state, modalId, onClose, onSave);
21806
+ return;
21807
+ }
21808
+ await onSave(min, max);
21809
+ });
21810
+ }
21811
+ function openTemperatureSettingsModal(params) {
21812
+ const modalId = `myio-temp-settings-${Date.now()}`;
21813
+ const state = {
21814
+ customerId: params.customerId,
21815
+ customerName: params.customerName || "",
21816
+ token: params.token,
21817
+ theme: params.theme || "dark",
21818
+ minTemperature: null,
21819
+ maxTemperature: null,
21820
+ isLoading: true,
21821
+ isSaving: false,
21822
+ error: null,
21823
+ successMessage: null
21824
+ };
21825
+ const container = document.createElement("div");
21826
+ container.id = `${modalId}-container`;
21827
+ document.body.appendChild(container);
21828
+ const destroy = () => {
21829
+ container.remove();
21830
+ params.onClose?.();
21831
+ };
21832
+ const handleSave = async (min, max) => {
21833
+ state.isSaving = true;
21834
+ state.error = null;
21835
+ state.successMessage = null;
21836
+ renderModal3(container, state, modalId, destroy, handleSave);
21837
+ try {
21838
+ await saveCustomerAttributes(state.customerId, state.token, min, max);
21839
+ state.minTemperature = min;
21840
+ state.maxTemperature = max;
21841
+ state.isSaving = false;
21842
+ state.successMessage = "Configura\xE7\xF5es salvas com sucesso!";
21843
+ renderModal3(container, state, modalId, destroy, handleSave);
21844
+ params.onSave?.({ minTemperature: min, maxTemperature: max });
21845
+ setTimeout(() => {
21846
+ destroy();
21847
+ }, 1500);
21848
+ } catch (error) {
21849
+ state.isSaving = false;
21850
+ state.error = `Erro ao salvar: ${error.message}`;
21851
+ renderModal3(container, state, modalId, destroy, handleSave);
21852
+ }
21853
+ };
21854
+ renderModal3(container, state, modalId, destroy, handleSave);
21855
+ fetchCustomerAttributes(state.customerId, state.token).then(({ minTemperature, maxTemperature }) => {
21856
+ state.minTemperature = minTemperature;
21857
+ state.maxTemperature = maxTemperature;
21858
+ state.isLoading = false;
21859
+ renderModal3(container, state, modalId, destroy, handleSave);
21860
+ }).catch((error) => {
21861
+ state.isLoading = false;
21862
+ state.error = `Erro ao carregar: ${error.message}`;
21863
+ renderModal3(container, state, modalId, destroy, handleSave);
21864
+ });
21865
+ return { destroy };
21866
+ }
21264
21867
  export {
21265
21868
  CHART_COLORS,
21266
21869
  ConnectionStatusType,
@@ -21349,6 +21952,7 @@ export {
21349
21952
  openRealTimeTelemetryModal,
21350
21953
  openTemperatureComparisonModal,
21351
21954
  openTemperatureModal,
21955
+ openTemperatureSettingsModal,
21352
21956
  parseInputDateToDate,
21353
21957
  renderCardComponent,
21354
21958
  renderCardComponent2 as renderCardComponentEnhanced,