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

<div class="admin-page-head">
  <div>
    <h2>Portfolio Companies</h2>
    <p style="color: var(--ink-300);"><%= companies.length %> companies</p>
  </div>
  <a href="/admin/companies/new" class="btn btn-primary btn-sm"><i data-lucide="plus" width="16" height="16"></i> Add Company</a>
</div>

<div class="table-toolbar">
  <div class="search-box" style="min-width: 280px;">
    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.35-4.35"/></svg>
    <input type="search" placeholder="Filter companies…" data-table-search="#companies-table" />
  </div>
</div>

<div class="table-wrap">
  <table class="data-table" id="companies-table">
    <thead>
      <tr>
        <th>Name</th>
        <th>Sector</th>
        <th>Stage</th>
        <th>Valuation</th>
        <th>Featured</th>
        <th>Unicorn</th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <% if (!companies.length) { %>
        <tr><td class="empty-row" colspan="7">No companies yet. <a href="/admin/companies/new">Add your first one</a>.</td></tr>
      <% } %>
      <% companies.forEach(function(c) { %>
        <tr>
          <td class="cell-title"><%= c.name %></td>
          <td class="cell-muted"><%= c.category_name || '—' %></td>
          <td class="cell-muted"><%= c.stage %></td>
          <td class="cell-muted"><%= c.valuation_usd ? '$' + Number(c.valuation_usd).toLocaleString() : '—' %></td>
          <td><%= c.is_featured ? '✓' : '' %></td>
          <td><%= c.is_unicorn ? '✓' : '' %></td>
          <td class="actions">
            <a class="icon-btn" href="/admin/companies/<%= c.id %>/edit" title="Edit"><i data-lucide="pencil" width="15" height="15"></i></a>
            <form action="/admin/companies/<%= c.id %>/delete" method="POST" style="display:inline;" data-confirm="Remove <%= c.name.replace(/"/g, '&quot;') %> from the portfolio?">
              <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
              <button class="icon-btn is-danger" type="submit" title="Delete"><i data-lucide="trash-2" width="15" height="15"></i></button>
            </form>
          </td>
        </tr>
      <% }); %>
    </tbody>
  </table>
</div>

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