#!/bin/bash

# omarchy:summary=Returns a formatted weather status string with temperature and wind speed.

place=$(omarchy-weather-location 2>/dev/null)

if [[ -z $place ]]; then
  echo "Weather unavailable"
  exit 1
fi

query=$(jq -rn --arg place "$place" '$place | @uri')
weather=$(curl -fsS --max-time 4 "https://wttr.in/${query}?format=%t|%w" 2>/dev/null | tr -d '\n')

if [[ -z $weather ]]; then
  echo "Weather unavailable"
  exit 1
fi

IFS='|' read -r temperature wind <<< "$weather"
place=${place^}
temperature=${temperature#+}

echo "$place  ·  Temp $temperature  ·  Wind $wind"
