<% var pageTitle = 'Čišćenje'; var currentPage = 'cleaning'; %>
<%- include('partials/header') %>

<h1>Raspored čišćenja</h1>
<p class="subtitle">Zadaci se automatski stvaraju iz datuma odlaska gosta.</p>

<div class="tag-row">
  <a href="/cleaning?status=planirano" class="<%= filter === 'planirano' ? 'active' : '' %>">Planirano</a>
  <a href="/cleaning?status=gotovo" class="<%= filter === 'gotovo' ? 'active' : '' %>">Gotovo</a>
  <a href="/cleaning?status=sve" class="<%= filter === 'sve' ? 'active' : '' %>">Sve</a>
</div>

<div class="panel">
  <% if (tasks.length === 0) { %>
    <p class="empty-state">Nema zadataka za prikaz u ovoj kategoriji.</p>
  <% } else { %>
    <table>
      <thead><tr><th>Datum</th><th>Apartman</th><th>Zaduženo</th><th>Status</th><th></th></tr></thead>
      <tbody>
        <% tasks.forEach(t => { %>
          <tr>
            <td><%= fmt.date(t.task_date) %></td>
            <td><a href="/apartments/<%= t.apartment_id %>"><%= t.apartment_name %></a></td>
            <td>
              <form class="inline" method="POST" action="/cleaning/<%= t.id %>/assign">
                <input type="text" name="assigned_to" value="<%= t.assigned_to || '' %>" placeholder="ime osobe" style="width:140px; display:inline-block;" onblur="this.form.submit()">
              </form>
            </td>
            <td><span class="badge <%= t.status === 'gotovo' ? 'badge-confirmed' : 'badge-pending' %>"><%= t.status === 'gotovo' ? 'Gotovo' : 'Planirano' %></span></td>
            <td>
              <form class="inline" method="POST" action="/cleaning/<%= t.id %>/toggle">
                <button type="submit" class="btn btn-small <%= t.status === 'gotovo' ? 'btn-secondary' : '' %>">
                  <%= t.status === 'gotovo' ? 'Označi kao neodrađeno' : 'Označi gotovim' %>
                </button>
              </form>
            </td>
          </tr>
        <% }) %>
      </tbody>
    </table>
  <% } %>
</div>

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