<script setup lang="ts">
import {computed, onMounted, ref} from 'vue';
import {api, BASE, type DataRow} from '../services/api';

const data = ref<any>({});
const precipitation = '';
const humidity = computed(() => data.value.humidity || '—');
const label = computed(() => data.value.forecast_weather_label || '');

onMounted(async () => {
	data.value = await api.current();
	console.log(data.value);
});

</script>

<style scoped lang="scss">
.today-card {
	border-radius: 12px;
	background: var(--surface);
	border: 1px solid var(--border);
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.today-header {
	display: flex;
	align-items: center;
	gap: 12px;
}

.today-icon {
	width: 52px;
	height: 52px;
	object-fit: contain;
	flex-shrink: 0;
}

.today-title {
	flex: 1;
	min-width: 0;
}

.today-date {
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--text-muted);
}

.today-label {
	font-size: 16px;
	font-weight: 600;
	color: var(--text);
}

.hi-lo {
	display: flex;
	gap: 8px;
	font-size: 15px;
	font-weight: 600;
	margin-top: 2px;

	.hi { color: var(--text); }
	.lo { color: var(--text-muted); font-weight: 400; }
}

.divider {
	height: 1px;
	background: var(--border);
}

.stat-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
	gap: 10px;
}

.stat {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.stat-label {
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--text-muted);
}

.stat-value {
	font-size: 14px;
	font-weight: 600;
	color: var(--text);
}

.stat-sub {
	font-size: 11px;
	color: var(--text-muted);
}

.section-label {
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--text-muted);
	margin-bottom: -4px;
}
</style>

<template>
	<div class="today-card">
		<div class="flex-r align-items-center justify-between px-3">
			<div class="flex-c justify-center align-items-center">
				<div class="today-label">{{ data.label }}</div>
				<img v-if="data.icon" :src="BASE + data.icon" class="today-icon" alt="weather" />
			</div>
			<div class="flex-r align-items-center gap-3">
				<div class="fs-6">
					0°C
				</div>
				<div class="flex-c fg-muted">
					<span class="hi">↑ {{ high }}</span>
					<span class="lo">↓ {{ low }}</span>
				</div>
			</div>
		</div>

		<div class="divider" />

		<div class="stat-grid">
			<div class="stat"><span class="stat-label">Precipitation</span><span class="stat-value">{{ precipProb }}</span></div>
			<div class="stat"><span class="stat-label">Humidity</span><span class="stat-value">{{ humidity }}</span><span v-if="precipHrs" class="stat-sub">over {{ precipHrs }}</span></div>
			<div class="stat"><span class="stat-label">Wind</span><span class="stat-value">{{ windMax }}</span></div>
			<div class="stat"><span class="stat-label">Clouds</span><span class="stat-value">{{ windMax }}</span></div>
			<div class="stat"><span class="stat-label">Air Quality</span><span class="stat-value">{{ windMax }}</span></div>
			<div class="stat"><span class="stat-label">UV index</span><span class="stat-value">{{ windMax }}</span></div>
		</div>

	</div>
</template>
