#!/bin/bash
# css_generator.sh - Erzeugt die zentrale CSS-Datei

generate_css() {
    local css_file_path="${WEB_ROOT_PATH}/style.css"
    local actual_banner_img_url_path="${FALLBACK_BANNER_IMG_URL}"

    if [ -n "$STATIC_BANNER_FILENAME" ]; then
        local banner_web_path="/images/${STATIC_BANNER_FILENAME}"
        if [ -f "${WEB_ROOT_PATH}${banner_web_path}" ]; then
            actual_banner_img_url_path="$banner_web_path"
            log_message "Verwende statisches Banner: ${actual_banner_img_url_path}"
        else
            log_message "WARNUNG: Statisches Banner '${STATIC_BANNER_FILENAME}' nicht gefunden. Fallback: ${FALLBACK_BANNER_IMG_URL}"
        fi
    else
        log_message "Kein STATIC_BANNER_FILENAME definiert, verwende Fallback: ${FALLBACK_BANNER_IMG_URL}"
    fi

    log_message "Erzeuge/Aktualisiere ${css_file_path}..."
    render_template "${TEMPLATE_DIR_PATH}/css.template" "$css_file_path" \
        "css_banner_image_path" "$actual_banner_img_url_path" \
        "CACHE_BUSTER" "$CACHE_BUSTER"
    if [ $? -ne 0 ]; then log_message "FEHLER bei der CSS-Generierung."; fi
}
