citedd commited on
Commit
c318719
Β·
verified Β·
1 Parent(s): 9b18a76

Fix: use daily.time instead of daily.days

Browse files
Files changed (1) hide show
  1. public/index.html +86 -177
public/index.html CHANGED
@@ -27,7 +27,6 @@
27
  padding: 2rem 1rem 3rem;
28
  }
29
 
30
- /* ===== GLASS ===== */
31
  .glass {
32
  position: relative;
33
  background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.06) 40%, rgba(255,255,255,0.04) 60%, rgba(255,255,255,0.08) 100%);
@@ -44,91 +43,62 @@
44
  pointer-events: none;
45
  }
46
 
47
- /* ===== SEARCH ===== */
48
  .search-section { margin-bottom: 1.5rem; text-align: center; }
49
- .search-box {
50
- position: relative; max-width: 400px; margin: 0 auto;
51
- }
52
  .search-box input {
53
  width: 100%; padding: 0.85rem 1.2rem 0.85rem 2.8rem;
54
- background: rgba(255,255,255,0.1);
55
- backdrop-filter: blur(20px);
56
  -webkit-backdrop-filter: blur(20px);
57
- border: 1px solid rgba(255,255,255,0.2);
58
- border-radius: 16px;
59
- color: #fff; font-size: 0.95rem;
60
- outline: none; transition: border-color 0.3s, background 0.3s;
61
  }
62
  .search-box input::placeholder { color: rgba(255,255,255,0.4); }
63
- .search-box input:focus {
64
- border-color: rgba(255,255,255,0.4);
65
- background: rgba(255,255,255,0.15);
66
- }
67
- .search-icon {
68
- position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
69
- font-size: 1rem; opacity: 0.5; pointer-events: none;
70
- }
71
  .search-results {
72
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
73
  background: rgba(15,15,30,0.92); backdrop-filter: blur(20px);
74
  -webkit-backdrop-filter: blur(20px);
75
- border: 1px solid rgba(255,255,255,0.15);
76
- border-radius: 14px; overflow: hidden; z-index: 10;
77
- display: none;
78
  }
79
  .search-results.active { display: block; }
80
  .search-result {
81
- padding: 0.75rem 1.2rem; cursor: pointer;
82
- border-bottom: 1px solid rgba(255,255,255,0.06);
83
- font-size: 0.85rem; color: rgba(255,255,255,0.7);
84
- transition: background 0.2s;
85
  }
