#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
TEMPLATE="$ROOT_DIR/store-assets/google-ads/google-ads-creatives.html"
OUT_DIR="$ROOT_DIR/store-assets/google-ads"

mkdir -p "$OUT_DIR"

creatives=(
  "pqs-square-01-scanner 1200 1200"
  "pqs-square-02-results 1200 1200"
  "pqs-square-03-risk 1200 1200"
  "pqs-square-04-image-scan 1200 1200"
  "pqs-square-05-contact 1200 1200"
  "pqs-square-06-history 1200 1200"
  "pqs-square-07-batch 1200 1200"
  "pqs-square-08-settings 1200 1200"
  "pqs-horizontal-01-scanner-results 1200 628"
  "pqs-horizontal-02-gallery 1200 628"
  "pqs-horizontal-03-risk 1200 628"
  "pqs-horizontal-04-history 1200 628"
  "pqs-horizontal-05-wifi 1200 628"
  "pqs-horizontal-06-event 1200 628"
  "pqs-horizontal-07-tablet 1200 628"
  "pqs-horizontal-08-settings 1200 628"
  "pqs-vertical-01-scanner 1200 1500"
  "pqs-vertical-02-gallery 1200 1500"
  "pqs-vertical-03-event 1200 1500"
  "pqs-vertical-04-privacy 1200 1500"
)

for creative in "${creatives[@]}"; do
  read -r id width height <<< "$creative"
  google-chrome \
    --headless \
    --disable-gpu \
    --no-sandbox \
    --hide-scrollbars \
    --allow-file-access-from-files \
    --window-size="${width},${height}" \
    --screenshot="$OUT_DIR/${id}.png" \
    "file://$TEMPLATE?creative=$id" >/dev/null
  printf '%s %sx%s\n' "$id" "$width" "$height"
done
