<?php
/**
 * DACdb Plus Enqueue Functions
 *
 * @package    DACdb Plus
 * @subpackage Enqueue
 * @author     Member Minder Pro, LLC
 * @copyright  2024 Member Minder Pro, LLC
 * @license    GPL-2.0+
 * @link       https://github.com/memberminderpro/dacdbplus
 * 
 * This file handles all style enqueuing for the DACdb Plus plugin.
 * It manages Bootstrap, main plugin styles, and conditional shortcode-specific styles.
 */

// ANCHOR: Main Style Enqueue Function
/**
 * Enqueues all necessary styles for DACdb Plus plugin
 * 
 * @since 1.0.0
 * @return void
 */
function dacdb_enqueue_styles()
{
    global $post;

    // SECTION: Core Styles
    // NOTE: Bootstrap is only enqueued if not already present
    if (!wp_style_is('bootstrap', 'enqueued')) {
        wp_enqueue_style('dacdb-bootstrap', 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css', array(), '4.4.1');
    }

    // SECTION: Plugin-specific Styles
    wp_enqueue_style('dacdb-main', plugins_url('css/dacdbplus.css', __FILE__), array(), MMPDB_PLUGIN_VERSION);
    wp_enqueue_style('dacdb-social-media', plugins_url('css/sm.css', __FILE__), array(), MMPDB_PLUGIN_VERSION);
    wp_enqueue_style('mmp-rotary-colors', 'https://cdn.jsdelivr.net/gh/memberminderpro/rotary-brand-assets@latest/css/rotary-colors.css', array(), MMPDB_PLUGIN_VERSION);

    // SECTION: Conditional Shortcode Styles
    // NOTE: These styles are only loaded when their respective shortcodes are present
    if (is_a($post, 'WP_Post')) {
        // LINK: css/show-stories.css
        if (has_shortcode($post->post_content, 'dacdb_stories')) {
            wp_enqueue_style('show-stories', MMPDB_PLUGIN_URL . 'css/show-stories.css', array(), MMPDB_PLUGIN_VERSION);
        }
        // LINK: css/show-sponsors.css
        if (has_shortcode($post->post_content, 'dacdb_sponsors')) {
            wp_enqueue_style('show-sponsors', MMPDB_PLUGIN_URL . 'css/show-sponsors.css', array(), MMPDB_PLUGIN_VERSION);
        }
    }
}

// TODO: Consider adding version-specific Bootstrap enqueuing
// REVIEW: Evaluate if Bootstrap version should be updated to latest
// FIXME: Add error handling for failed style enqueuing
