{{-- 주간 날씨 위젯 (HTMX 파티셜) --}} @if(empty($forecasts))
날씨 정보를 불러올 수 없습니다
@else @php $today = now()->format('Ymd'); $dayNames = ['일', '월', '화', '수', '목', '금', '토']; // 전체 기온 범위 계산 (바 그래프용) $allTmn = collect($forecasts)->pluck('tmn')->filter(fn($v) => $v !== null); $allTmx = collect($forecasts)->pluck('tmx')->filter(fn($v) => $v !== null); $globalMin = $allTmn->isNotEmpty() ? $allTmn->min() : 0; $globalMax = $allTmx->isNotEmpty() ? $allTmx->max() : 20; $range = max($globalMax - $globalMin, 1); @endphp
@foreach($forecasts as $fc) @php $dt = \Carbon\Carbon::createFromFormat('Ymd', $fc['date']); $isToday = ($fc['date'] === $today); $dayName = $dayNames[$dt->dayOfWeek]; $isSunday = $dt->dayOfWeek === 0; $isSaturday = $dt->dayOfWeek === 6; $icon = $fc['icon'] ?? null; $weatherText = $fc['weather_text'] ?? ''; $tmn = $fc['tmn']; $tmx = $fc['tmx']; $pop = $fc['pop'] ?? 0; $hasData = ($tmn !== null || $tmx !== null || $icon !== null); // 바 위치 계산 (%) $barLeft = $tmn !== null ? round(($tmn - $globalMin) / $range * 100) : 0; $barRight = $tmx !== null ? round(($tmx - $globalMin) / $range * 100) : 100; $barWidth = max($barRight - $barLeft, 8); // 강수 여부 $isPrecip = in_array($icon, ['rain', 'snow', 'sleet']); @endphp
{{-- 요일 --}}
{{ $isToday ? '오늘' : $dayName }}
{{-- 날짜 --}}
{{ $dt->format('m.d') }}
@if($hasData) {{-- 날씨 아이콘 --}}
@if($icon) @include('dashboard.partials.weather-icon', ['icon' => $icon]) @else
@endif
{{-- 강수확률 --}} @if($pop > 0)
{{-- 우산 아이콘 --}} {{ $pop }}%
@else
@endif {{-- 기온 바 그래프 --}} @if($tmx !== null && $tmn !== null)
@endif {{-- 최고/최저 기온 --}}
@if($tmx !== null) {{ $tmx }}° @else - @endif / @if($tmn !== null) {{ $tmn }}° @else - @endif
@else {{-- 데이터 없는 날 --}}
준비 중
@endif
@endforeach
@endif