#!/bin/bash
# Converted with Linux and macOS compatibility

set -euo pipefail

# Detect OS for sed in-place flag
# macOS requires: sed -i ''  (empty backup extension)
# Linux requires:   sed -i    (no argument)
if [[ "$(uname)" == "Darwin" ]]; then
  SED_INPLACE=(-i '')
else
  SED_INPLACE=(-i)
fi

# Replace old logo URL with new logo URL in all .html files

# Replacement 1: hitbet-logo-min.webp -> hitbet-logo.png
# Old URL: https://assets.unlayer.com/projects/240067/1719912930761-hitbet-logo-min.webp
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/hitbet-logo.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1719912930761-hitbet-logo-min\.webp|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet-logo\.png|g' {} +

# Replacement 2: 1719915225991-hitlogotv-1.png
# Old URL: https://assets.unlayer.com/projects/240067/1719915225991-hitlogotv-1.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1719915225991-hitlogotv-1.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1719915225991-hitlogotv-1\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719915225991-hitlogotv-1\.png|g' {} +

# Replacement 3: 1720001316941-avi.png
# Old URL: https://assets.unlayer.com/projects/240067/1720001316941-avi.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1720001316941-avi.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1720001316941-avi\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001316941-avi\.png|g' {} +

# Replacement 4: 1720268466992-arkaplan.png
# Old URL: https://assets.unlayer.com/projects/240067/1720268466992-arkaplan.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1720268466992-arkaplan.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1720268466992-arkaplan\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720268466992-arkaplan\.png|g' {} +

# Replacement 5: 1720002209362-sol.png
# Old URL: https://assets.unlayer.com/projects/240067/1720002209362-sol.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1720002209362-sol.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1720002209362-sol\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720002209362-sol\.png|g' {} +

# Replacement 6: 1720001269964-slot.png
# Old URL: https://assets.unlayer.com/projects/240067/1720001269964-slot.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1720001269964-slot.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1720001269964-slot\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001269964-slot\.png|g' {} +

# Replacement 7: 1719932609357-casino-hg-sm.jpg
# Old URL: https://assets.unlayer.com/projects/240067/1719932609357-casino-hg-sm.jpg
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1719932609357-casino-hg-sm.jpg

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1719932609357-casino-hg-sm\.jpg|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719932609357-casino-hg-sm\.jpg|g' {} +

# Replacement 8: 1719932929425-ertesi-hg-sm.jpg
# Old URL: https://assets.unlayer.com/projects/240067/1719932929425-ertesi-hg-sm.jpg
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1719932929425-ertesi-hg-sm.jpg

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1719932929425-ertesi-hg-sm\.jpg|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719932929425-ertesi-hg-sm\.jpg|g' {} +

# Replacement 9: 1719933187523-KOMBİNE-sm.jpg
# Old URL: https://assets.unlayer.com/projects/240067/1719933187523-KOMBİNE-sm.jpg
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1719933187523-KOMBI%CC%87NE-sm.jpg

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1719933187523-KOMBİNE-sm\.jpg|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719933187523-KOMBI%CC%87NE-sm\.jpg|g' {} +

# Replacement 10: 1719998665713-canlı-casino%202.png
# Old URL: https://assets.unlayer.com/projects/240067/1719998665713-canlı-casino%202.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1719998665713-canlı-casino%202.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1719998665713-canlı-casino%202\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1719998665713-canlı-casino%202\.png|g' {} +

# Replacement 11: 1720001300763-spor%202.png
# Old URL: https://assets.unlayer.com/projects/240067/1720001300763-spor%202.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1720001300763-spor%202.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1720001300763-spor%202\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1720001300763-spor%202\.png|g' {} +

# Replacement 12: 1721028620156-Hit-saglayici.png
# Old URL: https://assets.unlayer.com/projects/240067/1721028620156-Hit-saglayici.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/1721028620156-Hit-saglayici.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://assets\.unlayer\.com/projects/240067/1721028620156-Hit-saglayici\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/1721028620156-Hit-saglayici\.png|g' {} +

