<!-- ── Trial Banner ─────────────────────────────────────────── -->
<% if (currentUser.is_trial && currentUser.membership_status === 'trial') { %>
  <% const trialDaysLeft = moment(currentUser.trial_end).diff(moment(), 'days'); %>
  <div class="trial-banner <%= trialDaysLeft <= 3 ? 'trial-urgent' : trialDaysLeft <= 7 ? 'trial-warning' : 'trial-info' %>">
    <div class="tb-left">
      <i class="bi bi-hourglass-<%= trialDaysLeft <= 3 ? 'bottom' : 'split' %>"></i>
      <div>
        <strong>
          <% if (trialDaysLeft <= 0) { %>Your free trial has expired!
          <% } else if (trialDaysLeft === 1) { %>Your trial expires TOMORROW!
          <% } else { %>Your free trial expires in <%= trialDaysLeft %> days<% } %>
        </strong>
        <p>Activate your membership to keep access to all features — just $299/year.</p>
      </div>
    </div>
    <div class="tb-right">
      <a href="/member/billing" class="btn btn-white btn-sm"><i class="bi bi-credit-card-fill"></i> Activate Now — $299/yr</a>
      <span class="tb-expiry">Trial ends <%= moment(currentUser.trial_end).format('MMM D, YYYY') %></span>
    </div>
  </div>
<% } %>

<!-- Welcome Bar -->
<div class="dash-welcome">
  <div>
    <h2>Good <%= new Date().getHours() < 12 ? 'morning' : new Date().getHours() < 17 ? 'afternoon' : 'evening' %>, <%= currentUser.first_name %>! 👋</h2>
    <p>Here's what's happening with your business today.</p>
  </div>
  <% if (membership && membership.status === 'trial' && membership.is_trial) { %>
    <% const tdl = moment(membership.trial_end).diff(moment(), 'days'); %>
    <a href="/member/billing" class="membership-badge <%= tdl <= 3 ? 'expired' : 'trial' %>">
      <i class="bi bi-hourglass-split"></i> Free Trial — <%= tdl >= 0 ? tdl + 'd left' : 'Expired' %>
    </a>
  <% } else if (membership && membership.status === 'active') { %>
    <div class="membership-badge active"><i class="bi bi-patch-check-fill"></i> Active Member <% if(daysToExpiry !== null && daysToExpiry <= 30) { %><span class="expiry-warn">Renews in <%= daysToExpiry %>d</span><% } %></div>
  <% } else if (membership && membership.status === 'pending') { %>
    <a href="/member/billing" class="membership-badge pending"><i class="bi bi-clock-fill"></i> Activate Membership</a>
  <% } else { %>
    <a href="/member/billing" class="membership-badge expired"><i class="bi bi-exclamation-triangle-fill"></i> Renew Membership</a>
  <% } %>
</div>

<!-- Stats Row -->
<% if (stats) { %>
<div class="stats-row">
  <div class="stat-card"><div class="stat-icon" style="background:#eff6ff;color:#1a56db"><i class="bi bi-pin-map-fill"></i></div><div class="stat-body"><p class="stat-num"><%= stats.posts || 0 %></p><p class="stat-label">Bulletin Posts</p></div></div>
  <div class="stat-card"><div class="stat-icon" style="background:#f0fdf4;color:#10b981"><i class="bi bi-calendar-check-fill"></i></div><div class="stat-body"><p class="stat-num"><%= stats.events_registered || 0 %></p><p class="stat-label">Events Joined</p></div></div>
  <div class="stat-card"><div class="stat-icon" style="background:#fdf4ff;color:#9333ea"><i class="bi bi-newspaper"></i></div><div class="stat-body"><p class="stat-num"><%= stats.published_releases || 0 %></p><p class="stat-label">Press Releases</p></div></div>
  <div class="stat-card"><div class="stat-icon" style="background:#fff7ed;color:#f59e0b"><i class="bi bi-envelope-fill"></i></div><div class="stat-body"><p class="stat-num"><%= stats.unread_messages || 0 %></p><p class="stat-label">Unread Messages</p></div></div>
</div>
<% } %>

<!-- No org prompt -->
<% if (!currentUser.org_id) { %>
<div class="info-banner"><i class="bi bi-info-circle-fill"></i><div><strong>Complete your profile!</strong> Add your organization details to get listed in the directory and access all features.<br><a href="/member/profile" class="btn btn-sm btn-primary" style="margin-top:8px">Complete Profile</a></div></div>
<% } %>

