<?php
/**
 * dashboard.php — dynamic member dashboard
 *
 * Replaces the old static HTML mockup. Pulls real data from
 * pinnadb7_customer (via the coach/objects POG classes, same pattern
 * used by member_homepage.php / member_profile.php):
 *   - baseline_bodycomposition : Body Weight / Body Fat % / Fat Weight /
 *                                Visceral Fat / Lean Body Mass / Muscle Mass
 *   - accountability_chart     : Daily Log Score (today + week cumulative)
 *   - food_journal             : Photo Food Journal recent activity
 *
 * Auth + layout follow the same include chain as member_homepage.php:
 * member_session.php -> member-header.php -> sidebar.php -> member-footer.php
 */

session_start(['gc_maxlifetime' => 14400, 'cookie_httponly' => true]);
ini_set('serialize_precision', -1); // avoid float-precision noise in json_encode()'d chart data
include('member_session.php');
include('../coach/functions.php');
include('../coach/objects/class.member.php');
include('../coach/objects/baseline_bodycomposition.class.php');
include('../coach/objects/food_journal.class.php');

function h(mixed $value): string
{
    return htmlspecialchars((string)($value ?? ''), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

function fnum(?float $value, int $decimals = 1): string
{
    return $value === null ? '—' : number_format($value, $decimals);
}

function grade_for_score(float $total): string
{
    if ($total == 0) { return 'A+'; }
    if ($total <= 2) { return 'A'; }
    if ($total <= 4) { return 'B+'; }
    if ($total <= 6) { return 'B'; }
    return 'C';
}

$memberid = (int)($_SESSION['memberid'] ?? 0);

$member_object = new Member();
$member        = $member_object->Get($memberid);

// ── Body composition history (Weight / Body Fat % / Fat Weight / Visceral Fat / Lean Mass / Muscle Mass) ──
$bodycomposition = new Baseline_bodycomposition();
$bodycomp_rows   = $bodycomposition->GetList([['member_id', '=', $memberid]], 'date', true);

// Filter out placeholder rows (blank/zero dates, zero weight) left over from the legacy import.
$bodycomp_rows = array_values(array_filter($bodycomp_rows, function ($row) {
    return !empty($row->date) && $row->date !== '0000-00-00' && (float)$row->weight > 0;
}));

$first_bodycomp  = $bodycomp_rows[0] ?? null;
$latest_bodycomp = !empty($bodycomp_rows) ? $bodycomp_rows[count($bodycomp_rows) - 1] : null;
$prev_bodycomp   = count($bodycomp_rows) > 1 ? $bodycomp_rows[count($bodycomp_rows) - 2] : null;

$stat_defs = [
    'weight'         => ['label' => 'Body Weight',      'unit' => 'Lbs'],
    'body_fat'       => ['label' => 'Body Fat Percent', 'unit' => '%'],
    'fat_weight'     => ['label' => 'Fat Weight',       'unit' => 'Lbs'],
    'visceral_fat'   => ['label' => 'Visceral Fat',     'unit' => ''],
    'lean_body_mass' => ['label' => 'Lean Body Mass',   'unit' => 'Lbs'],
    'muscle_mass'    => ['label' => 'Muscle Mass',      'unit' => 'Lbs'],
];

function metric_value(?object $row, string $key): ?float
{
    if ($row === null || $row->$key === '' || $row->$key === null) {
        return null;
    }
    $val = (float)$row->$key;
    return $val > 0 ? round($val, 1) : null;
}

$stats = [];
foreach ($stat_defs as $key => $def) {
    $latest = metric_value($latest_bodycomp, $key);
    $first  = metric_value($first_bodycomp, $key);
    $prev   = metric_value($prev_bodycomp, $key);
    $stats[$key] = [
        'label'       => $def['label'],
        'unit'        => $def['unit'],
        'latest'      => $latest,
        'started'     => $first,
        'change'      => ($latest !== null && $first !== null) ? $latest - $first : null,
        'prev'        => $prev,
        'prev_change' => ($latest !== null && $prev !== null) ? $latest - $prev : null,
    ];
}

// ── Progress chart date range (?range=1w|1m|3m|6m, default 3m) ──
$range = $_GET['range'] ?? '3m';
$range_options = [
    '1w' => '-1 week',
    '1m' => '-1 month',
    '3m' => '-3 months',
    '6m' => '-6 months',
];
if (!array_key_exists($range, $range_options)) {
    $range = '3m';
}
$chart_from_date = date('Y-m-d', strtotime($range_options[$range]));

$chart_rows = array_values(array_filter($bodycomp_rows, function ($row) use ($chart_from_date) {
    return $row->date >= $chart_from_date;
}));

$chart_categories = [];
$chart_weight = [];
$chart_bf     = [];
$chart_lean   = [];
$chart_muscle = [];

foreach ($chart_rows as $row) {
    $chart_categories[] = date('M d', strtotime($row->date));
    $chart_weight[]  = metric_value($row, 'weight');
    $chart_bf[]      = metric_value($row, 'body_fat');
    $chart_lean[]    = metric_value($row, 'lean_body_mass');
    $chart_muscle[]  = metric_value($row, 'muscle_mass');
}
$has_chart_data = count($chart_rows) > 0;

// ── Daily Log Score (today) + This Week's Cumulative Score ──
$today      = date('Y-m-d');
$week_start = $today;
$week_end   = $today;
for ($i = 0; $i < 7; $i++) {
    $d = date('Y-m-d', strtotime("-{$i} days", strtotime($today)));
    if (date('D', strtotime($d)) === 'Mon') { $week_start = $d; }
}
for ($i = 0; $i < 7; $i++) {
    $d = date('Y-m-d', strtotime("+{$i} days", strtotime($today)));
    if (date('D', strtotime($d)) === 'Sun') { $week_end = $d; }
}

$week_logs = $member_object->GetAccountability_chartList([
    ['log_date', '>=', $week_start],
    ['log_date', '<=', $week_end],
]);

$today_total = null;
$week_total  = 0.0;
foreach ($week_logs as $log) {
    $day_total = (float)$log->meal_score_totals + (float)$log->activity_total_score;
    $week_total += $day_total;
    if ($log->log_date === $today) {
        $today_total = $day_total;
    }
}
$today_grade = $today_total !== null ? grade_for_score($today_total) : null;
$week_grade  = !empty($week_logs) ? grade_for_score($week_total) : null;

// ── Recent Activity feed (body comp + daily log + food journal, merged & sorted) ──
$recent_logs = $member_object->GetAccountability_chartList([], 'log_date', false, '5');

$food_journal_obj = new Food_journal();
$recent_food      = $food_journal_obj->GetList([['member_id', '=', $memberid]], 'date', false, '5');

$recent_activity = [];

foreach (array_slice(array_reverse($bodycomp_rows), 0, 3) as $row) {
    $w  = metric_value($row, 'weight');
    $bf = metric_value($row, 'body_fat');
    $recent_activity[] = [
        'date'  => $row->date,
        'label' => 'Weight Logged',
        'value' => ($w !== null ? fnum($w) . ' Lbs' : '—') . ($bf !== null ? ' · Body Fat ' . fnum($bf) . '%' : ''),
    ];
}
foreach ($recent_logs as $log) {
    if (empty($log->log_date) || $log->log_date === '0000-00-00') {
        continue;
    }
    $tot = (float)$log->meal_score_totals + (float)$log->activity_total_score;
    $recent_activity[] = [
        'date'  => $log->log_date,
        'label' => 'Daily Tracker Completed',
        'value' => 'Score: ' . grade_for_score($tot),
    ];
}
foreach ($recent_food as $entry) {
    if (empty($entry->date)) {
        continue;
    }
    $recent_activity[] = [
        'date'  => date('Y-m-d', strtotime($entry->date)),
        'label' => 'Photo Food Journal Entry',
        'value' => h($entry->category),
    ];
}

usort($recent_activity, fn($a, $b) => strtotime($b['date']) <=> strtotime($a['date']));
$recent_activity = array_slice($recent_activity, 0, 6);

include('member-header.php');
?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
<link rel="stylesheet" href="./style.css">
<style>
.app-layout {
    width: 100%;
}
.page-header-title, .page-header-subtitle {
    padding: 0;
}
.dashboard-empty-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
}
.dashboard-empty-card p {
    color: var(--textSecondary, #212529b2);
    margin: 0 0 12px 0;
}
</style>

<div class="app-layout">
    <?php include('sidebar.php'); ?>
    <main class="main-content">

        <header class="page-header">
            <div class="page-header-meta">
                <div>
                    <h1 class="page-header-title">Dashboard</h1>
                    <p class="page-header-subtitle">View your progress, metrics, and activity at a glance</p>
                </div>
            </div>
        </header>

        <div class="body-content dashboard-body">

            <!-- Progress Summary -->
            <section class="dashboard-section">
                <div class="section-header">
                    <h2 class="dashboard-section-title">Progress Summary</h2>
                </div>

                <?php if (empty($bodycomp_rows)) { ?>
                    <div class="dashboard-empty-card">
                        <p>No body composition measurements yet.</p>
                        <?php if (in_array('body_composition', $remote_client, true) && $remoteClient == 1) { ?>
                            <a href="baseline.php" class="btn-ds-primary" style="display:inline-block;text-decoration:none;">Log Your First Entry</a>
                        <?php } else { ?>
                            <span class="stat-muted">Your trainer will add your first measurement.</span>
                        <?php } ?>
                    </div>
                <?php } else { ?>
                    <div class="stats-grid">
                        <?php foreach ($stats as $stat) { ?>
                            <div class="stat-card">
                                <div class="stat-header">
                                    <span class="stat-label"><?= h($stat['label']) ?></span>
                                </div>
                                <div class="stat-value"><?= fnum($stat['latest']) ?> <span class="stat-unit"><?= h($stat['unit']) ?></span></div>
                                <div class="stat-meta">
                                    <div class="stat-row">
                                        <span class="stat-muted"><span class="stat-muted-label">Started:</span> <?= fnum($stat['started']) ?> <?= h($stat['unit']) ?></span>
                                        <?php if ($stat['change'] !== null) { ?>
                                            <span class="stat-change <?= $stat['change'] <= 0 ? 'stat-change-down' : 'stat-change-up' ?>">
                                                <span class="stat-muted-label">Change:</span> <?= ($stat['change'] > 0 ? '+' : '') . fnum($stat['change']) ?>
                                                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                    <path d="M8 3.33301V12.6663" stroke="#4C78CE" stroke-linecap="round" stroke-linejoin="round" />
                                                    <path d="M12.6666 8L7.99998 12.6667L3.33331 8" stroke="#4C78CE" stroke-linecap="round" stroke-linejoin="round" />
                                                </svg>
                                            </span>
                                        <?php } ?>
                                    </div>
                                    <?php if ($stat['prev'] !== null) { ?>
                                    <div class="meta-detail-row">
                                        <span class="stat-muted"><span class="stat-muted-label">Last entry:</span> <?= fnum($stat['prev']) ?> <?= h($stat['unit']) ?></span>
                                        <?php if ($stat['prev_change'] !== null) { ?>
                                            <span class="stat-change <?= $stat['prev_change'] <= 0 ? 'stat-change-down' : 'stat-change-up' ?>">
                                                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                    <path d="M8 3.33301V12.6663" stroke="#4C78CE" stroke-linecap="round" stroke-linejoin="round" />
                                                    <path d="M12.6666 8L7.99998 12.6667L3.33331 8" stroke="#4C78CE" stroke-linecap="round" stroke-linejoin="round" />
                                                </svg>
                                                <?= ($stat['prev_change'] > 0 ? '+' : '') . fnum($stat['prev_change']) ?> <?= h($stat['unit']) ?>
                                            </span>
                                        <?php } ?>
                                    </div>
                                    <?php } ?>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                <?php } ?>
            </section>

            <!-- Progress Charts -->
            <section class="dashboard-section">
                <div class="charts-header">
                    <h2 class="dashboard-section-title">Progress Charts</h2>
                    <div class="white-black-filter-tabs" id="dashboard-chart-filter-tab">
                        <a href="?range=1w" class="white-black-filter-btn<?= $range === '1w' ? ' active' : '' ?>">1W</a>
                        <a href="?range=1m" class="white-black-filter-btn<?= $range === '1m' ? ' active' : '' ?>">1M</a>
                        <a href="?range=3m" class="white-black-filter-btn<?= $range === '3m' ? ' active' : '' ?>">3M</a>
                        <a href="?range=6m" class="white-black-filter-btn<?= $range === '6m' ? ' active' : '' ?>">6M</a>
                    </div>
                </div>
                <?php if (!$has_chart_data) { ?>
                    <div class="dashboard-empty-card">
                        <p>No measurements in this date range yet.</p>
                    </div>
                <?php } else { ?>
                    <div class="charts-grid">
                        <div class="mini-chart-card">
                            <h4 class="mini-chart-title">Body Weight</h4>
                            <div class="mini-chart-wrap">
                                <div id="chartBodyWeightMini"></div>
                            </div>
                        </div>
                        <div class="mini-chart-card">
                            <h4 class="mini-chart-title">Body Fat Percent</h4>
                            <div class="mini-chart-wrap">
                                <div id="chartBodyFatMini"></div>
                            </div>
                        </div>
                        <div class="mini-chart-card">
                            <h4 class="mini-chart-title">Lean Body Mass</h4>
                            <div class="mini-chart-wrap">
                                <div id="chartLeanMassMini"></div>
                            </div>
                        </div>
                        <div class="mini-chart-card">
                            <h4 class="mini-chart-title">Muscle Mass</h4>
                            <div class="mini-chart-wrap">
                                <div id="chartMuscleMassMini"></div>
                            </div>
                        </div>
                    </div>
                <?php } ?>
            </section>

            <!-- Activity & Tracking + Quick Access Row -->
            <section class="dashboard-section">
                <div class="activity-quick-row">
                    <!-- Activity & Tracking -->
                    <div class="activity-tracking-col">
                        <div class="section-header">
                            <h2 class="dashboard-section-title">Activity & Tracking</h2>
                        </div>
                        <div class="activity-cards-row">
                            <!-- Daily Log Score -->
                            <div class="activity-card">
                                <h4 class="activity-card-title">Daily Log Score</h4>
                                <div class="score-badge"><?= $today_grade !== null ? h($today_grade) : '—' ?></div>
                                <div class="score-label">
                                    <?php if ($today_grade !== null) { ?>
                                        Today's Score
                                    <?php } else { ?>
                                        <a href="member_homepage.php">Log Today's Entry &rarr;</a>
                                    <?php } ?>
                                </div>
                                <div class="score-cumulative">
                                    <span class="score-cumulative-label">This Weeks Cumulative Score</span>
                                    <span class="score-cumulative-value"><?= $week_grade !== null ? h($week_grade) : '—' ?></span>
                                </div>
                            </div>
                            <!-- Latest Progress Entry -->
                            <div class="activity-card activity-card-entry">
                                <h4 class="activity-card-title">Latest Progress Entry</h4>
                                <?php if ($latest_bodycomp === null) { ?>
                                    <div class="entry-date">No entries yet</div>
                                <?php } else { ?>
                                    <div class="entry-date"><?= h(date('M d, Y', strtotime($latest_bodycomp->date))) ?></div>
                                    <div class="entry-details-arrow">
                                        <div class="entry-details">
                                            <div class="entry-item">
                                                <span>Weight: <strong><?= fnum(metric_value($latest_bodycomp, 'weight')) ?> lbs</strong></span>
                                            </div>
                                            <div class="entry-item">
                                                <span>Body Fat: <strong><?= fnum(metric_value($latest_bodycomp, 'body_fat')) ?> %</strong></span>
                                            </div>
                                            <div class="entry-item">
                                                <span>Lean Body Mass: <strong><?= fnum(metric_value($latest_bodycomp, 'lean_body_mass')) ?> lbs</strong></span>
                                            </div>
                                        </div>
                                        <a href="body_composition_chart.php" class="entry-arrow">
                                            <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                <path d="M9 18L15 12L9 6" stroke="black" stroke-opacity="0.5" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round" />
                                            </svg>
                                        </a>
                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                    </div>

                    <!-- Quick Access -->
                    <div class="quick-access-col">
                        <div class="section-header">
                            <h2 class="dashboard-section-title">Quick Access</h2>
                        </div>
                        <div class="quick-access-grid">
                            <a href="member_homepage.php" class="quick-access-card">
                                <div class="quick-access-icon">
                                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
                                        <path d="M2 6h4M2 10h4M2 14h4M2 18h4M18 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V4a2 2 0 00-2-2z" />
                                        <path d="M16 2v20" />
                                    </svg>
                                </div>
                                <span class="quick-access-label">Daily Log</span>
                            </a>
                            <?php if (!(in_array('member_document', $remote_client, true) && $remoteClient == 1)) { ?>
                            <a href="member_document.php" class="quick-access-card">
                                <div class="quick-access-icon">
                                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
                                        <path d="M19 3H5a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2V5a2 2 0 00-2-2z" />
                                        <path d="M17 12h-2l-2 5-2-10-2 5H7" />
                                    </svg>
                                </div>
                                <span class="quick-access-label">Training Program</span>
                            </a>
                            <?php } ?>
                            <?php if (!(in_array('graphs_and_charts', $remote_client, true) && $remoteClient == 1)) { ?>
                            <a href="graphs_charts.php" class="quick-access-card">
                                <div class="quick-access-icon">
                                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
                                        <path d="M12 16v5M16 14v7M20 10v11M22 3l-8.646 8.646a.5.5 0 01-.708 0L9.354 8.354a.5.5 0 00-.708 0L2 15" />
                                        <path d="M4 18v3M8 14v7" />
                                    </svg>
                                </div>
                                <span class="quick-access-label">Graphs &amp; Charts</span>
                            </a>
                            <?php } ?>
                            <?php if ($foodJournal == 1) { ?>
                            <a href="foodjournal_list.php" class="quick-access-card">
                                <div class="quick-access-icon">
                                    <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
                                        <path d="M14 3H5a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2V8l-5-5z" />
                                        <path d="M14 3v5h5" />
                                        <path d="M12 13a3 3 0 100 6 3 3 0 000-6z" />
                                    </svg>
                                </div>
                                <span class="quick-access-label">Photo Food Journal</span>
                            </a>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Recent Activity -->
            <section class="dashboard-section">
                <div class="recent-activity-card">
                    <div class="recent-activity-header">
                        <h2 class="recent-activity-title">Recent Activity</h2>
                    </div>
                    <?php if (empty($recent_activity)) { ?>
                        <div class="dashboard-empty-card">
                            <p>No recent activity yet — log a daily entry or a measurement to get started.</p>
                        </div>
                    <?php } else { ?>
                        <div class="activity-list">
                            <?php foreach ($recent_activity as $activity) { ?>
                                <div class="activity-item">
                                    <div class="activity-date"><?= h(date('M d', strtotime($activity['date']))) ?></div>
                                    <div class="activity-item-details">
                                        <div class="activity-icon-desc">
                                            <div class="activity-icon">
                                                <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                    <path d="M8.00065 14.6663C11.6825 14.6663 14.6673 11.6816 14.6673 7.99967C14.6673 4.31778 11.6825 1.33301 8.00065 1.33301C4.31875 1.33301 1.33398 4.31778 1.33398 7.99967C1.33398 11.6816 4.31875 14.6663 8.00065 14.6663Z" stroke="#4C78CE" stroke-linecap="round" stroke-linejoin="round" />
                                                    <path d="M6 8.00033L7.33333 9.33366L10 6.66699" stroke="#4C78CE" stroke-linecap="round" stroke-linejoin="round" />
                                                </svg>
                                            </div>
                                            <div class="activity-desc"><?= h($activity['label']) ?></div>
                                        </div>
                                        <div class="activity-value"><?= $activity['value'] ?></div>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>
                    <?php } ?>
                </div>
            </section>

        </div>
    </main>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<?php if ($has_chart_data) { ?>
<script src="https://cdn.jsdelivr.net/npm/apexcharts@3.54.0/dist/apexcharts.min.js"></script>
<script>
    const chartCategories = <?= json_encode($chart_categories) ?>;

    function createMiniChartOptions(color, data, unit, metricLabel) {
        return {
            chart: {
                type: 'area',
                height: 160,
                width: '100%',
                toolbar: { show: false },
                sparkline: { enabled: false },
                parentHeightOffset: 0,
                redrawOnParentResize: true,
                redrawOnWindowResize: true,
                offsetX: -8,
            },
            series: [{ name: metricLabel, data: data }],
            colors: [color],
            fill: {
                type: 'gradient',
                gradient: { shadeIntensity: 1, opacityFrom: 0.75, opacityTo: 0.05, stops: [0, 95, 100] }
            },
            stroke: { curve: 'smooth', width: 2.5, lineCap: 'round' },
            dataLabels: { enabled: false },
            grid: {
                show: true,
                borderColor: '#F3F4F6',
                strokeDashArray: 0,
                padding: { top: 4, right: 8, bottom: 0, left: 4 },
                xaxis: { lines: { show: false } },
                yaxis: { lines: { show: true } }
            },
            xaxis: {
                categories: chartCategories,
                axisBorder: { show: false },
                axisTicks: { show: false },
                labels: { show: true, style: { colors: '#9CA3AF', fontSize: '10px' } },
                tooltip: { enabled: false }
            },
            yaxis: {
                show: true,
                tickAmount: 3,
                labels: {
                    offsetX: -8,
                    style: { colors: '#9CA3AF', fontSize: '10px' },
                    formatter: (val) => (val === null || val === undefined) ? '' : val.toFixed(0)
                }
            },
            tooltip: {
                theme: false,
                custom: function ({ series, seriesIndex, dataPointIndex }) {
                    const val = series[seriesIndex][dataPointIndex];
                    const date = chartCategories[dataPointIndex];
                    return `<div class="mini-chart-tooltip-card">
                        <div class="mini-chart-tooltip-date">Date: ${date}</div>
                        <div class="mini-chart-tooltip-value">${val === null ? '—' : val.toFixed(1) + ' ' + unit}</div>
                    </div>`;
                }
            },
            markers: { size: 0, hover: { size: 5 } }
        };
    }

    const miniChartData = {
        bodyWeight: <?= json_encode($chart_weight) ?>,
        bodyFat:    <?= json_encode($chart_bf) ?>,
        leanMass:   <?= json_encode($chart_lean) ?>,
        muscleMass: <?= json_encode($chart_muscle) ?>
    };

    const miniCharts = [
        new ApexCharts(document.querySelector("#chartBodyWeightMini"),
            createMiniChartOptions('#3B82F6', miniChartData.bodyWeight, 'Lbs', 'Body Weight')),
        new ApexCharts(document.querySelector("#chartBodyFatMini"),
            createMiniChartOptions('#EF4444', miniChartData.bodyFat, '%', 'Body Fat')),
        new ApexCharts(document.querySelector("#chartLeanMassMini"),
            createMiniChartOptions('#8B5CF6', miniChartData.leanMass, 'Lbs', 'Lean Body Mass')),
        new ApexCharts(document.querySelector("#chartMuscleMassMini"),
            createMiniChartOptions('#10B981', miniChartData.muscleMass, 'Lbs', 'Muscle Mass'))
    ];

    Promise.all(miniCharts.map(c => c.render())).then(() => {
        window.dispatchEvent(new Event('resize'));
    });
</script>
<?php } ?>

<?php include('member-footer.php'); ?>
