<% content_for :title, t(".weight_balance", tail_number: @aircraft.tail_number) %> <%= render "shared/aircraft_header", aircraft: @aircraft %> <% setup = @aircraft.loading_setup %>

<%= t(".current_weight_balance") %>

<% if can?(:manage_weight_balance) %><%= link_to t(".new_w_b"), new_aircraft_weight_balance_record_path(@aircraft), class: "btn-primary btn-sm" %><% end %>
<% if @current %>
<%= t(".as_of") %>
<%= fmt_date(@current.date) %><%= " ยท #{@current.reason}" if @current.reason.present? %>
<%= t(".empty_weight") %>
<%= t(".lb_html", delimiter: (number_with_precision(@current.empty_weight, precision: 1, delimiter: ","))) %>
<%= t(".empty_cg_arm") %>
<%= t(".in_html", precision: (number_with_precision(@current.empty_arm, precision: 2))) %>
<%= t(".moment") %>
<%= t(".lb_in_html", delimiter: (number_with_precision(@current.empty_moment, precision: 0, delimiter: ","))) %>
<%= t(".max_gross_weight") %>
<%= @current.max_gross_weight ? "#{number_with_precision(@current.max_gross_weight, precision: 0, delimiter: ',')} lb" : "โ€”" %>
<%= t(".useful_load") %>
<%= @current.useful_load ? "#{number_with_precision(@current.useful_load, precision: 1, delimiter: ',')} lb" : "โ€”" %>
<% else %> <%= empty_state t(".no_weight_balance_recorded_yet") %> <% end %>

<%= t(".loading_calculator") %>

<% if can?(:manage_weight_balance) %><%= link_to t(".loading_setup"), edit_aircraft_loading_setup_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
<% if @current && setup.configured? %> <%= render "weight_balance_records/calculator", record: @current, setup: setup %> <% elsif !@current %> <%= empty_state t(".record_the_current_weight_balance") %> <% else %> <%= empty_state(can?(:manage_weight_balance) ? t(".set_up_the_loading_stations") : t(".an_owner_needs_to_set")) %> <% end %>

<%= t(".history") %>

<% if @records.any? %>
<% @records.each do |r| %> <% end %>
<%= t(".date") %><%= t(".empty_weight") %><%= t(".cg") %><%= t(".useful_load") %><%= t(".reason") %>
<%= fmt_date(r.date) %> <%= t(".lb_html", delimiter: (number_with_precision(r.empty_weight, precision: 1, delimiter: ","))) %> <%= t(".in_html", precision: (number_with_precision(r.empty_arm, precision: 2))) %> <%= r.useful_load ? "#{number_with_precision(r.useful_load, precision: 1, delimiter: ',')} lb" : "โ€”" %> <%= r.reason %> <% if r.major_record %>
<%= link_to r.major_record.title, aircraft_major_record_path(@aircraft, r.major_record), class: "link" %>
<% end %> <% if r.document %>
<%= link_to "๐Ÿ“„ #{r.document.name}", aircraft_document_path(@aircraft, r.document), class: "link" %>
<% end %>
<% if can?(:manage_weight_balance) %><%= link_to t(".edit"), edit_aircraft_weight_balance_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %>
<% else %><%= empty_state t(".no_records_yet") %><% end %>