<?php
require_once __DIR__.'/includes/functions.php';
$user = require_user();
mj_require_user_feature('selling_center', (int)$user['id']);
$pageTitle = 'Selling Center';
$limits=function_exists('mj_v300_user_limits')?mj_v300_user_limits((int)$user['id']):['max_listings'=>0,'max_companies'=>0,'max_deals'=>0];
$dealLimit=function_exists('mj_v300_deal_limit_status')?mj_v300_deal_limit_status((int)$user['id']):['used'=>0,'max'=>0];
$perfData=function_exists('mj_v300_user_performance_data')?mj_v300_user_performance_data((int)$user['id']):[];

include __DIR__.'/includes/header.php';
?>
<section class="mj-section">
  <div class="container">
    <div class="mj-center-shell">
      <?php include __DIR__.'/includes/account-sidebar.php'; ?>
      <div class="mj-center-main">
        <div class="mj-section-title mb-4">
          <div><span class="mj-badge mb-2"><i class="bi bi-shop-window"></i> Seller tools</span><h1 class="h2 fw-bold mb-1">Selling Center</h1><p class="text-muted mb-0">Everything for listings, companies, CRM, booking, renewals and upgrades in one place.</p></div>
        </div>
        
<div class="row g-3 mb-4">
  <div class="col-md-3"><div class="mj-stat-tile"><small class="text-muted">Active Listings</small><b class="d-block"><?=e(mj_v288_count('mj_listings','user_id=? AND (status IS NULL OR status NOT IN (\'rejected\',\'deleted\'))',[(int)$user['id']]))?></b></div></div>
  <div class="col-md-3"><div class="mj-stat-tile"><small class="text-muted">Companies</small><b class="d-block"><?=e(mj_v288_count('mj_companies','user_id=?',[(int)$user['id']]))?></b></div></div>
  <div class="col-md-3"><div class="mj-stat-tile"><small class="text-muted">Deals</small><b class="d-block"><?=e($dealLimit['used'] ?? 0)?> / <?=e($dealLimit['max'] ?? 0)?></b></div></div>
  <div class="col-md-3"><div class="mj-stat-tile"><small class="text-muted">Payment Proofs</small><b class="d-block"><?=e(mj_v288_count('mj_upgrade_payment_proofs','user_id=?',[(int)$user['id']]))?></b></div></div>
</div>
<div class="row g-3 mb-4"><div class="col-md-4"><?php mj_v300_render_limit_card('Listings', mj_v288_count('mj_listings',"user_id=? AND (status IS NULL OR status NOT IN ('rejected','deleted'))",[(int)$user['id']]), (int)$limits['max_listings'], base_url('billing-payments.php?tab=cart'), 'bi-tags'); ?></div><div class="col-md-4"><?php mj_v300_render_limit_card('Companies', mj_v288_count('mj_companies','user_id=?',[(int)$user['id']]), (int)$limits['max_companies'], base_url('billing-payments.php?tab=cart'), 'bi-building'); ?></div><div class="col-md-4"><?php mj_v300_render_limit_card('Deals', (int)$dealLimit['used'], (int)$dealLimit['max'], base_url('billing-payments.php?tab=cart'), 'bi-fire'); ?></div></div><div class="mj-v3-chart-card mb-4" data-chart-type="bar" data-mj-v3-chart="<?=mj_v300_chart_data_attr($perfData)?>"><h3>Lead performance</h3><p>Your listing/deal views, enquiries and click actions.</p></div>
<div class="mj-module-grid mb-4">
  <a class="mj-module-tile" href="<?=base_url('my-listings.php')?>"><i class="bi bi-tags"></i><b>My Listings</b><small>Post, edit, renew, sponsor, feature and check listing health.</small></a>
  <a class="mj-module-tile" href="<?=base_url('my-companies.php')?>"><i class="bi bi-building"></i><b>My Companies</b><small>Manage company profiles, branches, staff and limits.</small></a>
  <a class="mj-module-tile" href="<?=base_url('my-deals.php')?>"><i class="bi bi-fire"></i><b>My Deals</b><small>Create display-only deals and collect WhatsApp/call/email enquiries.</small></a>
  <a class="mj-module-tile" href="<?=base_url('company-page-builder.php')?>"><i class="bi bi-palette"></i><b>Company Page Builder</b><small>Custom cover, color, sections, SEO and preview.</small></a>
  <a class="mj-module-tile" href="<?=base_url('booking-settings.php')?>"><i class="bi bi-calendar2-check"></i><b>Booking Settings</b><small>Enable appointment booking, slots and approval rules.</small></a>
  <a class="mj-module-tile" href="<?=base_url('crm-leads.php')?>"><i class="bi bi-kanban"></i><b>CRM / Leads</b><small>Follow up enquiries, notes, tags and customer timeline.</small></a>
  <a class="mj-module-tile" href="<?=base_url('billing-payments.php')?>"><i class="bi bi-credit-card"></i><b>Billing</b><small>Upload proof, invoices, renewals and extra slots.</small></a>
  <a class="mj-module-tile" href="<?=base_url('listing-qr-poster.php')?>"><i class="bi bi-qr-code"></i><b>QR / Share Poster</b><small>Create shareable listing QR and social poster.</small></a>
  <a class="mj-module-tile" href="<?=base_url('request-more-slots.php')?>"><i class="bi bi-plus-circle"></i><b>More Slots</b><small>Request extra listing or company posting quota.</small></a>
</div>
<div class="mj-center-card"><div class="card-body"><h5 class="fw-bold">Recent selling timeline</h5><?php mj_v288_render_timeline(mj_v288_user_timeline((int)$user['id'], 35)); ?></div></div>

      </div>
    </div>
  </div>
</section>
<?php include __DIR__.'/includes/footer.php'; ?>