86
  .search-result:hover { background: rgba(255,255,255,0.08); color: #fff; }
87
  .search-result:last-child { border-bottom: none; }
88
  .search-result .country { color: rgba(255,255,255,0.35); font-size: 0.75rem; }
89
 
90
- /* ===== HEADER ===== */
91
- .weather-header {
92
- text-align: center; padding: 2rem 1.5rem;
93
- margin-bottom: 1.2rem; border-radius: 24px;
94
- }
95
  .city-name { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.25rem; }
96
  .weather-desc { font-size: 0.9rem; color: rgba(255,255,255,0.5); margin-bottom: 1rem; }
97
  .weather-icon { font-size: 4rem; margin-bottom: 0.5rem; }
98
  .current-temp {
99
  font-size: 4.5rem; font-weight: 700;
100
  background: linear-gradient(135deg, #fff 30%, rgba(255,255,255,0.7));
101
- -webkit-background-clip: text; -webkit-text-fill-color: transparent;
102
- background-clip: text;
103
  }
104
  .feels-like { font-size: 0.8rem; color: rgba(255,255,255,0.4); margin-top: 0.25rem; }
105
 
106
- /* ===== DETAIL CARDS ===== */
107
  .details {
108
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
109
  gap: 0.75rem; margin-bottom: 1.2rem;
110
  }
111
- .detail-card {
112
- padding: 1rem 0.9rem; text-align: center;
113
- }
114
- .detail-icon { font-size: 1.5rem; margin-bottom: 0.3rem; }
115
  .detail-value { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.15rem; }
116
  .detail-label { font-size: 0.63rem; color: rgba(255,255,255,0.35); text-transform: uppercase; letter-spacing: 0.06em; }
117
 
118
- /* ===== FORECAST ===== */
119
- .section-title {
120
- font-size: 0.85rem; color: rgba(255,255,255,0.5);
121
- margin-bottom: 0.6rem; padding-left: 0.2rem;
122
- }
123
- .forecast {
124
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
125
  gap: 0.6rem; padding: 1.2rem 1rem;
126
  }
127
  .forecast-day {
128
- text-align: center; padding: 0.8rem 0.4rem;
129
- border-radius: 14px;
130
- background: rgba(255,255,255,0.05);
131
- border: 1px solid rgba(255,255,255,0.06);
132
  transition: background 0.2s;
133
  }
134
  .forecast-day:hover { background: rgba(255,255,255,0.1); }
@@ -137,25 +107,16 @@
137
  .forecast-temp { font-size: 0.9rem; font-weight: 600; }
138
  .forecast-temp-low { color: rgba(255,255,255,0.35); font-size: 0.75rem; font-weight: 400; }
139
 
140
- /* ===== LOADING / ERROR ===== */
141
- .loading, .error {
142
- text-align: center; padding: 4rem 1rem;
143
- font-size: 1rem; color: rgba(255,255,255,0.5);
144
- }
145
  .error { color: #f87171; }
146
  .spinner {
147
  display: inline-block; width: 24px; height: 24px;
148
- border: 2px solid rgba(255,255,255,0.2);
149
- border-top-color: #a78bfa; border-radius: 50%;
150
- animation: spin 0.8s linear infinite;
151
- margin-bottom: 0.5rem;
152
  }
153
  @keyframes spin { to { transform: rotate(360deg); } }
154
 
155
- .footer {
156
- text-align: center; margin-top: 2.5rem;
157
- color: rgba(255,255,255,0.18); font-size: 0.68rem;
158
- }
159
  .footer a { color: rgba(167,139,250,0.4); text-decoration: none; }
160
 
161
  @media (max-width: 600px) {
@@ -163,7 +124,7 @@
163
  .current-temp { font-size: 3.5rem; }
164
  .weather-icon { font-size: 3rem; }
165
  .details { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
166
- .forecast { grid-template-columns: repeat(3, 1fr); }
167
  .weather-header { padding: 1.5rem 1rem; }
168
  }
169
  </style>
@@ -173,7 +134,6 @@
173
  <div class="bg-overlay"></div>
174
 
175
  <div class="container">
176
- <!-- Search -->
177
  <div class="search-section">
178
  <div class="search-box">
179
  <span class="search-icon">πŸ”</span>
@@ -181,15 +141,9 @@
181
  <div class="search-results" id="searchResults"></div>
182
  </div>
183
  </div>
184
-
185
- <!-- Main Content -->
186
  <div id="app">
187
- <div class="loading">
188
- <div class="spinner"></div>
189
- <div>Loading weather...</div>
190
- </div>
191
  </div>
192
-
193
  <div class="footer">
194
  Weather by <a href="https://open-meteo.com" target="_blank">Open-Meteo</a> Β· Liquid Glass Dashboard by Hedd
195
  </div>
@@ -197,32 +151,23 @@
197
 
198
  <script>
199
  const WMO = {
200
- 0: { desc: 'Cerah', icon: 'β˜€οΈ' },
201
- 1: { desc: 'Cerah Berawan', icon: '🌀️' },
202
- 2: { desc: 'Berawan', icon: 'β›…' },
203
- 3: { desc: 'Mendung', icon: '☁️' },
204
- 45: { desc: 'Kabut', icon: '🌫️' },
205
- 48: { desc: 'Kabut Tebal', icon: '🌫️' },
206
- 51: { desc: 'Gerimis Ringan', icon: '🌦️' },
207
- 53: { desc: 'Gerimis', icon: '🌦️' },
208
  55: { desc: 'Gerimis Lebat', icon: '🌧️' },
209
- 61: { desc: 'Hujan Ringan', icon: '🌧️' },
210
- 63: { desc: 'Hujan', icon: '🌧️' },
211
  65: { desc: 'Hujan Lebat', icon: 'β›ˆοΈ' },
212
- 71: { desc: 'Salju Ringan', icon: '🌨️' },
213
- 73: { desc: 'Salju', icon: '❄️' },
214
  75: { desc: 'Salju Lebat', icon: '❄️' },
215
- 80: { desc: 'Hujan Lokal', icon: '🌦️' },
216
- 81: { desc: 'Hujan Sedang', icon: '🌧️' },
217
  82: { desc: 'Hujan Deras', icon: 'β›ˆοΈ' },
218
  95: { desc: 'Badai Petir', icon: 'β›ˆοΈ' },
219
- 96: { desc: 'Badai + Hujan Es', icon: '🌩️' },
220
- 99: { desc: 'Badai + Hujan Es', icon: '🌩️' },
221
  };
222
 
223
  const DAYS = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'];
224
  let searchTimeout;
225
-
226
  const searchInput = document.getElementById('searchInput');
227
  const searchResults = document.getElementById('searchResults');
228
  const app = document.getElementById('app');
@@ -235,50 +180,37 @@
235
  });
236
 
237
  searchInput.addEventListener('keydown', (e) => {
238
- if (e.key === 'Enter') {
239
- clearTimeout(searchTimeout);
240
- const q = searchInput.value.trim();
241
- if (q.length >= 2) searchCity(q);
242
- }
243
  });
244
 
245
- document.addEventListener('click', (e) => {
246
- if (!e.target.closest('.search-box')) searchResults.classList.remove('active');
247
- });
248
 
249
  async function searchCity(query) {
250
  try {
251
- const res = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
252
  const data = await res.json();
253
  if (data.results && data.results.length > 0) {
254
  searchResults.innerHTML = data.results.slice(0, 5).map(r =>
255
- `<div class="search-result" data-lat="${r.latitude}" data-lon="${r.longitude}" data-name="${r.name}" data-country="${r.admin1 || r.country || ''}">
256
- <div>${r.name}</div>
257
- <div class="country">${r.admin1 ? r.admin1 + ', ' : ''}${r.country || ''}</div>
258
- </div>`
259
  ).join('');
260
  searchResults.classList.add('active');
261
-
262
  searchResults.querySelectorAll('.search-result').forEach(el => {
263
  el.addEventListener('click', () => {
264
  const { lat, lon, name, country } = el.dataset;
265
  searchResults.classList.remove('active');
266
  searchInput.value = name;
267
- loadWeather(parseFloat(lat), parseFloat(lon), `${name}, ${country}`);
268
  });
269
  });
270
  } else {
271
  searchResults.innerHTML = '<div class="search-result" style="opacity:0.5">Tidak ditemukan</div>';
272
  searchResults.classList.add('active');
273
  }
274
- } catch(e) {
275
- console.error('Search error:', e);
276
- }
277
  }
278
 
279
- function getWmo(code) {
280
- return WMO[code] || { desc: 'Tidak diketahui', icon: '❓' };
281
- }
282
 
283
  function formatDay(dateStr) {
284
  const d = new Date(dateStr + 'T00:00:00');
@@ -287,12 +219,14 @@
287
 
288
  function loadWeather(lat, lon, name) {
289
  app.innerHTML = '<div class="loading"><div class="spinner"></div><div>Loading weather...</div></div>';
290
-
291
- fetch(`/api/weather?lat=${lat}&lon=${lon}&name=${encodeURIComponent(name)}`)
292
  .then(r => r.json())
293
- .then(data => renderWeather(data))
 
 
 
294
  .catch(e => {
295
- app.innerHTML = `<div class="error">Gagal memuat data cuaca.<br><small>${e.message}</small></div>`;
296
  });
297
  }
298
 
@@ -302,76 +236,51 @@
302
  const wmo = getWmo(cur.weather_code);
303
  const name = data.location_name || '';
304
 
305
- const sunrise = daily.sunrise[0] ? new Date(daily.sunrise[0]).toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' }) : 'β€”';
306
- const sunset = daily.sunset[0] ? new Date(daily.sunset[0]).toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' }) : 'β€”';
 
 
 
 
307
 
308
- app.innerHTML = `
309
- <!-- Current Weather Header -->
310
- <div class="weather-header glass">
311
- <div class="city-name">${name}</div>
312
- <div class="weather-icon">${wmo.icon}</div>
313
- <div class="weather-desc">${wmo.desc}</div>
314
- <div class="current-temp">${Math.round(cur.temperature_2m)}Β°</div>
315
- <div class="feels-like">Terasa seperti ${Math.round(cur.apparent_temperature)}Β°C</div>
316
- </div>
317
 
318
- <!-- Detail Cards -->
319
- <div class="section-title">Detail</div>
320
- <div class="details">
321
- <div class="detail-card glass">
322
- <div class="detail-icon">πŸ’§</div>
323
- <div class="detail-value">${cur.relative_humidity_2m}%</div>
324
- <div class="detail-label">Kelembapan</div>
325
- </div>
326
- <div class="detail-card glass">
327
- <div class="detail-icon">πŸ’¨</div>
328
- <div class="detail-value">${Math.round(cur.wind_speed_10m)}</div>
329
- <div class="detail-label">Angin (km/h)</div>
330
- </div>
331
- <div class="detail-card glass">
332
- <div class="detail-icon">🌑️</div>
333
- <div class="detail-value">${Math.round(cur.pressure_msl)}</div>
334
- <div class="detail-label">Tekanan (hPa)</div>
335
- </div>
336
- <div class="detail-card glass">
337
- <div class="detail-icon">β˜€οΈ</div>
338
- <div class="detail-value">${cur.uv_index ?? 'β€”'}</div>
339
- <div class="detail-label">UV Index</div>
340
- </div>
341
- <div class="detail-card glass">
342
- <div class="detail-icon">πŸŒ…</div>
343
- <div class="detail-value">${sunrise}</div>
344
- <div class="detail-label">Sunrise</div>
345
- </div>
346
- <div class="detail-card glass">
347
- <div class="detail-icon">πŸŒ‡</div>
348
- <div class="detail-value">${sunset}</div>
349
- <div class="detail-label">Sunset</div>
350
- </div>
351
- </div>
352
 
353
- <!-- Forecast -->
354
- <div class="section-title">Ramalan ${daily.days.length} Hari</div>
355
- <div class="glass" style="padding: 0; margin-bottom: 1rem;">
356
- <div class="forecast">
357
- ${daily.days.map((day, i) => {
358
- const dw = getWmo(daily.weather_code[i]);
359
- const isToday = i === 0;
360
- return `
361
- <div class="forecast-day" style="${isToday ? 'background: rgba(167,139,250,0.15); border-color: rgba(167,139,250,0.3);' : ''}">
362
- <div class="forecast-name">${isToday ? 'Hari ini' : formatDay(day)}</div>
363
- <div class="forecast-icon">${dw.icon}</div>
364
- <div class="forecast-temp">${Math.round(daily.temperature_2m_max[i])}Β°</div>
365
- <div class="forecast-temp-low">${Math.round(daily.temperature_2m_min[i])}Β°</div>
366
- </div>
367
- `;
368
- }).join('')}
369
- </div>
370
- </div>
371
- `;
372
  }
373
 
374
- // Load Jakarta by default
375
  loadWeather(-6.2, 106.85, 'Jakarta, Indonesia');
376
  </script>
377
  </body>
 
27
  padding: 2rem 1rem 3rem;
28
  }
29
 
 
30
  .glass {
31
  position: relative;
32
  background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.06) 40%, rgba(255,255,255,0.04) 60%, rgba(255,255,255,0.08) 100%);
 
