<%- include('partials/header', { title }) %>

<div class="section-head">
  <p class="section-eyebrow">Founder Portal</p>
  <h1 style="font-size: 1.75rem;">Welcome back, <%= currentFounder.name %></h1>
  <p class="lead">Track the status of every application you've submitted to Kubera Wealth Management.</p>
</div>

<% if (!applications.length) { %>
  <div class="card" style="text-align:center; padding: 3rem;">
    <p style="margin-bottom: 1rem;">You don't have any applications yet.</p>
    <a href="/apply" class="btn btn-primary">Apply for Funding</a>
  </div>
<% } %>

<% applications.forEach(function(app) { %>
  <div class="card" style="margin-bottom: 1.5rem;">
    <div style="display:flex; align-items:flex-start; justify-content:space-between; flex-wrap:wrap; gap:0.75rem;">
      <div>
        <h2 style="font-size: 1.25rem; margin-bottom: 0.25rem;"><%= app.company_name %></h2>
        <p style="font-size: 0.8125rem; color: var(--ink-300); margin:0;">Submitted <%= new Date(app.created_at).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) %></p>
      </div>
      <span class="badge <%= app.status === 'invested' ? 'badge-accent' : '' %>"><%= statusLabels[app.status] %></span>
    </div>

    <% if (app.status === 'passed') { %>
      <div class="status-track status-track--passed">
        <div class="status-track__step is-complete">
          <div class="status-track__dot"><i data-lucide="x" width="14" height="14"></i></div>
          <div class="status-track__label">Not Moving Forward</div>
        </div>
      </div>
      <p style="font-size: 0.875rem; color: var(--ink-500);">Thank you for sharing <%= app.company_name %> with us. We're not moving forward with this opportunity right now, but we'd welcome hearing from you again as the company progresses.</p>
    <% } else { %>
      <% var currentIndex = statusSteps.indexOf(app.status); %>
      <div class="status-track">
        <% statusSteps.forEach(function(step, i) { %>
          <div class="status-track__step <%= i < currentIndex ? 'is-complete' : '' %> <%= i === currentIndex ? 'is-current' : '' %>">
            <div class="status-track__dot"><%= i < currentIndex ? '✓' : (i + 1) %></div>
            <div class="status-track__label"><%= statusLabels[step] %></div>
          </div>
        <% }); %>
      </div>
    <% } %>

    <dl class="application-meta-grid">
      <div><dt>Sector</dt><dd><%= app.sector || '—' %></dd></div>
      <div><dt>Stage</dt><dd><%= app.stage || '—' %></dd></div>
      <div><dt>Target Raise</dt><dd><%= app.raise_amount_usd ? formatUsdCompact(app.raise_amount_usd) : '—' %></dd></div>
    </dl>

    <h3 style="font-size: 0.9375rem; margin-bottom: 0.5rem;">Documents</h3>
    <div class="document-row">
      <span>Pitch Deck</span>
      <% if (app.pitch_deck_path) { %><a href="<%= app.pitch_deck_path %>" target="_blank">View</a><% } else { %><span class="document-row__status">Not provided</span><% } %>
    </div>
    <div class="document-row">
      <span>Financials</span>
      <% if (app.financials_path) { %><a href="<%= app.financials_path %>" target="_blank">View</a><% } else { %><span class="document-row__status">Not provided</span><% } %>
    </div>
    <div class="document-row">
      <span>Business Plan</span>
      <% if (app.business_plan_path) { %><a href="<%= app.business_plan_path %>" target="_blank">View</a><% } else { %><span class="document-row__status">Not provided</span><% } %>
    </div>

    <% if (app.status === 'new') { %>
      <details style="margin-top: 1rem;">
        <summary style="cursor:pointer; font-size: 0.875rem; font-weight: 600; color: var(--color-accent);">Update documents</summary>
        <form action="/founder/applications/<%= app.id %>/documents" method="POST" enctype="multipart/form-data" style="margin-top: 1rem;">
          <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
          <div class="field">
            <label>Pitch deck <span class="hint">(PDF or PowerPoint)</span></label>
            <div class="file-drop" data-file-drop>
              <p>Drag & drop, or click to browse</p>
              <p class="filename"></p>
              <input type="file" name="pitchDeck" accept=".pdf,.ppt,.pptx" hidden />
            </div>
          </div>
          <div class="field">
            <label>Financials <span class="hint">(optional)</span></label>
            <div class="file-drop" data-file-drop>
              <p>Drag & drop, or click to browse</p>
              <p class="filename"></p>
              <input type="file" name="financials" accept=".pdf,.xls,.xlsx" hidden />
            </div>
          </div>
          <div class="field">
            <label>Business plan <span class="hint">(optional)</span></label>
            <div class="file-drop" data-file-drop>
              <p>Drag & drop, or click to browse</p>
              <p class="filename"></p>
              <input type="file" name="businessPlan" accept=".pdf,.doc,.docx" hidden />
            </div>
          </div>
          <button class="btn btn-outline btn-sm" type="submit">Save Documents</button>
        </form>
      </details>
    <% } %>
  </div>
<% }); %>

<%- include('partials/footer') %>
