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.
@@ -17972,13 +17972,13 @@ ${rangeText}`;
17972
17972
  function initializeModal() {
17973
17973
  if (data) {
17974
17974
  modalState.goalsData = data;
17975
- renderModal3();
17975
+ renderModal4();
17976
17976
  } else {
17977
- renderModal3();
17977
+ renderModal4();
17978
17978
  loadGoalsData();
17979
17979
  }
17980
17980
  }
17981
- function renderModal3() {
17981
+ function renderModal4() {
17982
17982
  const existing = document.getElementById("myio-goals-panel-modal");
17983
17983
  if (existing) {
17984
17984
  existing.remove();
@@ -19978,8 +19978,12 @@ ${rangeText}`;
19978
19978
  const paddingBottom = 55;
19979
19979
  const isPeriodsFiltered = state.selectedPeriods.length < 4 && state.selectedPeriods.length > 0;
19980
19980
  const values = chartData.map((d) => d.y);
19981
- const minY = Math.min(...values) - 1;
19982
- const maxY = Math.max(...values) + 1;
19981
+ const dataMin = Math.min(...values);
19982
+ const dataMax = Math.max(...values);
19983
+ const thresholdMin = state.temperatureMin !== null ? state.temperatureMin : dataMin;
19984
+ const thresholdMax = state.temperatureMax !== null ? state.temperatureMax : dataMax;
19985
+ const minY = Math.min(dataMin, thresholdMin) - 1;
19986
+ const maxY = Math.max(dataMax, thresholdMax) + 1;
19983
19987
  const chartWidth = width - paddingLeft - paddingRight;
19984
19988
  const chartHeight = height - paddingTop - paddingBottom;
19985
19989
  const scaleY = chartHeight / (maxY - minY || 1);
@@ -20320,8 +20324,10 @@ ${rangeText}`;
20320
20324
  deviceData: [],
20321
20325
  isLoading: true,
20322
20326
  dateRangePicker: null,
20323
- selectedPeriods: ["madrugada", "manha", "tarde", "noite"]
20327
+ selectedPeriods: ["madrugada", "manha", "tarde", "noite"],
20324
20328
  // All periods selected by default
20329
+ temperatureMin: params.temperatureMin ?? null,
20330
+ temperatureMax: params.temperatureMax ?? null
20325
20331
  };
20326
20332
  const savedGranularity = localStorage.getItem("myio-temp-comparison-granularity");
20327
20333
  const savedTheme = localStorage.getItem("myio-temp-comparison-theme");
@@ -20717,16 +20723,52 @@ ${rangeText}`;
20717
20723
  return;
20718
20724
  }
20719
20725
  const isPeriodsFiltered = state.selectedPeriods.length < 4 && state.selectedPeriods.length > 0;
20720
- let globalMinY = Infinity;
20721
- let globalMaxY = -Infinity;
20726
+ let dataMinY = Infinity;
20727
+ let dataMaxY = -Infinity;
20722
20728
  processedData.forEach(({ points }) => {
20723
20729
  points.forEach((point) => {
20724
- if (point.y < globalMinY) globalMinY = point.y;
20725
- if (point.y > globalMaxY) globalMaxY = point.y;
20730
+ if (point.y < dataMinY) dataMinY = point.y;
20731
+ if (point.y > dataMaxY) dataMaxY = point.y;
20732
+ });
20733
+ });
20734
+ const rangeMap = /* @__PURE__ */ new Map();
20735
+ state.deviceData.forEach((dd, index) => {
20736
+ const device = dd.device;
20737
+ const min = device.temperatureMin;
20738
+ const max = device.temperatureMax;
20739
+ if (min !== void 0 && min !== null && max !== void 0 && max !== null) {
20740
+ const key = `${min}-${max}`;
20741
+ if (!rangeMap.has(key)) {
20742
+ rangeMap.set(key, {
20743
+ min,
20744
+ max,
20745
+ customerName: device.customerName || "",
20746
+ color: CHART_COLORS[index % CHART_COLORS.length],
20747
+ deviceLabels: [device.label]
20748
+ });
20749
+ } else {
20750
+ rangeMap.get(key).deviceLabels.push(device.label);
20751
+ }
20752
+ }
20753
+ });
20754
+ if (rangeMap.size === 0 && state.temperatureMin !== null && state.temperatureMax !== null) {
20755
+ rangeMap.set("global", {
20756
+ min: state.temperatureMin,
20757
+ max: state.temperatureMax,
20758
+ customerName: "Global",
20759
+ color: colors.success,
20760
+ deviceLabels: []
20726
20761
  });
20762
+ }
20763
+ const temperatureRanges = Array.from(rangeMap.values());
20764
+ let thresholdMinY = dataMinY;
20765
+ let thresholdMaxY = dataMaxY;
20766
+ temperatureRanges.forEach((range) => {
20767
+ if (range.min < thresholdMinY) thresholdMinY = range.min;
20768
+ if (range.max > thresholdMaxY) thresholdMaxY = range.max;
20727
20769
  });