43
  pointer-events: none;
44
  }
45
 
 
46
  .search-section { margin-bottom: 1.5rem; text-align: center; }
47
+ .search-box { position: relative; max-width: 400px; margin: 0 auto; }
 
 
48
  .search-box input {
49
  width: 100%; padding: 0.85rem 1.2rem 0.85rem 2.8rem;
50
+ background: rgba(255,255,255,0.1); backdrop-filter: blur(20px);
 
51
  -webkit-backdrop-filter: blur(20px);
52
+ border: 1px solid rgba(255,255,255,0.2); border-radius: 16px;
53
+ color: #fff; font-size: 0.95rem; outline: none;
54
+ transition: border-color 0.3s, background 0.3s;
 
55
  }
56
  .search-box input::placeholder { color: rgba(255,255,255,0.4); }
57
+ .search-box input:focus { border-color: rgba(255,255,255,0.4); background: rgba(255,255,255,0.15); }
58
+ .search-icon { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); opacity: 0.5; pointer-events: none; }
 
 
 
 
 
 
59
  .search-results {
60
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
61
  background: rgba(15,15,30,0.92); backdrop-filter: blur(20px);
62
  -webkit-backdrop-filter: blur(20px);
63
+ border: 1px solid rgba(255,255,255,0.15); border-radius: 14px; overflow: hidden; z-index: 10; display: none;
 
 
64
  }
