<?php
if (!defined("ABSPATH")) exit;

// Pinery Flow — Post Card Overlays (price, rating)
// Theme calls pinery_flow_price_overlay() via function_exists().

/**
 * Output price + star rating overlay on post card images.
 * Controlled by Pinery Flow "Price + Rating Overlay" setting.
 */
function pinery_flow_price_overlay() {
    if (!get_option('pinery_flow_show_price_overlay', 1)) return '';
    $meta = get_post_meta(get_the_ID(), '_pinery_flow_product', true);
    if (empty($meta['price']) && empty($meta['rating'])) return '';
    $price  = esc_html($meta['price'] ?? '');
    $rating = esc_html($meta['rating'] ?? '');
    $rating = str_replace(' stars', '', $rating);
    $price_color  = esc_attr(get_option('pinery_flow_price_color', '#ffffff'));
    $price_size   = (int) get_option('pinery_flow_price_size', 14);
    $rating_color = esc_attr(get_option('pinery_flow_rating_color', '#ffd700'));
    $rating_size  = (int) get_option('pinery_flow_rating_size', 12);
    $price_style  = 'color:' . $price_color . ';font-size:' . $price_size . 'px;';
    $rating_style = 'color:' . $rating_color . ';font-size:' . $rating_size . 'px;';
    return '<div class="post-card-price-overlay">'
        . '<span class="overlay-price" style="' . $price_style . '">' . $price . '</span>'
        . '<span class="overlay-rating" style="' . $rating_style . '">★ ' . $rating . '</span>'
        . '</div>';
}