# Replacement 13: NVNacb.png (resmim.net -> r2.dev)
# Old URL: https://resmim.net/cdn/2025/04/21/NVNacb.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/NVNacb.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://resmim\.net/cdn/2025/04/21/NVNacb\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/NVNacb\.png|g' {} +

# Replacement 14: NVNG4I.png (resmim.net -> r2.dev)
# Old URL: https://resmim.net/cdn/2025/04/21/NVNG4I.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/NVNG4I.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://resmim\.net/cdn/2025/04/21/NVNG4I\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/NVNG4I\.png|g' {} +

# Replacement 15: spor-hg-sm-1.jpg (i.ibb.co -> r2.dev)
# Old URL: https://i.ibb.co/cjLhMVN/spor-hg-sm-1.jpg
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/hitbet-spor-hosgeldin-bonusu.jpg

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://i\.ibb\.co/cjLhMVN/spor-hg-sm-1\.jpg|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/hitbet-spor-hosgeldin-bonusu\.jpg|g' {} +

# Replacement 16: Facebook social link
# Old URL: https://www.facebook.com/tam.isabet.902
# New URL: https://h1t.io/HB-Facebook

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://www\.facebook\.com/tam\.isabet\.902|https://h1t\.io/HB-Facebook|g' {} +

#find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
#  's|https://www\.instagram\.com/hitbetcom|https://h1t\.io/HB-Whatsapp|g' {} +

# Replacement 18: YouTube social link
# Old URL: https://youtube.com/@hitbet
# New URL: https://h1t.io/HB-YouTube

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://youtube\.com/@hitbet|https://h1t\.io/HB-YouTube|g' {} +

# Replacement 19: Facebook social icon image
# Old URL: https://cdn.tools.unlayer.com/social/icons/circle/facebook.png
# New URL: https://hitbet.com/img/social/facebook.png

#find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
#  's|https://cdn\.tools\.unlayer\.com/social/icons/circle/facebook\.png|https://hitbet\.com/img/social/facebook\.png|g' {} +

# Replacement 20: X/Twitter social icon image
# Old URL: https://cdn.tools.unlayer.com/social/icons/circle/x.png
# New URL: https://hitbet.com/img/social/x.png

#find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
#  's|https://cdn\.tools\.unlayer\.com/social/icons/circle/x\.png|https://hitbet\.com/img/social/x\.png|g' {} +

# Replacement 21: Instagram social icon image -> WhatsApp
# Old URL: https://cdn.tools.unlayer.com/social/icons/circle/instagram.png
# New URL: https://hitbet.com/img/social/whatsapp.png

#find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
# 's|https://cdn\.tools\.unlayer\.com/social/icons/circle/instagram\.png|https://hitbet\.com/img/social/whatsapp\.png|g' {} +

# Replacement 22: YouTube social icon image
# Old URL: https://cdn.tools.unlayer.com/social/icons/circle/youtube.png
# New URL: https://hitbet.com/img/social/youtube.png

#find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
#  's|https://cdn\.tools\.unlayer\.com/social/icons/circle/youtube\.png|https://hitbet\.com/img/social/youtube\.png|g' {} +

# Replacement 23: Telegram social icon image
# Old URL: https://cdn.tools.unlayer.com/social/icons/circle/telegram.png
# New URL: https://hitbet.com/img/social/telegram.png

#find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
#  's|https://cdn\.tools\.unlayer\.com/social/icons/circle/telegram\.png|https://hitbet\.com/img/social/telegram\.png|g' {} +

# Replacement 24: cutt.ly/Hitbet-Ads1 -> htbt.co/Hit-Kayit
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://cutt\.ly/Hitbet-Ads1|https://htbt\.co/Hit-Kayit|g' {} +

# Replacement 25: cutt.ly/Hitbet-Ads2 -> htbt.co/Hit-2026
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://cutt\.ly/Hitbet-Ads2|https://htbt\.co/Hit-2026|g' {} +

# Replacement 26: cutt.ly/Hitbet-Vmeta -> htbt.co/Hit-Kayit
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://cutt\.ly/Hitbet-Vmeta|https://htbt\.co/Hit-Kayit|g' {} +

