#!/bin/bash
# WP Bootstrap Studio Theme — Bootstrap File Downloader
# Run this once to download Bootstrap 5.3.3 files into the theme.
# This ensures the theme never depends on a CDN.

THEME_DIR="$(cd "$(dirname "$0")" && pwd)"
BS_DIR="$THEME_DIR/assets/bootstrap"

echo "Downloading Bootstrap 5.3.3 files..."

# Compiled CSS
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" -o "$BS_DIR/css/bootstrap.min.css"
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css.map" -o "$BS_DIR/css/bootstrap.min.css.map"
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.css" -o "$BS_DIR/css/bootstrap.css"

# Compiled JS
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" -o "$BS_DIR/js/bootstrap.bundle.min.js"
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js.map" -o "$BS_DIR/js/bootstrap.bundle.min.js.map"
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.js" -o "$BS_DIR/js/bootstrap.bundle.js"

# Bootstrap Icons
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" -o "$BS_DIR/css/bootstrap-icons.min.css"

# Bootstrap Icons fonts (placed in css/fonts/ to match the CSS @font-face paths)
mkdir -p "$BS_DIR/css/fonts"
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/fonts/bootstrap-icons.woff2" -o "$BS_DIR/css/fonts/bootstrap-icons.woff2"
curl -sL "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/fonts/bootstrap-icons.woff" -o "$BS_DIR/css/fonts/bootstrap-icons.woff"

# Font Awesome 6 Free (CSS + webfonts)
echo "Downloading Font Awesome 6 Free..."
FA_DIR="$THEME_DIR/assets/fontawesome"
mkdir -p "$FA_DIR/css" "$FA_DIR/webfonts"
curl -sL "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/css/all.min.css" -o "$FA_DIR/css/all.min.css"
curl -sL "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/webfonts/fa-solid-900.woff2" -o "$FA_DIR/webfonts/fa-solid-900.woff2"
curl -sL "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/webfonts/fa-regular-400.woff2" -o "$FA_DIR/webfonts/fa-regular-400.woff2"
curl -sL "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/webfonts/fa-brands-400.woff2" -o "$FA_DIR/webfonts/fa-brands-400.woff2"
curl -sL "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/webfonts/fa-solid-900.ttf" -o "$FA_DIR/webfonts/fa-solid-900.ttf"
curl -sL "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/webfonts/fa-regular-400.ttf" -o "$FA_DIR/webfonts/fa-regular-400.ttf"
curl -sL "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/webfonts/fa-brands-400.ttf" -o "$FA_DIR/webfonts/fa-brands-400.ttf"

# Bootstrap SCSS source (for customization)
echo "Downloading Bootstrap SCSS source..."
curl -sL "https://github.com/twbs/bootstrap/archive/refs/tags/v5.3.3.tar.gz" -o /tmp/bootstrap-src.tar.gz
tar -xzf /tmp/bootstrap-src.tar.gz -C /tmp/
cp -r /tmp/bootstrap-5.3.3/scss/* "$BS_DIR/scss/"
rm -rf /tmp/bootstrap-src.tar.gz /tmp/bootstrap-5.3.3

echo ""
echo "✓ Bootstrap 5.3.3 + Font Awesome 6 files downloaded successfully!"
echo "  Bootstrap CSS:   $BS_DIR/css/"
echo "  Bootstrap JS:    $BS_DIR/js/"
echo "  Bootstrap SCSS:  $BS_DIR/scss/"
echo "  Bootstrap Icons: $BS_DIR/css/fonts/"
echo "  Font Awesome:    $FA_DIR/"
echo ""
echo "Your theme is now fully self-contained. No CDN required."