20728
- globalMinY = Math.floor(globalMinY) - 1;
20729
- globalMaxY = Math.ceil(globalMaxY) + 1;
20770
+ const globalMinY = Math.floor(Math.min(dataMinY, thresholdMinY)) - 1;
20771
+ const globalMaxY = Math.ceil(Math.max(dataMaxY, thresholdMaxY)) + 1;
20730
20772
  const chartWidth = width - paddingLeft - paddingRight;
20731
20773
  const chartHeight = height - paddingTop - paddingBottom;
20732
20774
  const scaleY = chartHeight / (globalMaxY - globalMinY || 1);
@@ -20766,6 +20808,41 @@ ${rangeText}`;
20766
20808
  ctx.lineTo(width - paddingRight, y);
20767
20809
  ctx.stroke();
20768
20810
  }
20811
+ const rangeColors = [
20812
+ { fill: "rgba(76, 175, 80, 0.12)", stroke: "#4CAF50" },
20813
+ // Green
20814
+ { fill: "rgba(33, 150, 243, 0.12)", stroke: "#2196F3" },
20815
+ // Blue
20816
+ { fill: "rgba(255, 152, 0, 0.12)", stroke: "#FF9800" },
20817
+ // Orange
20818
+ { fill: "rgba(156, 39, 176, 0.12)", stroke: "#9C27B0" }
20819
+ // Purple
20820
+ ];
20821
+ temperatureRanges.forEach((range, index) => {
20822
+ const rangeMinY = height - paddingBottom - (range.min - globalMinY) * scaleY;
20823
+ const rangeMaxY = height - paddingBottom - (range.max - globalMinY) * scaleY;
20824
+ const colorSet = rangeColors[index % rangeColors.length];
20825
+ ctx.fillStyle = colorSet.fill;
20826
+ ctx.fillRect(paddingLeft, rangeMaxY, chartWidth, rangeMinY - rangeMaxY);
20827
+ ctx.strokeStyle = colorSet.stroke;
20828
+ ctx.lineWidth = 1.5;
20829
+ ctx.setLineDash([6, 4]);
20830
+ ctx.beginPath();
20831
+ ctx.moveTo(paddingLeft, rangeMinY);
20832
+ ctx.lineTo(width - paddingRight, rangeMinY);
20833
+ ctx.moveTo(paddingLeft, rangeMaxY);
20834
+ ctx.lineTo(width - paddingRight, rangeMaxY);
20835
+ ctx.stroke();
20836
+ ctx.setLineDash([]);
20837
+ if (temperatureRanges.length > 1 || range.customerName) {
20838
+ ctx.fillStyle = colorSet.stroke;
20839
+ ctx.font = "10px system-ui, sans-serif";
20840
+ ctx.textAlign = "left";
20841
+ const labelY = (rangeMinY + rangeMaxY) / 2;
20842
+ const labelText = range.customerName || `${range.min}\xB0-${range.max}\xB0C`;
20843
+ ctx.fillText(labelText, width - paddingRight + 5, labelY + 3);
20844
+ }
20845
+ });
20769
20846
  processedData.forEach(({ device, points }) => {
20770
20847
  ctx.strokeStyle = device.color;
20771
20848
  ctx.lineWidth = 2.5;
@@ -21086,6 +21163,532 @@ ${rangeText}`;
21086
21163
  URL.revokeObjectURL(url);
21087
21164
  }
21088
21165
 
