echo "Icons generated. Replace placeholders with designer assets if needed."
#!/usr/bin/env bash
set -euo pipefail

SRC="$(pwd)/app/play_store_512.png"
if [ ! -f "$SRC" ]; then
  echo "Source image not found: $SRC"
  exit 1
fi

# entries in format dir:size
entries=(
  "mipmap-mdpi:48"
  "mipmap-hdpi:72"
  "mipmap-xhdpi:96"
  "mipmap-xxhdpi:144"
  "mipmap-xxxhdpi:192"
)

RES_DIR="app/src/main/res"

for e in "${entries[@]}"; do
  dir="${e%%:*}"
  size="${e##*:}"
  outdir="$RES_DIR/$dir"
  mkdir -p "$outdir"
  out="$outdir/ic_launcher.png"
  echo "Generating $out ($size px)"
  sips -Z "$size" "$SRC" --out "$out" >/dev/null
  # also create foreground copy
  fg_out="$outdir/ic_launcher_foreground.png"
  sips -Z "$size" "$SRC" --out "$fg_out" >/dev/null
done

# ensure mipmap-anydpi-v26 exists and create adaptive xml
mkdir -p "$RES_DIR/mipmap-anydpi-v26"
cat > "$RES_DIR/mipmap-anydpi-v26/ic_launcher.xml" <<EOF
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/ic_launcher_background" />
    <foreground android:drawable="@mipmap/ic_launcher_foreground" />
</adaptive-icon>
EOF

echo "Icons generated. Replace placeholders with designer assets if needed."
