<?php
function aump_enqueue_dynamic_css() {
    // Enqueue a dummy style if needed (can be your main plugin style handle if exists)
    $handle = 'aump-dynamic-style';
    wp_register_style($handle, false); // Register a handle without a file
    wp_enqueue_style($handle);

    $aump_columns = esc_attr(get_option('aump_columns', 3));
    $aump_grid_border_clr = esc_attr(get_option('aump_grid_border_clr'));
    $aump_open_button_bg = esc_attr(get_option('aump_open_button_bg'));
    $aump_open_button_text_color = esc_attr(get_option('aump_open_button_text_color'));
    $aump_title_color = esc_attr(get_option('aump_title_color'));
    $aump_title_bg = esc_attr(get_option('aump_title_bg'));
    $aump_desc_color = esc_attr(get_option('aump_desc_color'));
    $aump_desc_bg = esc_attr(get_option('aump_desc_bg'));
    $aump_load_more_button_bg = esc_attr(get_option('aump_load_more_button_bg'));
    $aump_load_more_button_text_color = esc_attr(get_option('aump_load_more_button_text_color'));
    $aump_category_filter_bg = esc_attr(get_option('aump_category_filter_bg'));
    $aump_category_filter_text_colour = esc_attr(get_option('aump_category_filter_text_colour'));
    $aump_next_prev_text_color = esc_attr(get_option('aump_next_prev_text_color'));
    $aump_next_prev_bg = esc_attr(get_option('aump_next_prev_bg'));
    $aump_grid_image_height_desktop = esc_attr(get_option('aump_grid_image_height_desktop'));
    $aump_grid_image_height_mobile = esc_attr(get_option('aump_grid_image_height_mobile'));    
    $aump_enable_featured_image_on_popup = get_option('aump_enable_featured_image_on_popup') ? 'block' : 'none';
    $popup_width = esc_attr(get_option('aump_popup_width', 70));    
    $aump_hide_title_on_popup = get_option('aump_hide_title_on_popup') ? 'none' : 'block';
    $aump_hide_categories_on_popup = get_option('aump_hide_categories_on_popup') ? 'none' : 'block';    
    $aump_popup_bg_color = esc_attr(get_option('aump_popup_bg_color'));

    $custom_css = "
        @media (min-width: 981px) {
            .aump_et_pb_portfolio_grid_items, .aump_et_pb_portfolio_items {
                display: grid;
                grid-template-columns: repeat({$aump_columns}, 1fr);
                gap: 20px;
            }
            .aump_popup-content {
                width: {$popup_width}% !important;
            }
            a.aump_wrapper-link-custom {
                height: {$aump_grid_image_height_desktop}px !important;
            }
        }

        @media (max-width: 981px) {
            a.aump_wrapper-link-custom {
                height: {$aump_grid_image_height_mobile}px !important;
            }
        }

        .aump_project.type-project.status-publish {
            border-color: {$aump_grid_border_clr} !important;
        }

        a.aump_portfolio-details-button {
            background: {$aump_open_button_bg} !important;
            color: {$aump_open_button_text_color} !important;
        }

        .aump_et_pb_module_header {
            color: {$aump_title_color} !important;
            background: {$aump_title_bg} !important;
        }

        .aump_portfolio-description {
            color: {$aump_desc_color} !important;
            background: {$aump_desc_bg} !important;
        }

        #aump_load-more-btn {
            color: {$aump_load_more_button_text_color} !important;
            background: {$aump_load_more_button_bg} !important;
        }

        span.aump_active {
            color: {$aump_category_filter_text_colour} !important;
            background: {$aump_category_filter_bg} !important;
        }

        div#aump_popup-content-area .aump_featured-image-wrapper {
            display: {$aump_enable_featured_image_on_popup} !important;
        }

        span.aump_previous-button-circle, span.aump_next-button-circle {
            border-color: {$aump_next_prev_text_color} !important;
        }

        button.aump_prev-project:hover span.aump_previous-button-circle,
        button.aump_next-project:hover span.aump_next-button-circle {
            background: {$aump_next_prev_bg} !important;
        }

        .aump_portfolio-title {
            display: {$aump_hide_title_on_popup} !important;
        }

        .aump_portfolio-categories {
            display: {$aump_hide_categories_on_popup} !important;
        }

        .aump_popup-content, .aump_popup-header {
            background: {$aump_popup_bg_color} !important;
        }
    ";

    wp_add_inline_style($handle, $custom_css);
}
add_action('wp_enqueue_scripts', 'aump_enqueue_dynamic_css');