21166
+ // src/components/temperature/TemperatureSettingsModal.ts
21167
+ var DARK_THEME2 = {
21168
+ modalBg: "linear-gradient(180deg, #1e1e2e 0%, #151521 100%)",
21169
+ headerBg: "#3e1a7d",
21170
+ textPrimary: "#ffffff",
21171
+ textSecondary: "rgba(255, 255, 255, 0.7)",
21172
+ textMuted: "rgba(255, 255, 255, 0.5)",
21173
+ inputBg: "rgba(255, 255, 255, 0.08)",
21174
+ inputBorder: "rgba(255, 255, 255, 0.2)",
21175
+ inputText: "#ffffff",
21176
+ buttonPrimary: "#3e1a7d",
21177
+ buttonPrimaryHover: "#5a2da8",
21178
+ buttonSecondary: "rgba(255, 255, 255, 0.1)",
21179
+ success: "#4CAF50",
21180
+ error: "#f44336",
21181
+ overlay: "rgba(0, 0, 0, 0.85)"
21182
+ };
21183
+ var LIGHT_THEME2 = {
21184
+ modalBg: "#ffffff",
21185
+ headerBg: "#3e1a7d",
21186
+ textPrimary: "#1a1a2e",
21187
+ textSecondary: "rgba(0, 0, 0, 0.7)",
21188
+ textMuted: "rgba(0, 0, 0, 0.5)",
21189
+ inputBg: "#f5f5f5",
21190
+ inputBorder: "rgba(0, 0, 0, 0.2)",
21191
+ inputText: "#1a1a2e",
21192
+ buttonPrimary: "#3e1a7d",
21193
+ buttonPrimaryHover: "#5a2da8",
21194
+ buttonSecondary: "rgba(0, 0, 0, 0.05)",
21195
+ success: "#4CAF50",
21196
+ error: "#f44336",
21197
+ overlay: "rgba(0, 0, 0, 0.5)"
21198
+ };
21199
+ function getColors(theme) {
21200
+ return theme === "dark" ? DARK_THEME2 : LIGHT_THEME2;
21201
+ }
21202
+ async function fetchCustomerAttributes(customerId, token) {
21203
+ const url = `/api/plugins/telemetry/CUSTOMER/${customerId}/values/attributes/SERVER_SCOPE`;
21204
+ const response = await fetch(url, {
21205
+ method: "GET",
21206
+ headers: {
21207
+ "Content-Type": "application/json",
21208
+ "X-Authorization": `Bearer ${token}`
21209
+ }
21210
+ });
21211
+ if (!response.ok) {
21212
+ if (response.status === 404 || response.status === 400) {
21213
+ return { minTemperature: null, maxTemperature: null };
21214
+ }
21215
+ throw new Error(`Failed to fetch attributes: ${response.status}`);
21216
+ }
21217
+ const attributes = await response.json();
21218
+ let minTemperature = null;
21219
+ let maxTemperature = null;
21220
+ if (Array.isArray(attributes)) {
21221
+ for (const attr of attributes) {
21222
+ if (attr.key === "minTemperature") {
21223
+ minTemperature = Number(attr.value);
21224
+ } else if (attr.key === "maxTemperature") {
21225
+ maxTemperature = Number(attr.value);
21226
+ }
21227
+ }
21228
+ }
21229
+ return { minTemperature, maxTemperature };
21230
+ }
21231
+ async function saveCustomerAttributes(customerId, token, minTemperature, maxTemperature) {
21232
+ const url = `/api/plugins/telemetry/CUSTOMER/${customerId}/SERVER_SCOPE`;
21233
+ const attributes = {
21234
+ minTemperature,
21235
+ maxTemperature
21236
+ };
21237
+ const response = await fetch(url, {
21238
+ method: "POST",
21239
+ headers: {
21240
+ "Content-Type": "application/json",
21241
+ "X-Authorization": `Bearer ${token}`
21242
+ },
21243
+ body: JSON.stringify(attributes)
21244
+ });
21245
+ if (!response.ok) {
21246
+ throw new Error(`Failed to save attributes: ${response.status}`);
21247
+ }
21248
+ }
21249
+ function renderModal3(container, state, modalId, onClose, onSave) {
21250
+ const colors = getColors(state.theme);
21251
+ const minValue = state.minTemperature !== null ? state.minTemperature : "";
21252
+ const maxValue = state.maxTemperature !== null ? state.maxTemperature : "";
21253
+ container.innerHTML = `
21254
+ <style>
21255
+ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
21256
+ @keyframes slideIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
21257
+ @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
21258
+
21259
+ #${modalId} {
21260
+ position: fixed;
21261
+ top: 0;
21262
+ left: 0;
21263
+ width: 100%;
21264
+ height: 100%;
21265
+ background: ${colors.overlay};
21266
+ z-index: 10000;
21267
+ display: flex;
21268
+ align-items: center;
21269
+ justify-content: center;
21270
+ animation: fadeIn 0.2s ease-out;
21271
+ }
21272
+
21273
+ #${modalId} .modal-content {
21274
+ background: ${colors.modalBg};
21275
+ border-radius: 16px;
21276
+ width: 90%;
21277
+ max-width: 480px;
21278
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
21279
+ border: 1px solid rgba(255, 255, 255, 0.1);
21280
+ animation: slideIn 0.3s ease-out;
21281
+ overflow: hidden;
21282
+ }
21283
+
21284
+ #${modalId} .modal-header {
21285
+ background: ${colors.headerBg};
21286
+ padding: 20px 24px;
21287
+ display: flex;
21288
+ align-items: center;
21289
+ justify-content: space-between;
21290
+ }
21291
+
21292
+ #${modalId} .modal-title {
21293
+ margin: 0;
21294
+ font-size: 18px;
21295
+ font-weight: 600;
21296
+ color: #fff;
21297
+ font-family: 'Roboto', sans-serif;
21298
+ display: flex;
21299
+ align-items: center;
21300
+ gap: 10px;
21301
+ }
21302
+
21303
+ #${modalId} .close-btn {
21304
+ width: 32px;
21305
+ height: 32px;
21306
+ background: rgba(255, 255, 255, 0.1);
21307
+ border: 1px solid rgba(255, 255, 255, 0.2);
21308
+ border-radius: 8px;
21309
+ cursor: pointer;
21310
+ display: flex;
21311
+ align-items: center;
21312
+ justify-content: center;
21313
+ transition: all 0.2s;
21314
+ color: #fff;
21315
+ font-size: 18px;
21316
+ }
21317
+
21318
+ #${modalId} .close-btn:hover {
21319
+ background: rgba(255, 68, 68, 0.25);
21320
+ border-color: rgba(255, 68, 68, 0.5);
21321
+ }
21322
+
21323
+ #${modalId} .modal-body {
21324
+ padding: 24px;
21325
+ }
21326
+
21327
+ #${modalId} .customer-info {
21328
+ margin-bottom: 24px;
21329
+ padding: 12px 16px;
21330
+ background: ${colors.inputBg};
21331
+ border-radius: 8px;
21332
+ border: 1px solid ${colors.inputBorder};
21333
+ }
21334
+
21335
+ #${modalId} .customer-label {
21336
+ font-size: 12px;
21337
+ color: ${colors.textMuted};
21338
+ margin-bottom: 4px;
21339
+ }
21340
+
21341
+ #${modalId} .customer-name {
21342
+ font-size: 16px;
21343
+ font-weight: 500;
21344
+ color: ${colors.textPrimary};
21345
+ }
21346
+
21347
+ #${modalId} .form-group {
21348
+ margin-bottom: 20px;
21349
+ }
21350
+
21351
+ #${modalId} .form-label {
21352
+ display: block;
21353
+ font-size: 14px;
21354
+ font-weight: 500;
21355
+ color: ${colors.textSecondary};
21356
+ margin-bottom: 8px;
21357
+ }
21358
+
21359
+ #${modalId} .form-input {
21360
+ width: 100%;
21361
+ padding: 12px 16px;
21362
+ font-size: 16px;
21363
+ background: ${colors.inputBg};
21364
+ border: 1px solid ${colors.inputBorder};
21365
+ border-radius: 8px;
21366
+ color: ${colors.inputText};
21367
+ outline: none;
21368
+ transition: border-color 0.2s;
21369
+ box-sizing: border-box;
21370
+ }
21371
+
21372
+ #${modalId} .form-input:focus {
21373
+ border-color: ${colors.buttonPrimary};
21374
+ }
21375
+
21376
+ #${modalId} .form-input::placeholder {
21377
+ color: ${colors.textMuted};
21378
+ }
21379
+
21380
+ #${modalId} .form-hint {
21381
+ font-size: 12px;
21382
+ color: ${colors.textMuted};
21383
+ margin-top: 6px;
21384
+ }
21385
+
21386
+ #${modalId} .temperature-range {
21387
+ display: grid;
21388
+ grid-template-columns: 1fr 1fr;
21389
+ gap: 16px;
21390
+ }
21391
+
21392
+ #${modalId} .range-preview {
21393
+ margin-top: 20px;
21394
+ padding: 16px;
21395
+ background: rgba(76, 175, 80, 0.1);
21396
+ border: 1px dashed ${colors.success};
21397
+ border-radius: 8px;
21398
+ text-align: center;
21399
+ }
21400
+
21401
+ #${modalId} .range-preview-label {
21402
+ font-size: 12px;
21403
+ color: ${colors.textMuted};
21404
+ margin-bottom: 8px;
21405
+ }
21406
+
21407
+ #${modalId} .range-preview-value {
21408
+ font-size: 24px;
21409
+ font-weight: 600;
21410
+ color: ${colors.success};
21411
+ }
21412
+
21413
+ #${modalId} .modal-footer {
21414
+ padding: 16px 24px;
21415
+ border-top: 1px solid ${colors.inputBorder};
21416
+ display: flex;
21417
+ justify-content: flex-end;
21418
+ gap: 12px;
21419
+ }
21420
+
21421
+ #${modalId} .btn {
21422
+ padding: 10px 24px;
21423
+ font-size: 14px;
21424
+ font-weight: 500;
21425
+ border-radius: 8px;
21426
+ cursor: pointer;
21427
+ transition: all 0.2s;
21428
+ border: none;
21429
+ display: flex;
21430
+ align-items: center;
21431
+ gap: 8px;
21432
+ }
21433
+
21434
+ #${modalId} .btn-secondary {
21435
+ background: ${colors.buttonSecondary};
21436
+ color: ${colors.textSecondary};
21437
+ border: 1px solid ${colors.inputBorder};
21438
+ }
21439
+
21440
+ #${modalId} .btn-secondary:hover {
21441
+ background: ${colors.inputBg};
21442
+ }
21443
+
21444
+ #${modalId} .btn-primary {
21445
+ background: ${colors.buttonPrimary};
21446
+ color: #fff;
21447
+ }
21448
+
21449
+ #${modalId} .btn-primary:hover {
21450
+ background: ${colors.buttonPrimaryHover};
21451
+ }
21452
+
21453
+ #${modalId} .btn-primary:disabled {
21454
+ opacity: 0.6;
21455
+ cursor: not-allowed;
21456
+ }
21457
+
21458
+ #${modalId} .spinner {
21459
+ width: 16px;
21460
+ height: 16px;
21461
+ border: 2px solid rgba(255,255,255,0.3);
21462
+ border-top-color: #fff;
21463
+ border-radius: 50%;
21464
+ animation: spin 1s linear infinite;
21465
+ }
21466
+
21467
+ #${modalId} .message {
21468
+ padding: 12px 16px;
21469
+ border-radius: 8px;
21470
+ margin-bottom: 16px;
21471
+ font-size: 14px;
21472
+ }
21473
+
21474
+ #${modalId} .message-error {
21475
+ background: rgba(244, 67, 54, 0.1);
21476
+ border: 1px solid ${colors.error};
21477
+ color: ${colors.error};
21478
+ }
21479
+
21480
+ #${modalId} .message-success {
21481
+ background: rgba(76, 175, 80, 0.1);
21482
+ border: 1px solid ${colors.success};
21483
+ color: ${colors.success};
21484
+ }
21485
+
21486
+ #${modalId} .loading-overlay {
21487
+ display: flex;
21488
+ flex-direction: column;
21489
+ align-items: center;
21490
+ justify-content: center;
21491
+ padding: 48px;
21492
+ color: ${colors.textSecondary};
21493
+ }
21494
+
21495
+ #${modalId} .loading-spinner {
21496
+ width: 40px;
21497
+ height: 40px;
21498
+ border: 3px solid ${colors.inputBorder};
21499
+ border-top-color: ${colors.buttonPrimary};
21500
+ border-radius: 50%;
21501
+ animation: spin 1s linear infinite;
21502
+ margin-bottom: 16px;
21503
+ }
21504
+ </style>
21505
+
21506
+ <div id="${modalId}" class="modal-overlay">
21507
+ <div class="modal-content">
21508
+ <div class="modal-header">
21509
+ <h2 class="modal-title">
21510
+ <span>\u{1F321}\uFE0F</span>
21511
+ Configurar Temperatura
21512
+ </h2>
21513
+ <button class="close-btn" id="${modalId}-close">&times;</button>
21514
+ </div>
21515
+
21516
+ <div class="modal-body">
21517
+ ${state.isLoading ? `
21518
+ <div class="loading-overlay">
21519
+ <div class="loading-spinner"></div>
21520
+ <div>Carregando configura\xE7\xF5es...</div>
21521
+ </div>
21522
+ ` : `
21523
+ ${state.error ? `
21524
+ <div class="message message-error">${state.error}</div>
21525
+ ` : ""}
21526
+
21527
+ ${state.successMessage ? `
21528
+ <div class="message message-success">${state.successMessage}</div>
21529
+ ` : ""}
21530
+
21531
+ <div class="customer-info">
21532
+ <div class="customer-label">Shopping / Cliente</div>
21533
+ <div class="customer-name">${state.customerName || "N\xE3o identificado"}</div>
21534
+ </div>
21535
+
21536
+ <div class="form-group">
21537
+ <label class="form-label">Faixa de Temperatura Ideal</label>
21538
+ <div class="temperature-range">
21539
+ <div>
21540
+ <input
21541
+ type="number"
21542
+ id="${modalId}-min"
21543
+ class="form-input"
21544
+ placeholder="M\xEDnima"
21545
+ value="${minValue}"
21546
+ step="0.5"
21547
+ min="0"
21548
+ max="50"
21549
+ />
21550
+ <div class="form-hint">Temperatura m\xEDnima (\xB0C)</div>
21551
+ </div>
21552
+ <div>
21553
+ <input
21554
+ type="number"
21555
+ id="${modalId}-max"
21556
+ class="form-input"
21557
+ placeholder="M\xE1xima"
21558
+ value="${maxValue}"
21559
+ step="0.5"
21560
+ min="0"
21561
+ max="50"
21562
+ />
21563
+ <div class="form-hint">Temperatura m\xE1xima (\xB0C)</div>
21564
+ </div>
21565
+ </div>
21566
+ </div>
21567
+
21568
+ <div class="range-preview" id="${modalId}-preview">
21569
+ <div class="range-preview-label">Faixa configurada</div>
21570
+ <div class="range-preview-value" id="${modalId}-preview-value">
21571
+ ${minValue && maxValue ? `${minValue}\xB0C - ${maxValue}\xB0C` : "N\xE3o definida"}
21572
+ </div>
21573
+ </div>
21574
+ `}
21575
+ </div>
21576
+
21577
+ ${!state.isLoading ? `
21578
+ <div class="modal-footer">
21579
+ <button class="btn btn-secondary" id="${modalId}-cancel">Cancelar</button>
21580
+ <button class="btn btn-primary" id="${modalId}-save" ${state.isSaving ? "disabled" : ""}>
21581
+ ${state.isSaving ? '<div class="spinner"></div> Salvando...' : "Salvar"}
21582
+ </button>
21583
+ </div>
21584
+ ` : ""}
21585
+ </div>
21586
+ </div>
21587
+ `;
21588
+ const closeBtn = document.getElementById(`${modalId}-close`);
21589
+ const cancelBtn = document.getElementById(`${modalId}-cancel`);
21590
+ const saveBtn = document.getElementById(`${modalId}-save`);
21591
+ const minInput = document.getElementById(`${modalId}-min`);
21592
+ const maxInput = document.getElementById(`${modalId}-max`);
21593
+ const previewValue = document.getElementById(`${modalId}-preview-value`);
21594
+ const overlay = document.getElementById(modalId);
21595
+ closeBtn?.addEventListener("click", onClose);
21596
+ cancelBtn?.addEventListener("click", onClose);
21597
+ overlay?.addEventListener("click", (e) => {
21598
+ if (e.target === overlay) onClose();
21599
+ });
21600
+ const updatePreview = () => {
21601
+ if (previewValue && minInput && maxInput) {
21602
+ const min = minInput.value;
21603
+ const max = maxInput.value;
21604
+ if (min && max) {
21605
+ previewValue.textContent = `${min}\xB0C - ${max}\xB0C`;
21606
+ } else {
21607
+ previewValue.textContent = "N\xE3o definida";
21608
+ }
21609
+ }
21610
+ };
21611
+ minInput?.addEventListener("input", updatePreview);
21612
+ maxInput?.addEventListener("input", updatePreview);
21613
+ saveBtn?.addEventListener("click", async () => {
21614
+ if (!minInput || !maxInput) return;
21615
+ const min = parseFloat(minInput.value);
21616
+ const max = parseFloat(maxInput.value);
21617
+ if (isNaN(min) || isNaN(max)) {
21618
+ state.error = "Por favor, preencha ambos os valores.";
21619
+ renderModal3(container, state, modalId, onClose, onSave);
21620
+ return;
21621
+ }
21622
+ if (min >= max) {
21623
+ state.error = "A temperatura m\xEDnima deve ser menor que a m\xE1xima.";
21624
+ renderModal3(container, state, modalId, onClose, onSave);
21625
+ return;
21626
+ }
21627
+ if (min < 0 || max > 50) {
21628
+ state.error = "Os valores devem estar entre 0\xB0C e 50\xB0C.";
21629
+ renderModal3(container, state, modalId, onClose, onSave);
21630
+ return;
21631
+ }
21632
+ await onSave(min, max);
21633
+ });
21634
+ }
21635
+ function openTemperatureSettingsModal(params) {
21636
+ const modalId = `myio-temp-settings-${Date.now()}`;
21637
+ const state = {
21638
+ customerId: params.customerId,
21639
+ customerName: params.customerName || "",
21640
+ token: params.token,
21641
+ theme: params.theme || "dark",
21642
+ minTemperature: null,
21643
+ maxTemperature: null,
21644
+ isLoading: true,
21645
+ isSaving: false,
21646
+ error: null,
21647
+ successMessage: null
21648
+ };
21649
+ const container = document.createElement("div");
21650
+ container.id = `${modalId}-container`;
21651
+ document.body.appendChild(container);
21652
+ const destroy = () => {
21653
+ container.remove();
21654
+ params.onClose?.();
21655
+ };
21656
+ const handleSave = async (min, max) => {
21657
+ state.isSaving = true;
21658
+ state.error = null;
21659
+ state.successMessage = null;
21660
+ renderModal3(container, state, modalId, destroy, handleSave);
21661
+ try {
21662
+ await saveCustomerAttributes(state.customerId, state.token, min, max);
21663
+ state.minTemperature = min;
21664
+ state.maxTemperature = max;
21665
+ state.isSaving = false;
21666
+ state.successMessage = "Configura\xE7\xF5es salvas com sucesso!";
21667
+ renderModal3(container, state, modalId, destroy, handleSave);
21668
+ params.onSave?.({ minTemperature: min, maxTemperature: max });
21669
+ setTimeout(() => {
21670
+ destroy();
21671
+ }, 1500);
21672
+ } catch (error) {
21673
+ state.isSaving = false;
21674
+ state.error = `Erro ao salvar: ${error.message}`;
21675
+ renderModal3(container, state, modalId, destroy, handleSave);
21676
+ }
21677
+ };
21678
+ renderModal3(container, state, modalId, destroy, handleSave);
21679
+ fetchCustomerAttributes(state.customerId, state.token).then(({ minTemperature, maxTemperature }) => {
21680
+ state.minTemperature = minTemperature;
21681
+ state.maxTemperature = maxTemperature;
21682
+ state.isLoading = false;
21683
+ renderModal3(container, state, modalId, destroy, handleSave);
21684
+ }).catch((error) => {
21685
+ state.isLoading = false;
21686
+ state.error = `Erro ao carregar: ${error.message}`;
21687
+ renderModal3(container, state, modalId, destroy, handleSave);
21688
+ });
21689
+ return { destroy };
21690
+ }
21691
+
21089
21692
  exports.CHART_COLORS = CHART_COLORS;
21090
21693
  exports.ConnectionStatusType = ConnectionStatusType;
21091
21694
  exports.DEFAULT_CLAMP_RANGE = DEFAULT_CLAMP_RANGE;
@@ -21172,6 +21775,7 @@ ${rangeText}`;
21172
21775
  exports.openRealTimeTelemetryModal = openRealTimeTelemetryModal;
21173
21776
  exports.openTemperatureComparisonModal = openTemperatureComparisonModal;
21174
21777
  exports.openTemperatureModal = openTemperatureModal;
21778
+ exports.openTemperatureSettingsModal = openTemperatureSettingsModal;
21175
21779
  exports.parseInputDateToDate = parseInputDateToDate;
21176
21780
  exports.renderCardComponent = renderCardComponent;
21177
21781
  exports.renderCardComponentEnhanced = renderCardComponent2;