<?php
/**
 * DACdb Plus Club Leaders Display Function
 *
 * Retrieves and displays club leadership information based on specified roles and styling preferences.
 * This function interfaces with the DACdb API to fetch club officer data and render it in various
 * customizable formats.
 *
 * @package    DACdbPlus
 * @subpackage Display
 * @since      1.0.0
 * @author     Member Minder Pro, LLC (@memberminderpro)
 * 
 * @see        dacdb_DisplayClub() For the actual rendering of club data
 * @link       https://github.com/memberminderpro/dacdbplus/
 */

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Generates HTML output for club leaders based on specified parameters
 *
 * @since 1.0.0
 *
 * @param array $atts {
 *     Optional. An array of attributes for customizing the display.
 *
 *     @type string $rolekeys Comma-separated list of role keys to filter leaders (default 'P,S')
 *     @type int    $style    Display style number (default 1)
 * }
 * @return string HTML formatted string containing club leaders' information
 */
function dacdb_clubleaders($atts)
{
    global $fDebug, $data_path, $file_path, $options;

    $members = '';

    // #region Configuration and Setup
    $account_id = $options['dacdb_district'];
    $club_id    = $options['dacdb_club'];
    $rolekeys   = isset($atts['rolekeys']) ? $atts['rolekeys'] : 'P,S';
    $style      = isset($atts['style']) ? $atts['style'] : 1;
    // #endregion

    // #region Debug Output
    if ($fDebug) {
        $members .= "=================================================================<BR>";
        $members .= "function dacdb_clubleaders called <br>";
        $members .= "AccountID=" . $account_id . "<br>";
        $members .= "ClubID=" . $club_id . "<br>";
        $members .= "Style=" . $style . "<br>";
        $members .= "RoleKeys=" . $rolekeys . "<br>";
        $members .= "URL=" . $data_path . 'wp_clubleaders.cfm?AccountID=' . $account_id . '&ClubID=' . $club_id . '&rolekeys=' . $rolekeys . "<br>";
        $members .= "=================================================================<BR>";
    }
    // #endregion

    // #region Data Retrieval
    // Construct and execute API request
    $xml = simplexml_load_file($data_path . 'wp_clubleaders.cfm?AccountID=' . $account_id . 
           '&ClubID=' . $club_id . '&rolekeys=' . $rolekeys . '&R=' . rand());

    // Handle empty response
    if (empty($xml)) {
        $members .= 'There are no club leaders to display at this time.';
        return $members;
    }
    // #endregion

    // #region Display Generation
    // Process XML data and generate HTML output
    $members .= dacdb_DisplayClub($xml, $style, $atts);
    // #endregion

    return $members;
}