<?php
declare(strict_types=1);

use App\Core\EventBus;

// Menu registered centrally via Members/bootstrap.php under "membership" parent.

EventBus::listen('member.profile_data', function (array &$data) {
    if (isset($data['member']) && $data['member']) {
        $memberId = is_object($data['member']) ? (int) $data['member']->id : (int) ($data['member']['id'] ?? 0);
        if ($memberId > 0) {
            try {
                $db = \App\Core\App::getInstance()->db();
                if ($db->tableExists('seasonal_memberships')) {
                    $data['seasonal'] = $db->select(
                        "SELECT s.*, b.name_ar as branch_name FROM seasonal_memberships s JOIN branches b ON b.id = s.branch_id WHERE s.member_id = ? AND s.is_archived = 0 ORDER BY s.start_date DESC",
                        [$memberId]
                    );
                }
            } catch (\Throwable $e) {}
        }
    }
});