<% content_for :title, "Benutzerliste" %>
<h1 class="font-bold text-4xl py-4 text-hsrm-gray">Alle Druckaufträge</h1>
<% if @calendar %>
  <%= link_to icon("magnifying-glass", class: "icon size-5 mr-3") + 'Filter', admin_jobs_path(), class: "px-4 py-2 hover:bg-gray-100 hover:text-hsrm-red border-b-4 hover:border-hsrm-red-light" %>
  <%= content_tag :span, icon("calendar", class: "icon size-5 mr-3") + 'Kalender', class: "px-4 py-2 border-b-4 border-hsrm-red-light" %>
  <div class="pt-2">
    <%== pagy_nav(@calendar[:year]) %>
    <%== pagy_nav(@calendar[:month]) if @calendar[:month] %>
  </div>
<% else %>
  <%= content_tag :span, icon("magnifying-glass", class: "icon size-5 mr-3") + 'Filter', class: "px-4 py-2 border-b-4 border-hsrm-red-light" %>
  <%= link_to icon("calendar", class: "icon size-5 mr-3") + 'Kalender', admin_jobs_path(calendar: true), class: "px-4 py-2 hover:bg-gray-100 hover:text-hsrm-red border-b-4 hover:border-hsrm-red-light" %>
  <div class="flex items-center justify-between py-4">
    <%= search_form_for @q, data: { turbo_frame: :admin_jobs, turbo_action: 'advance' }, url: admin_jobs_path() do |f| %>
      <%= f.search_field :customer_firstname_or_customer_lastname_or_pdf_blob_filename_cont, placeholder: "Suchen", oninput: 'this.form.requestSubmit();' %>
      <%= f.label :status_eq, "Status:" %>
      <%= f.select :status_eq, Job.statuses.keys, {include_blank: "alle"}, onchange: 'this.form.requestSubmit();' %>
      <%= f.label :created_by_operator_eq, "Erstellt vom:" %>
      <%= f.select :created_by_operator_eq, [["Operator", true],["Kunden", false]], {include_blank: "alle"}, onchange: 'this.form.requestSubmit();' %>
      <%= f.submit "Filter anwenden", class: "py-2 px-3 bg-hsrm-red hover:bg-hsrm-red-light shadow-lg text-white inline-block font-medium cursor-pointer" %>
    </div>
  <% end %>
<% end %>
<div>
  <%= turbo_frame_tag "admin_jobs", data: { turbo_action: 'advance'} do %>
    <div class="flex justify-between items-center">
      <%== pagy_nav(@pagy) %>
      <%== pagy_info(@pagy) %>
    </div>
    <div class="min-w-full overflow-auto shadow-lg pt-2">
      <table class="w-full py-8 table-auto">
        <thead class="font-semibold tracking-wide bg-gray-200 border-b-2 border-gray-300 text text-hsrm-gray">
          <tr>
            <th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :id, "ID", ) %></th>
            <th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :customer_firstname, "Vorname") %></th>
            <th class="min-w-24 p-2 py-3 text-left"><%= sort_link(@q, :customer_lastname, "Nachname") %></th>
            <th class="p-2 py-3 text-left"><%= sort_link(@q, :pdf_blob_filename, "PDF") %></th>
            <th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a0, "A0") %></th>
            <th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a1, "A1") %></th>
            <th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a2, "A2") %></th>
            <th class="w-1 p-1 py-3 text-left text-nowrap"><%= sort_link(@q, :number_of_plans_a3, "A3") %></th>
            <th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :costum_qm_plan, "no DIN") %></th>
            <th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :cost, "Kosten") %></th>
            <th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :created_at, "Erstellt am") %></th>
            <th class="w-1 p-2 py-3 text-center text-nowrap"><%= sort_link(@q, :created_by_operator, "Erstellt von") %></th>
            <th class="w-1 p-2 py-3 text-center"><%= sort_link(@q, :status, "Status") %></th>
          </tr>
        </thead>
        <tbody id='jobs' class="divide-y divivde-gray-300">
          <%= render partial: "job_tr", collection: @records, as: :job, locals: { no_actions: true } %>
        </tbody>
      </table>
    </div>
    <div class="flex justify-between items-center">
      <%== pagy_nav(@pagy) %>
      <%== pagy_info(@pagy, item_name: "Users") %>
    </div>
  <% end %>
