<?php
$currentAccountPage = basename((string)($_SERVER['SCRIPT_NAME'] ?? ''));
$accountSideUserId = (int)($_SESSION['user_id'] ?? 0);
if (!function_exists('mj_account_side_feature')) { function mj_account_side_feature(string $code, int $userId): bool { return module_enabled($code) && mj_user_feature_enabled($code, $userId); } }
if (!function_exists('mj_account_side_active')) { function mj_account_side_active(array $files, string $current): string { return in_array($current, $files, true) ? 'active' : ''; } }
?>
<aside class="side-menu" aria-label="Account navigation">
  <span class="mj-side-section">Main</span>
  <a class="<?=mj_account_side_active(['my-account.php'],$currentAccountPage)?>" href="<?=base_url('my-account.php')?>"><i class="bi bi-speedometer2"></i> Dashboard</a>
  <a class="<?=mj_account_side_active(['notifications.php'],$currentAccountPage)?>" href="<?=base_url('notifications.php')?>"><i class="bi bi-bell"></i> Notifications</a>

  <span class="mj-side-section">Centers</span>
  <?php if (mj_account_side_feature('selling_center', $accountSideUserId)): ?><a class="<?=mj_account_side_active(['selling-center.php','my-listings.php','my-companies.php','my-deals.php','deal-create.php','deal-edit.php','my-deal-enquiries.php','edit-listing.php','post-listing.php','company-edit.php','add-company.php','company-page-builder.php','booking-settings.php'],$currentAccountPage)?>" href="<?=base_url('selling-center.php')?>"><i class="bi bi-shop-window"></i> Selling Center</a>
  <a class="<?=mj_account_side_active(['my-deals.php','deal-create.php','deal-edit.php','my-deal-enquiries.php'],$currentAccountPage)?>" href="<?=base_url('my-deals.php')?>"><i class="bi bi-fire"></i> My Deals</a><?php endif; ?>
  <?php if (mj_account_side_feature('buying_center', $accountSideUserId)): ?><a class="<?=mj_account_side_active(['buying-center.php','messages.php','chat.php','my-offers.php','my-quotes.php','my-orders.php','saved.php','saved-deals.php','appointments.php'],$currentAccountPage)?>" href="<?=base_url('buying-center.php')?>"><i class="bi bi-bag-heart"></i> Buying Center</a><?php endif; ?>
  <?php if (mj_account_side_feature('crm_leads', $accountSideUserId)): ?><a class="<?=mj_account_side_active(['my-leads.php','crm-leads.php','my-customers.php','customer-view.php'],$currentAccountPage)?>" href="<?=base_url('my-leads.php')?>"><i class="bi bi-kanban"></i> CRM / Leads</a><?php endif; ?>
  <?php if (mj_account_side_feature('appointment_booking', $accountSideUserId)): ?><a class="<?=mj_account_side_active(['appointments.php','company-bookings.php'],$currentAccountPage)?>" href="<?=base_url('appointments.php')?>"><i class="bi bi-calendar-check"></i> Appointments</a><?php endif; ?>

  <span class="mj-side-section">Account</span>
  <?php if (mj_account_side_feature('account_center', $accountSideUserId)): ?><a class="<?=mj_account_side_active(['account-center.php','account-settings.php','notification-settings.php'],$currentAccountPage)?>" href="<?=base_url('account-center.php')?>"><i class="bi bi-person-gear"></i> Account Center</a><?php endif; ?>
  <?php if (mj_account_side_feature('billing_payments', $accountSideUserId)): ?><a class="<?=mj_account_side_active(['billing-payments.php','wallet.php','my-upgrade-payments.php','invoice-view.php','checkout.php','packages.php','request-more-slots.php'],$currentAccountPage)?>" href="<?=base_url('billing-payments.php')?>"><i class="bi bi-credit-card-2-front"></i> Billing & Payments</a><?php endif; ?>
  <?php if (mj_account_side_feature('billing_payments', $accountSideUserId)): ?><a class="<?=($_GET['tab'] ?? '')==='cart' ? 'active' : ''?>" href="<?=base_url('billing-payments.php?tab=cart')?>"><i class="bi bi-cart3"></i> Service Cart <?php if(function_exists('mj2919_cart_count') && ($mjSideCart=mj2919_cart_count($accountSideUserId))>0): ?><span class="badge bg-primary ms-1"><?=e($mjSideCart)?></span><?php endif; ?></a><?php endif; ?>
  <?php if (mj_account_side_feature('trust_verification', $accountSideUserId)): ?><a class="<?=mj_account_side_active(['trust-verification.php','verification.php','privacy-center.php','my-reviews.php','report.php'],$currentAccountPage)?>" href="<?=base_url('trust-verification.php')?>"><i class="bi bi-shield-check"></i> Trust & Verification</a><?php endif; ?>
  <?php if (mj_account_side_feature('support_center', $accountSideUserId)): ?><a class="<?=mj_account_side_active(['help-support.php','help.php','safety.php'],$currentAccountPage)?>" href="<?=base_url('help-support.php')?>"><i class="bi bi-headset"></i> Help & Support</a><?php endif; ?>
</aside>
