<section class="section">
  <p class="eyebrow">Admin festival access</p>
  <h1><%= event.title %></h1>
  <div class="festival-stats">
    <div class="city-tile"><strong><%= occupancy.totalInside %></strong><span>inside acum</span></div>
    <div class="city-tile"><strong><%= occupancy.entriesToday %></strong><span>intrari azi</span></div>
    <div class="city-tile"><strong><%= occupancy.exitsToday %></strong><span>iesiri azi</span></div>
    <div class="city-tile"><strong><%= occupancy.invalidScans %></strong><span>scanari invalide</span></div>
  </div>
</section>

<section class="section split-sections">
  <form class="checkout-form" method="post" action="/admin/events/<%= event.id %>/festival/settings">
    <%- include('../partials/csrf-field') %>
    <h2>Festival Settings</h2>
    <label><input type="checkbox" name="enabled" value="1" <%= settings?.enabled ? 'checked' : '' %>> Festival mode activ</label>
    <label>Valid from <input type="datetime-local" name="valid_from"></label>
    <label>Valid until <input type="datetime-local" name="valid_until"></label>
    <label>Timezone <input name="timezone" value="<%= settings?.timezone || 'Europe/Bucharest' %>"></label>
    <label>Max intrari/zi <input type="number" name="max_entries_per_day" min="1" value="<%= settings?.max_entries_per_day || 3 %>"></label>
    <label><input type="checkbox" name="require_exit_scan" value="1" <%= settings?.require_exit_scan !== 0 ? 'checked' : '' %>> Require exit scan</label>
    <label><input type="checkbox" name="allow_manual_override" value="1" <%= settings?.allow_manual_override ? 'checked' : '' %>> Allow manual override</label>
    <button type="submit">Salveaza settings</button>
  </form>

  <form class="checkout-form" method="post" action="/admin/events/<%= event.id %>/festival/days">
    <%- include('../partials/csrf-field') %>
    <h2>Festival Days</h2>
    <label>Zi <input type="date" name="day_date" required></label>
    <label>Opens at <input type="datetime-local" name="opens_at" required></label>
    <label>Closes at <input type="datetime-local" name="closes_at" required></label>
    <label>Max intrari/zi <input type="number" name="max_entries_per_day" min="1" value="<%= settings?.max_entries_per_day || 3 %>"></label>
    <label>Status <select name="status"><option value="active">active</option><option value="inactive">inactive</option><option value="cancelled">cancelled</option></select></label>
    <button type="submit">Adauga zi</button>
  </form>
</section>

<section class="section split-sections">
  <form class="checkout-form" method="post" action="/admin/events/<%= event.id %>/festival/zones">
    <%- include('../partials/csrf-field') %>
    <h2>Access Zones</h2>
    <label>Nume <input name="name" placeholder="General" required></label>
    <label>Cod <input name="code" placeholder="GENERAL" required></label>
    <label>Capacitate <input type="number" name="capacity_limit" min="0"></label>
    <label>Culoare <input name="color" value="#4f46e5"></label>
    <label>Status <select name="status"><option value="active">active</option><option value="inactive">inactive</option></select></label>
    <button type="submit">Salveaza zona</button>
  </form>

  <form class="checkout-form" method="post" action="/admin/events/<%= event.id %>/festival/gates">
    <%- include('../partials/csrf-field') %>
    <h2>Event Gates</h2>
    <label>Nume <input name="name" placeholder="Poarta 1" required></label>
    <label>Cod <input name="code" placeholder="GATE-1" required></label>
    <label>Tip <select name="type"><option value="entry">entry</option><option value="exit">exit</option><option value="mixed">mixed</option></select></label>
    <label>Zona <select name="zone_id"><option value="">Fara zona</option><% zones.forEach((z) => { %><option value="<%= z.id %>"><%= z.name %></option><% }) %></select></label>
    <button type="submit">Salveaza poarta</button>
  </form>
</section>

<section class="section">
  <h2>Entitlements pe ticket type</h2>
  <div class="event-grid">
    <% ticketTypes.forEach((ticketType) => { const active = mappings.filter((m) => Number(m.ticket_type_id) === Number(ticketType.id)).map((m) => Number(m.zone_id)); %>
      <form class="checkout-form" method="post" action="/admin/events/<%= event.id %>/festival/entitlements">
        <%- include('../partials/csrf-field') %>
        <input type="hidden" name="ticket_type_id" value="<%= ticketType.id %>">
        <h3><%= ticketType.name %></h3>
        <% zones.forEach((zone) => { %>
          <label><input type="checkbox" name="zone_ids" value="<%= zone.id %>" <%= active.includes(Number(zone.id)) ? 'checked' : '' %>> <%= zone.name %></label>
        <% }) %>
        <button type="submit">Salveaza zone</button>
      </form>
    <% }) %>
  </div>
</section>

<section class="section split-sections">
  <div class="checkout-form"><h2>Zile</h2><% days.forEach((d) => { %><p><strong><%= d.day_date %></strong> · <%= d.opens_at %> - <%= d.closes_at %> · <%= d.status %></p><% }) %></div>
  <div class="checkout-form"><h2>Porți</h2><% gates.forEach((g) => { %><p><strong><%= g.name %></strong> · <%= g.type %> · <%= g.zone_name || 'fara zona' %></p><% }) %></div>
</section>
