<?php
/**
 * WeTheme Options CSS
 */

// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Get theme options
$primary_color = wetheme_get_primary_color();
$secondary_color = wetheme_get_secondary_color();
$text_color = wetheme_get_text_color();
$link_color = wetheme_get_link_color();
$link_hover_color = wetheme_get_link_hover_color();
$body_font = wetheme_get_body_font();
$heading_font = wetheme_get_heading_font();
$menu_font = wetheme_get_menu_font();

// Generate CSS
$css = '';

// Body font
if ( ! empty( $body_font ) ) {
    $css .= ':root {';
    if ( ! empty( $body_font['font-family'] ) ) {
        $css .= '--body-font-family: ' . $body_font['font-family'] . ';';
    }
    if ( ! empty( $body_font['font-size'] ) ) {
        $css .= '--body-font-size: ' . $body_font['font-size'] . ';';
    }
    if ( ! empty( $body_font['line-height'] ) ) {
        $css .= '--body-line-height: ' . $body_font['line-height'] . ';';
    }
    if ( ! empty( $body_font['color'] ) ) {
        $css .= '--body-color: ' . $body_font['color'] . ';';
    }
    $css .= '}';
    
    $css .= 'body {';
    if ( ! empty( $body_font['font-family'] ) ) {
        $css .= 'font-family: ' . $body_font['font-family'] . ';';
    }
    if ( ! empty( $body_font['font-size'] ) ) {
        $css .= 'font-size: ' . $body_font['font-size'] . ';';
    }
    if ( ! empty( $body_font['line-height'] ) ) {
        $css .= 'line-height: ' . $body_font['line-height'] . ';';
    }
    if ( ! empty( $body_font['color'] ) ) {
        $css .= 'color: ' . $body_font['color'] . ';';
    }
    $css .= '}';
}

// Heading font
if ( ! empty( $heading_font ) ) {
    $css .= 'h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {';
    if ( ! empty( $heading_font['font-family'] ) ) {
        $css .= 'font-family: ' . $heading_font['font-family'] . ';';
    }
    if ( ! empty( $heading_font['font-weight'] ) ) {
        $css .= 'font-weight: ' . $heading_font['font-weight'] . ';';
    }
    if ( ! empty( $heading_font['color'] ) ) {
        $css .= 'color: ' . $heading_font['color'] . ';';
    }
    $css .= '}';
}

// Menu font
if ( ! empty( $menu_font ) ) {
    $css .= '.main-navigation, .main-navigation a, .menu-item a {';
    if ( ! empty( $menu_font['font-family'] ) ) {
        $css .= 'font-family: ' . $menu_font['font-family'] . ';';
    }
    if ( ! empty( $menu_font['font-size'] ) ) {
        $css .= 'font-size: ' . $menu_font['font-size'] . ';';
    }
    if ( ! empty( $menu_font['font-weight'] ) ) {
        $css .= 'font-weight: ' . $menu_font['font-weight'] . ';';
    }
    $css .= '}';
}

// Colors
$css .= ':root {';
$css .= '--primary-color: ' . $primary_color . ';';
$css .= '--secondary-color: ' . $secondary_color . ';';
$css .= '--text-color: ' . $text_color . ';';
$css .= '--link-color: ' . $link_color . ';';
$css .= '--link-hover-color: ' . $link_hover_color . ';';
$css .= '}';

// Primary color usage
$css .= '.btn-primary, .button-primary, .woocommerce a.button.alt, .woocommerce button.button.alt, .woocommerce input.button.alt {';
$css .= 'background-color: ' . $primary_color . ';';
$css .= 'border-color: ' . $primary_color . ';';
$css .= '}';

$css .= '.btn-primary:hover, .button-primary:hover, .woocommerce a.button.alt:hover, .woocommerce button.button.alt:hover, .woocommerce input.button.alt:hover {';
$css .= 'background-color: ' . $secondary_color . ';';
$css .= 'border-color: ' . $secondary_color . ';';
$css .= '}';

// Link colors
$css .= 'a {';
$css .= 'color: ' . $link_color . ';';
$css .= '}';

$css .= 'a:hover {';
$css .= 'color: ' . $link_hover_color . ';';
$css .= '}';

// Text color
$css .= 'body, p, .text-muted {';
$css .= 'color: ' . $text_color . ';';
$css .= '}';

// Output CSS
echo $css;