65
  .search-results.active { display: block; }
66
  .search-result {
67
+ padding: 0.75rem 1.2rem; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.06);
68
+ font-size: 0.85rem; color: rgba(255,255,255,0.7); transition: background 0.2s;
 
 
69
  }
70
  .search-result:hover { background: rgba(255,255,255,0.08); color: #fff; }
71
  .search-result:last-child { border-bottom: none; }
72
  .search-result .country { color: rgba(255,255,255,0.35); font-size: 0.75rem; }
73
 
74
+ .weather-header { text-align: center; padding: 2rem 1.5rem; margin-bottom: 1.2rem; border-radius: 24px; }
 
 
 
 
75
  .city-name { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.25rem; }
76
  .weather-desc { font-size: 0.9rem; color: rgba(255,255,255,0.5); margin-bottom: 1rem; }
77
  .weather-icon { font-size: 4rem; margin-bottom: 0.5rem; }
78
  .current-temp {
79
  font-size: 4.5rem; font-weight: 700;
80
  background: linear-gradient(135deg, #fff 30%, rgba(255,255,255,0.7));
81
+ -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
 
82
  }
83
  .feels-like { font-size: 0.8rem; color: rgba(255,255,255,0.4); margin-top: 0.25rem; }
84
 
 
85
  .details {
86
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
87
  gap: 0.75rem; margin-bottom: 1.2rem;
88
  }
89
+ .detail-card { padding: 1rem 0.9rem; text-align: center; }
90
+ .detail-icon-val { font-size: 1.5rem; margin-bottom: 0.3rem; }
 
 
91
  .detail-value { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.15rem; }
92
  .detail-label { font-size: 0.63rem; color: rgba(255,255,255,0.35); text-transform: uppercase; letter-spacing: 0.06em; }
93
 
94
+ .section-title { font-size: 0.85rem; color: rgba(255,255,255,0.5); margin-bottom: 0.6rem; padding-left: 0.2rem; }
95
+ .forecast-grid {
 
 
 
 
96
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
97
  gap: 0.6rem; padding: 1.2rem 1rem;
98
  }
99
  .forecast-day {
100
+ text-align: center; padding: 0.8rem 0.4rem; border-radius: 14px;
101
+ background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.06);
 
 
102
  transition: background 0.2s;
103
  }
104
  .forecast-day:hover { background: rgba(255,255,255,0.1); }
 
107
  .forecast-temp { font-size: 0.9rem; font-weight: 600; }
108
  .forecast-temp-low { color: rgba(255,255,255,0.35); font-size: 0.75rem; font-weight: 400; }
109
 
110
+ .loading, .error { text-align: center; padding: 4rem 1rem; font-size: 1rem; color: rgba(255,255,255,0.5); }
 
 
 
 
111
  .error { color: #f87171; }
112
  .spinner {
113
  display: inline-block; width: 24px; height: 24px;
114
+ border: 2px solid rgba(255,255,255,0.2); border-top-color: #a78bfa;
115
+ border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 0.5rem;
 
 
116
  }
117
  @keyframes spin { to { transform: rotate(360deg); } }
118
 
119
+ .footer { text-align: center; margin-top: 2.5rem; color: rgba(255,255,255,0.18); font-size: 0.68rem; }
 
 
 
120
  .footer a { color: rgba(167,139,250,0.4); text-decoration: none; }
121
 
122
  @media (max-width: 600px) {
 
124
  .current-temp { font-size: 3.5rem; }
125
  .weather-icon { font-size: 3rem; }
126
  .details { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
127
+ .forecast-grid { grid-template-columns: repeat(3, 1fr); }
128
  .weather-header { padding: 1.5rem 1rem; }
129
  }
130
  </style>
 
134
  <div class="bg-overlay"></div>
135
 
136
  <div class="container">
 
137
  <div class="search-section">
138
  <div class="search-box">
139
  <span class="search-icon">πŸ”</span>
 
141
  <div class="search-results" id="searchResults"></div>
142
  </div>
143
  </div>
 
 
144
  <div id="app">
145
+ <div class="loading"><div class="spinner"></div><div>Loading weather...</div></div>
 
 
 
146
  </div>
 
147
  <div class="footer">
148
  Weather by <a href="https://open-meteo.com" target="_blank">Open-Meteo</a> Β· Liquid Glass Dashboard by Hedd
149
  </div>
 
151
 
152
  <script>
153
  const WMO = {
154
+ 0: { desc: 'Cerah', icon: 'β˜€οΈ' }, 1: { desc: 'Cerah Berawan', icon: '🌀️' },
155
+ 2: { desc: 'Berawan', icon: 'β›…' }, 3: { desc: 'Mendung', icon: '☁️' },
156
+ 45: { desc: 'Kabut', icon: '🌫️' }, 48: { desc: 'Kabut Tebal', icon: '🌫️' },
157
+ 51: { desc: 'Gerimis Ringan', icon: '🌦️' }, 53: { desc: 'Gerimis', icon: '🌦️' },
 
 
 
 
158
  55: { desc: 'Gerimis Lebat', icon: '🌧️' },
159
+ 61: { desc: 'Hujan Ringan', icon: '🌧️' }, 63: { desc: 'Hujan', icon: '🌧️' },
 
160
  65: { desc: 'Hujan Lebat', icon: 'β›ˆοΈ' },
161
+ 71: { desc: 'Salju Ringan', icon: '🌨️' }, 73: { desc: 'Salju', icon: '❄️' },
 
162
  75: { desc: 'Salju Lebat', icon: '❄️' },
163
+ 80: { desc: 'Hujan Lokal', icon: '🌦️' }, 81: { desc: 'Hujan Sedang', icon: '🌧️' },
 
164
  82: { desc: 'Hujan Deras', icon: 'β›ˆοΈ' },
165
  95: { desc: 'Badai Petir', icon: 'β›ˆοΈ' },
166
+ 96: { desc: 'Badai + Hujan Es', icon: '🌩️' }, 99: { desc: 'Badai + Hujan Es', icon: '🌩️' },
 
167
  };
168
 
169
  const DAYS = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'];
170
  let searchTimeout;
 
171
  const searchInput = document.getElementById('searchInput');
172
  const searchResults = document.getElementById('searchResults');
173
  const app = document.getElementById('app');
 
180
  });
181
 
182
  searchInput.addEventListener('keydown', (e) => {
183
+ if (e.key === 'Enter') { clearTimeout(searchTimeout); const q = searchInput.value.trim(); if (q.length >= 2) searchCity(q); }
 
 
 
 
184
  });
185
 
186
+ document.addEventListener('click', (e) => { if (!e.target.closest('.search-box')) searchResults.classList.remove('active'); });
 
 
187
 
188
  async function searchCity(query) {
189
  try {
190
+ const res = await fetch('/api/search?q=' + encodeURIComponent(query));
191
  const data = await res.json();
192
  if (data.results && data.results.length > 0) {
193
  searchResults.innerHTML = data.results.slice(0, 5).map(r =>
194
+ '<div class="search-result" data-lat="' + r.latitude + '" data-lon="' + r.longitude + '" data-name="' + r.name + '" data-country="' + (r.admin1 || r.country || '') + '">' +
195
+ '<div>' + r.name + '</div><div class="country">' + (r.admin1 ? r.admin1 + ', ' : '') + (r.country || '') + '</div></div>'
 
 
196
  ).join('');
197
  searchResults.classList.add('active');
 
198
  searchResults.querySelectorAll('.search-result').forEach(el => {
199
  el.addEventListener('click', () => {
200
  const { lat, lon, name, country } = el.dataset;
201
  searchResults.classList.remove('active');
202
  searchInput.value = name;
203
+ loadWeather(parseFloat(lat), parseFloat(lon), name + ', ' + country);
204
  });
205
  });
206
  } else {
207
  searchResults.innerHTML = '<div class="search-result" style="opacity:0.5">Tidak ditemukan</div>';
208
  searchResults.classList.add('active');
209
  }
210
+ } catch(e) { console.error(e); }
 
 
211
  }
212
 
213
+ function getWmo(code) { return WMO[code] || { desc: 'Tidak diketahui', icon: '❓' }; }
 
 
214
 
215
  function formatDay(dateStr) {
216
  const d = new Date(dateStr + 'T00:00:00');
 
219
 
220
  function loadWeather(lat, lon, name) {
221
  app.innerHTML = '<div class="loading"><div class="spinner"></div><div>Loading weather...</div></div>';
222
+ fetch('/api/weather?lat=' + lat + '&lon=' + lon + '&name=' + encodeURIComponent(name))
 
223
  .then(r => r.json())
224
+ .then(data => {
225
+ if (data.error) throw new Error(data.message || data.error);
226
+ renderWeather(data);
227
+ })
228
  .catch(e => {
229
+ app.innerHTML = '<div class="error">Gagal memuat data cuaca.<br><small>' + e.message + '</small></div>';
230
  });
231
  }
232
 
 
236
  const wmo = getWmo(cur.weather_code);
237
  const name = data.location_name || '';
238
 
239
+ const sunrise = daily.sunrise && daily.sunrise[0] ? new Date(daily.sunrise[0]).toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' }) : 'β€”';
240
+ const sunset = daily.sunset && daily.sunset[0] ? new Date(daily.sunset[0]).toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' }) : 'β€”';
241
+
242
+ // OpenMeteo: daily arrays (time, weather_code, etc) β€” NOT .days
243
+ const days = daily.time;
244
+ if (!days || days.length === 0) throw new Error('No forecast data');
245
 
246
+ app.innerHTML =
247
+ '<div class="weather-header glass">' +
248
+ '<div class="city-name">' + name + '</div>' +
249
+ '<div class="weather-icon">' + wmo.icon + '</div>' +
250
+ '<div class="weather-desc">' + wmo.desc + '</div>' +
251
+ '<div class="current-temp">' + Math.round(cur.temperature_2m) + 'Β°</div>' +
252
+ '<div class="feels-like">Terasa seperti ' + Math.round(cur.apparent_temperature) + 'Β°C</div>' +
253
+ '</div>' +
 
254
 
255
+ '<div class="section-title">Detail</div>' +
256
+ '<div class="details">' +
257
+ '<div class="detail-card glass"><div class="detail-icon-val">πŸ’§</div><div class="detail-value">' + cur.relative_humidity_2m + '%</div><div class="detail-label">Kelembapan</div></div>' +
258
+ '<div class="detail-card glass"><div class="detail-icon-val">πŸ’¨</div><div class="detail-value">' + Math.round(cur.wind_speed_10m) + '</div><div class="detail-label">Angin (km/h)</div></div>' +
259
+ '<div class="detail-card glass"><div class="detail-icon-val">🌑️</div><div class="detail-value">' + Math.round(cur.pressure_msl) + '</div><div class="detail-label">Tekanan (hPa)</div></div>' +
260
+ '<div class="detail-card glass"><div class="detail-icon-val">β˜€οΈ</div><div class="detail-value">' + (cur.uv_index ?? 'β€”') + '</div><div class="detail-label">UV Index</div></div>' +
261
+ '<div class="detail-card glass"><div class="detail-icon-val">πŸŒ…</div><div class="detail-value">' + sunrise + '</div><div class="detail-label">Sunrise</div></div>' +
262
+ '<div class="detail-card glass"><div class="detail-icon-val">πŸŒ‡</div><div class="detail-value">' + sunset + '</div><div class="detail-label">Sunset</div></div>' +
263
+ '</div>' +
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
 
265
+ '<div class="section-title">Ramalan ' + days.length + ' Hari</div>' +
266
+ '<div class="glass" style="padding: 0; margin-bottom: 1rem;">' +
267
+ '<div class="forecast-grid">' +
268
+ days.map(function(day, i) {
269
+ var dw = getWmo(daily.weather_code[i]);
270
+ var isToday = i === 0;
271
+ var style = isToday ? 'background: rgba(167,139,250,0.15); border-color: rgba(167,139,250,0.3);' : '';
272
+ return '<div class="forecast-day" style="' + style + '">' +
273
+ '<div class="forecast-name">' + (isToday ? 'Hari ini' : formatDay(day)) + '</div>' +
274
+ '<div class="forecast-icon">' + dw.icon + '</div>' +
275
+ '<div class="forecast-temp">' + Math.round(daily.temperature_2m_max[i]) + 'Β°</div>' +
276
+ '<div class="forecast-temp-low">' + Math.round(daily.temperature_2m_min[i]) + 'Β°</div>' +
277
+ '</div>';
278
+ }).join('') +
279
+ '</div>' +
280
+ '</div>';
 
 
 
281
  }
282
 
283
+ // Load Jakarta default
284
  loadWeather(-6.2, 106.85, 'Jakarta, Indonesia');
285
  </script>
286
  </body>