<% content_for :title, "#{@batch.type.split('::').first.titleize} Batch ##{@batch.id} - #{@batch.addresses.count} #{@batch.type.split('::').first.downcase.pluralize}" %>

<div class="container">
  <div class="page-header">
    <h1 class="page-title"><%= @batch.type.split('::').first.titleize %> Batch #<%= @batch.id %> <small>(<%= pluralize(@batch.addresses.count, @batch.type.split('::').first.downcase) %>)</small></h1>
    <div class="actions">
      <%= secondary_link_to "Back to batches", batches_path do %>
        <%= back_icon %>Back to batches
      <% end %>
      
      <%= secondary_link_to "Edit this batch", edit_batch_path(@batch) do %>
        <%= edit_icon %>Edit this batch
      <% end %>
    </div>
  </div>

  <%= render @batch %>
  
  <% if @batch.is_a?(Letter::Batch) && @batch.processed? %>
    <%= render partial: "letter_batch", locals: { batch: @batch } %>
    
    <% if @batch.letters.any? %>
      <div class="card">
        <details class="letters-details">
          <summary class="card-header">
            <h2 class="section-title mb-0">Letters (<%= @batch.letters.count %>)</h2>
            <div class="caret-icon">▼</div>
          </summary>
          <div class="card-body">
            <%= render partial: 'letters_collection', locals: { letters: @batch.letters } %>
          </div>
        </details>
      </div>
    <% end %>
  <% end %>
  
  <% if @batch.is_a?(Warehouse::Batch) && @batch.orders.any? %>
    <div class="card">
      <details class="orders-details">
        <summary class="card-header">
          <h2 class="section-title mb-0">Orders (<%= @batch.orders.count %>)</h2>
          <div class="caret-icon">▼</div>
        </summary>
        <div class="card-body">
          <%= render partial: 'orders_collection', locals: { orders: @batch.orders } %>
        </div>
      </details>
    </div>
  <% end %>
  
  <%= render partial: 'admin_inspector', locals: { record: @batch } %>
  
  <% if @batch.addresses.any? %>
    <div class="card">
      <details class="addresses-details">
        <summary class="card-header">
          <h2 class="section-title mb-0">Addresses (<%= @batch.addresses.count %>)</h2>
          <div class="caret-icon">▼</div>
        </summary>
        <div class="card-body">
          <%= render partial: 'addresses_table', locals: { addresses: @batch.addresses } %>
        </div>
      </details>
    </div>
  <% end %>
  
  <div class="danger-zone">
    <h3 class="text-danger">Danger Zone</h3>
    <%= danger_button_to "Delete this batch", @batch, method: :delete, data: { confirm: "Are you sure you want to delete this batch? This action cannot be undone." } %>
  </div>
</div>
