<% item_label = format_label(@pagy.count, "logs") %>
<% title = format_title(@searched, "Logs", current_user, item_label, @pagy.count, @organisation.name) %>

<% content_for :title, title %>

<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %>

<% if current_user.support? %>
  <%= render SubNavigationComponent.new(
    items: secondary_items(request.path, @organisation.id),
  ) %>
  <h2 class="govuk-visually-hidden">Logs</h2>
<% end %>

<div class="app-filter-layout" data-controller="filter-layout">
  <div class="govuk-button-group app-filter-toggle">
    <% if current_page?(controller: 'organisations', action: 'lettings_logs') %>
      <%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %>
    <% end %>
    <% if current_page?(controller: 'organisations', action: 'sales_logs') %>
      <%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post) %>
    <% end %>
  </div>

  <%= render partial: "logs/log_filters" %>
  <div class="app-filter-layout__content">
    <%= render SearchComponent.new(current_user:, search_label: "Search by log ID, tenant code, property reference or postcode", value: @searched) %>
    <%= govuk_section_break(visible: true, size: "m") %>
    <%= render partial: "logs/log_list",
               locals: {
                 logs: @logs,
                 title: "Logs",
                 pagy: @pagy,
                 searched: @searched,
                 item_label:,
                 total_count: @total_count,
                 csv_download_url: csv_download_url_by_log_type(@log_type, @organisation, search: @search_term, codes_only: false),
                 csv_codes_only_download_url: csv_download_url_by_log_type(@log_type, @organisation, search: @search_term, codes_only: true),
               } %>
    <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "logs" } %>
  </div>
</div>