<?php
/**
 * Branding Handler
 * 
 * Handles logo, favicon, colors, and login page customization.
 * 
 * @package WooNooW
 */

namespace WooNooW;

class Branding {
    
    /**
     * Initialize branding
     */
    public static function init() {
        // Apply colors to admin
        add_action('admin_head', [__CLASS__, 'inject_colors']);
        
        // Apply favicon
        add_action('wp_head', [__CLASS__, 'inject_favicon']);
        add_action('admin_head', [__CLASS__, 'inject_favicon']);
        
        // Note: Login page branding removed - WooNooW uses standalone SPA login
    }
    
    /**
     * Inject brand colors as CSS variables
     */
    public static function inject_colors() {
        $primary = get_option('woonoow_primary_color', '#3b82f6');
        $accent = get_option('woonoow_accent_color', '#10b981');
        $error = get_option('woonoow_error_color', '#ef4444');
        
        ?>
        <style id="woonoow-brand-colors">
            :root {
                --woonoow-primary: <?php echo esc_attr($primary); ?>;
                --woonoow-accent: <?php echo esc_attr($accent); ?>;
                --woonoow-error: <?php echo esc_attr($error); ?>;
            }
        </style>
        <?php
    }
    
    /**
     * Inject favicon
     */
    public static function inject_favicon() {
        $icon = get_option('woonoow_store_icon', '');
        
        if (!empty($icon)) {
            ?>
            <link rel="icon" type="image/png" href="<?php echo esc_url($icon); ?>" />
            <link rel="apple-touch-icon" href="<?php echo esc_url($icon); ?>" />
            <?php
        }
    }
    
    /**
     * Get logo URL or fallback to text
     * 
     * @return array ['type' => 'image'|'text', 'value' => string]
     */
    public static function get_logo() {
        $logo = get_option('woonoow_store_logo', '');
        
        if (!empty($logo)) {
            return [
                'type' => 'image',
                'value' => $logo,
            ];
        }
        
        return [
            'type' => 'text',
            'value' => get_option('blogname', 'WooNooW'),
        ];
    }
}
