#!/usr/bin/env bash
# Erzeugt Launcher-Icons aus dem Web-Header-Logo (frontend/src/assets/logo.png).
# Aufruf von überall: bash mobile-app/scripts/refresh-android-launcher-icons.sh
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
SRC="$ROOT/frontend/src/assets/logo.png"
RES="$ROOT/mobile-app/composeApp/src/androidMain/res"
if [[ ! -f "$SRC" ]]; then
  echo "Fehlt: $SRC" >&2
  exit 1
fi
mkdir -p "$RES/drawable-mdpi" "$RES/drawable-hdpi" "$RES/drawable-xhdpi" "$RES/drawable-xxhdpi" "$RES/drawable-xxxhdpi" \
  "$RES/mipmap-mdpi" "$RES/mipmap-hdpi" "$RES/mipmap-xhdpi" "$RES/mipmap-xxhdpi" "$RES/mipmap-xxxhdpi"
magick "$SRC" -resize 108x108!   -filter Lanczos "$RES/drawable-mdpi/ic_launcher_foreground.png"
magick "$SRC" -resize 162x162!   -filter Lanczos "$RES/drawable-hdpi/ic_launcher_foreground.png"
magick "$SRC" -resize 216x216!  -filter Lanczos "$RES/drawable-xhdpi/ic_launcher_foreground.png"
magick "$SRC" -resize 324x324!  -filter Lanczos "$RES/drawable-xxhdpi/ic_launcher_foreground.png"
magick "$SRC" -resize 432x432!  -filter Lanczos "$RES/drawable-xxxhdpi/ic_launcher_foreground.png"
# Erzeuge zusätzlich ein 512x512 PNG für den Play Store (Upload-Icon)
mkdir -p "$ROOT/mobile-app/composeApp/playstore"
magick "$SRC" -resize 512x512! -filter Lanczos "$ROOT/mobile-app/composeApp/playstore/ic_launcher_foreground_512.png"
magick "$SRC" -resize 48x48!    -filter Lanczos "$RES/mipmap-mdpi/ic_launcher.png"
magick "$SRC" -resize 72x72!    -filter Lanczos "$RES/mipmap-hdpi/ic_launcher.png"
magick "$SRC" -resize 96x96!    -filter Lanczos "$RES/mipmap-xhdpi/ic_launcher.png"
magick "$SRC" -resize 144x144!  -filter Lanczos "$RES/mipmap-xxhdpi/ic_launcher.png"
magick "$SRC" -resize 192x192!  -filter Lanczos "$RES/mipmap-xxxhdpi/ic_launcher.png"
for d in mipmap-mdpi mipmap-hdpi mipmap-xhdpi mipmap-xxhdpi mipmap-xxxhdpi; do
  cp "$RES/$d/ic_launcher.png" "$RES/$d/ic_launcher_round.png"
done
echo "OK: Icons aus $SRC nach $RES"