# Replacement 27: cutt.ly/Hitbet-Vmeta2 -> htbt.co/Hit-2026
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://cutt\.ly/Hitbet-Vmeta2|https://htbt\.co/Hit-2026|g' {} +

# Replacement 28: cutt.ly/Hitsterra1 -> htbt.co/Hit-Kayit
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://cutt\.ly/Hitsterra1|https://htbt\.co/Hit-Kayit|g' {} +

# Replacement 29: cutt.ly/Hitads2 -> htbt.co/Hit-2026
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://cutt\.ly/Hitads2|https://htbt\.co/Hit-2026|g' {} +

# Replacement 30: cutt.ly/Hit-Bonus -> htbt.co/Hit-Kayit
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://cutt\.ly/Hit-Bonus|https://htbt\.co/Hit-Kayit|g' {} +

# Replacement 31: cutt.ly/Hit-Bonus2 -> htbt.co/Hit-2026
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://cutt\.ly/Hit-Bonus2|https://htbt\.co/Hit-2026|g' {} +

# Replacement 32: h.t2m.io/Hit-Paravan -> htbt.co/Hit-Kayit
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://h\.t2m\.io/Hit-Paravan|https://htbt\.co/Hit-Kayit|g' {} +

# Replacement 33: h.t2m.io/Hit-paravan-Giris -> htbt.co/Hit-2026
find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://h\.t2m\.io/Hit-paravan-Giris|https://htbt\.co/Hit-2026|g' {} +

# Replacement 34: Multi-line legal text replacement (Hit Entertainment -> Gala Entertainment)
# Old: Turkish license text referring to Hit Entertainment BV / Curaçao (2 lines separated by whitespace)
# New: Turkish license text referring to Gala Entertainment Technologies Limitada / Anjouan
# Note: Uses perl instead of sed for reliable multi-line matching with \s+ across line breaks
find . -name "*.html" -type f -exec perl -i -0777 -pe \
  "s|Bu site, Hit Entertainment BV tarafından Curaçao Ticaret ve Sanayi Odası Ticaret Siciline kayıtlı 145060 numarasıyla işletilmektedir\. Lisans numarası 1668 / JAZ, Curaçao Egaming tarafından verilmiş olup Curaçao yönetimi tarafından yetkilendirilmiş\s+ve denetlenmektedir\.|Bu site, Anjouan Ticaret ve Sanayi Odası Ticaret Siciline, tescil edilen 3-102-928829 kayıt numarası ile Gala Entertainment Technologies Limitada tarafından işletilmektedir. Lisans numarası ALSI-202505014-FI1 Anjouan Egaming tarafından verilmiştir, Anjouan Hükümeti tarafından yetkilendirilir ve düzenlenir.<br>Bu web sitesine kaydolmak için kullanıcının Genel Hüküm ve Koşulları kabul etmesi gerekmektedir. [Genel Şartlar ve Koşullar]'ın güncellenmesi durumunda mevcut kullanıcılar, söz konusu güncelleme yürürlüğe girmeden, yani duyurulduktan en az iki hafta sonra ürünü ve hizmetleri kullanmayı bırakmayı tercih edebilirler.|gs" {} +

# Replacement 35: NVNacb.png -> anjouan_license.png (r2.dev -> r2.dev)
# Old URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/NVNacb.png
# New URL: https://pub-786f2c26edb242208bc1e12528dc15ac.r2.dev/anjouan_license.png

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/NVNacb\.png|https://pub-786f2c26edb242208bc1e12528dc15ac\.r2\.dev/anjouan_license\.png|g' {} +

# Replacement 36: Hit-Kayit -> Hit-2026
# Old URL: https://htbt.co/Hit-Kayit
# New URL: https://htbt.co/Hit-2026

find . -name "*.html" -type f -exec sed "${SED_INPLACE[@]}" \
  's|https://htbt\.co/Hit-Kayit|https://htbt\.co/Hit-2026|g' {} +

echo "Done. Replaced all thirty-six asset URLs and legal text in all .html files."