<div class="dash-grid">
  <!-- Bulletin Board -->
  <div class="dash-widget">
    <div class="widget-header"><h3><i class="bi bi-pin-map-fill"></i> Bulletin Board</h3><a href="/member/bulletin" class="widget-link">View All <i class="bi bi-arrow-right"></i></a></div>
    <% if (bulletinPosts && bulletinPosts.length) { %>
    <div class="widget-list">
      <% bulletinPosts.forEach(post => { %>
      <a href="/member/bulletin/<%= post.id %>" class="widget-item">
        <div class="wi-icon <% if(post.category === 'job') { %>wi-green<% } else if(post.category === 'opportunity') { %>wi-amber<% } else { %>wi-blue<% } %>"><i class="bi bi-<% if(post.category === 'job') { %>briefcase<% } else if(post.category === 'opportunity') { %>lightbulb<% } else { %>megaphone<% } %>-fill"></i></div>
        <div class="wi-body"><p class="wi-title"><%= post.title.substring(0,50) %><%= post.title.length > 50 ? '...' : '' %></p><p class="wi-meta"><%= post.org_name %> · <span class="wi-cat"><%= post.category %></span></p></div>
        <span class="wi-time"><%= moment(post.created_at).fromNow() %></span>
      </a>
      <% }) %>
    </div>
    <% } else { %><div class="widget-empty"><i class="bi bi-pin-map"></i><p>No posts yet. <a href="/member/bulletin/new">Create one!</a></p></div><% } %>
    <a href="/member/bulletin/new" class="widget-cta"><i class="bi bi-plus-circle-fill"></i> New Post</a>
  </div>

  <!-- Upcoming Events -->
  <div class="dash-widget">
    <div class="widget-header"><h3><i class="bi bi-calendar-event-fill"></i> Upcoming Events</h3><a href="/member/events" class="widget-link">View All <i class="bi bi-arrow-right"></i></a></div>
    <% if (events && events.length) { %>
    <div class="widget-list">
      <% events.forEach(event => { %>
      <a href="/member/events/<%= event.id %>" class="widget-item">
        <div class="wi-date"><span class="wi-month"><%= new Date(event.start_date).toLocaleDateString('en-US',{month:'short'}) %></span><span class="wi-day"><%= new Date(event.start_date).getDate() %></span></div>
        <div class="wi-body"><p class="wi-title"><%= event.title.substring(0,45) %></p><p class="wi-meta"><%= event.event_type %> <% if(event.is_free){ %> · Free<% } %></p></div>
      </a>
      <% }) %>
    </div>
    <% } else { %><div class="widget-empty"><i class="bi bi-calendar-x"></i><p>No upcoming events.</p></div><% } %>
    <a href="/member/events/create" class="widget-cta"><i class="bi bi-plus-circle-fill"></i> Create Event</a>
  </div>

  <!-- Press Releases -->
  <div class="dash-widget">
    <div class="widget-header"><h3><i class="bi bi-newspaper"></i> Press Releases</h3><a href="/member/press-releases" class="widget-link">View All <i class="bi bi-arrow-right"></i></a></div>
    <% if (pressReleases && pressReleases.length) { %>
    <div class="widget-list">
      <% pressReleases.forEach(pr => { %>
      <a href="/member/press-releases/<%= pr.id %>" class="widget-item">
        <div class="wi-status-dot <%= pr.status === 'published' ? 'dot-green' : pr.status === 'submitted' ? 'dot-amber' : 'dot-gray' %>"></div>
        <div class="wi-body"><p class="wi-title"><%= pr.title.substring(0,50) %></p><p class="wi-meta"><span class="badge badge-<%= pr.status === 'published' ? 'success' : pr.status === 'submitted' ? 'warning' : 'secondary' %>"><%= pr.status %></span></p></div>
      </a>
      <% }) %>
    </div>
    <% } else { %><div class="widget-empty"><i class="bi bi-newspaper"></i><p>No press releases yet.</p></div><% } %>
    <a href="/member/press-releases/new" class="widget-cta"><i class="bi bi-plus-circle-fill"></i> New Release</a>
  </div>

  <!-- Quick Actions -->
  <div class="dash-widget">
    <div class="widget-header"><h3><i class="bi bi-lightning-charge-fill"></i> Quick Actions</h3></div>
    <div class="quick-actions">
      <a href="/member/directory" class="qa-btn"><i class="bi bi-search"></i><span>Search Directory</span></a>
      <a href="/member/community/messages" class="qa-btn"><i class="bi bi-chat-dots-fill"></i><span>Messages</span></a>
      <a href="/member/loyalty" class="qa-btn"><i class="bi bi-star-fill"></i><span>Loyalty Program</span></a>
      <a href="/member/social/new" class="qa-btn"><i class="bi bi-megaphone-fill"></i><span>Promote Post</span></a>
      <a href="/member/profile" class="qa-btn"><i class="bi bi-pencil-fill"></i><span>Edit Profile</span></a>
    </div>
  </div>
</div>
