#!/bin/bash

# Script to replace image URLs across all HTML/PHP files.
#
# Replacement 1: Precisely targets the "hitbet casino hoş geldin bonusu" image
#   Old: alt="hitbet casino hoş geldin bonusu" src="https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/Sport%20and%20Casino%20bonus.png"
#   New: alt="hitbet casino hoş geldin bonusu" src="https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1719932609357-casino-hg-sm.jpg"
#
# Replacement 2: Updates the same image to a new CDN URL
#   Old: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1719932609357-casino-hg-sm.jpg
#   New: https://images.hitplinkooffer.com/p1.webp

SEARCH_DIR="."

echo "Starting image URL replacements..."

find "$SEARCH_DIR" -type f \( -name "index.html" \) | while read -r file; do
    modified=0

    # ---- Replacement 1: Specific alt+src pattern ----
    if grep -qi 'alt="hitbet casino hoş geldin bonusu"' "$file" 2>/dev/null; then
        sed -i  \
            's|alt="hitbet casino hoş geldin bonusu" src="https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/Sport%20and%20Casino%20bonus\.png"|alt="hitbet casino hoş geldin bonusu" src="https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1719932609357-casino-hg-sm.jpg"|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 2: Update the image URL to the new CDN ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719932609357-casino-hg-sm\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719932609357-casino-hg-sm\.jpg|https://images.hitplinkooffer.com/p1.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 3: hitbet-spor-hosgeldin-bonusu.jpg (all domains) to p2.webp ----
    if grep -q '/hitbet-spor-hosgeldin-bonusu\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/hitbet-spor-hosgeldin-bonusu\.jpg|https://images.hitplinkooffer.com/p2.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 4: ertesi-hg-sm.jpg to r3.png (images.hitplinkooffer.com) ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719932929425-ertesi-hg-sm\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719932929425-ertesi-hg-sm\.jpg|https://images.hitplinkooffer.com/p3.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 5: KOMBİNE-sm.jpg to r4.png ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719933187523-KOMBI%CC%87NE-sm\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719933187523-KOMBI%CC%87NE-sm\.jpg|https://images.hitplinkooffer.com/p4.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 6: Görevleri tamamla (3).webp to p2.webp ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/G%C3%B6revleri%20tamamla%20(3)\.webp' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/G%C3%B6revleri%20tamamla%20(3)\.webp|https://images.hitplinkooffer.com/p2.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 7: cekim imkanı.webp to p3.webp ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/cekim%20imkan%C4%B1\.webp' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/cekim%20imkan%C4%B1\.webp|https://images.hitplinkooffer.com/p3.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 8: %50 combined bonus.png to p4.webp ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/%2550%20combined%20bonus\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/%2550%20combined%20bonus\.png|https://images.hitplinkooffer.com/p4.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 9: amp/lisans.png to lisans.png at images CDN ----
    if grep -q 'https://hitbetguncel\.xyz/amp/lisans\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://hitbetguncel\.xyz/amp/lisans\.png|https://images.hitplinkooffer.com/lisans.png|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 10: NVNG4I.png to herowoman.webp at images CDN ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/NVNG4I\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/NVNG4I\.png|https://images.hitplinkooffer.com/herowoman.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 11: hitbet_bonus_max.webp to bonusmax.webp ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet_bonus_max\.webp' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet_bonus_max\.webp|https://images.hitplinkooffer.com/bonusmax.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 12: anjouan_license.png to lisans.png ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/anjouan_license\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/anjouan_license\.png|https://images.hitplinkooffer.com/lisans.png|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 13: pub-3d0bbe...r2.dev domain to images.hitplinkooffer.com ----
    if grep -q 'https://pub-3d0bbe27318e4b3bb88f3e1c0496620b\.r2\.dev/' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-3d0bbe27318e4b3bb88f3e1c0496620b\.r2\.dev/|https://images.hitplinkooffer.com/|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 14: hitbet-tv-img.png to images CDN ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet-tv-img\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet-tv-img\.png|https://images.hitplinkooffer.com/hitbet-tv-img.png|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 15: hitbet-logo.webp to images CDN ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet-logo\.webp' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet-logo\.webp|https://images.hitplinkooffer.com/hitbet-logo.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 16: hitbet-logo.png to hitbet-logo.webp on images CDN ----
    if grep -q 'https://images\.hitplinkooffer\.com/hitbet-logo\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://images\.hitplinkooffer\.com/hitbet-logo\.png|https://images.hitplinkooffer.com/hitbet-logo.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 17: arkaplan.png to arkaplan.webp on images CDN ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720268466992-arkaplan\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720268466992-arkaplan\.png|https://images.hitplinkooffer.com/arkaplan.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 18: slot.png to s1.webp ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001269964-slot\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001269964-slot\.png|https://images.hitplinkooffer.com/s1.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 19: canlı-casino 2.png to s2.webp ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719998665713-canlı-casino%202\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719998665713-canlı-casino%202\.png|https://images.hitplinkooffer.com/s2.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 20: spor 2.png to s3.webp ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001300763-spor%202\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001300763-spor%202\.png|https://images.hitplinkooffer.com/s3.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 21: avi.png to s4.webp ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001316941-avi\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001316941-avi\.png|https://images.hitplinkooffer.com/s4.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 22: unlayer hitbetfavicon to favicon.webp at images CDN ----
    if grep -q 'https://assets\.unlayer\.com/projects/240067/1720681067801-hitbetfavicon\.webp' "$file" 2>/dev/null; then
        sed -i  \
            's|https://assets\.unlayer\.com/projects/240067/1720681067801-hitbetfavicon\.webp|https://images.hitplinkooffer.com/favicon.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 23: Hit-saglayici.png to sponsors.png at images CDN ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1721028620156-Hit-saglayici\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1721028620156-Hit-saglayici\.png|https://images.hitplinkooffer.com/sponsors.png|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 24: hitbet.com/img/social/telegram.png to telegram.png at images CDN ----
    if grep -q 'https://hitbet\.com/img/social/telegram\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://hitbet\.com/img/social/telegram\.png|https://images.hitplinkooffer.com/telegram.png|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 25: unlayer social icons circle directory to images CDN ----
    if grep -q 'https://cdn\.tools\.unlayer\.com/social/icons/circle/' "$file" 2>/dev/null; then
        sed -i  \
            's|https://cdn\.tools\.unlayer\.com/social/icons/circle/|https://images.hitplinkooffer.com/|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 26: resmim.net NVTWcG.webp to favicon.webp at images CDN ----
    if grep -q 'https://resmim\.net/cdn/2025/04/21/NVTWcG\.webp' "$file" 2>/dev/null; then
        sed -i  \
            's|https://resmim\.net/cdn/2025/04/21/NVTWcG\.webp|https://images.hitplinkooffer.com/favicon.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 27: hitlogotv-1.png to hitbet-tv-img.png at images CDN ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719915225991-hitlogotv-1\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719915225991-hitlogotv-1\.png|https://images.hitplinkooffer.com/hitbet-tv-img.png|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 28: hitbet-anasayfa.png to herowoman.webp at images CDN ----
    if grep -q 'https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet-anasayfa\.png' "$file" 2>/dev/null; then
        sed -i  \
            's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet-anasayfa\.png|https://images.hitplinkooffer.com/herowoman.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 29: spor-hg-sm.jpg (all domains) to p2.webp ----
    if grep -q '/spor-hg-sm\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/spor-hg-sm\.jpg|https://images.hitplinkooffer.com/p2.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 30: unlayer SPOR-hg-sm.jpg to p2.webp ----
    if grep -q 'https://assets\.unlayer\.com/projects/240067/1719932804136-SPOR-hg-sm\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://assets\.unlayer\.com/projects/240067/1719932804136-SPOR-hg-sm\.jpg|https://images.hitplinkooffer.com/p2.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 31: 100-TL-DENEME.jpg (all domains) to p1.webp ----
    if grep -q '/100-TL-DENEME\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/100-TL-DENEME\.jpg|https://images.hitplinkooffer.com/p1.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 32: SPOR-HG.jpg (all domains) to p2.webp ----
    if grep -q '/SPOR-HG\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/SPOR-HG\.jpg|https://images.hitplinkooffer.com/p2.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 33: casino-HG.jpg (all domains) to p3.webp ----
    if grep -q '/casino-HG\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/casino-HG\.jpg|https://images.hitplinkooffer.com/p3.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 34: Hitbet-cekim-limiti.jpg (all domains) to p4.webp ----
    if grep -q '/Hitbet-cekim-limiti\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/Hitbet-cekim-limiti\.jpg|https://images.hitplinkooffer.com/p4.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 35: DENEME-BONUSU-2025-PRO.jpg (all domains) to p1.webp ----
    if grep -q '/DENEME-BONUSU-2025-PRO\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/DENEME-BONUSU-2025-PRO\.jpg|https://images.hitplinkooffer.com/p1.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 36: Spor-hg-pro.jpg (all domains) to p2.webp ----
    if grep -q '/Spor-hg-pro\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/Spor-hg-pro\.jpg|https://images.hitplinkooffer.com/p2.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 37: Hit-Casino-Hos-Geldin-pro.jpg (all domains) to p3.webp ----
    if grep -q '/Hit-Casino-Hos-Geldin-pro\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/Hit-Casino-Hos-Geldin-pro\.jpg|https://images.hitplinkooffer.com/p3.webp|g' \
            "$file"
        modified=1
    fi

    # ---- Replacement 38: Çekim-2025-Pro.jpg (all domains) to p4.webp ----
    if grep -q '/%C3%87ekim-2025-Pro\.jpg' "$file" 2>/dev/null; then
        sed -i  \
            's|https://[^/]*/%C3%87ekim-2025-Pro\.jpg|https://images.hitplinkooffer.com/p4.webp|g' \
            "$file"
        modified=1
    fi

    if [ "$modified" -eq 1 ]; then
        echo "  Updated: $file"
    fi
done

echo "Replacement complete!"

