<% content_for :title, t(".import_preview") %> <%= render "shared/aircraft_header", aircraft: @aircraft %> <% rows = @import.rows %> <% problems = rows.select { _1.status.in?(%i[error warning]) } %> <% last = @import.last_reading %>

<%= t(".preview_html", filename: @filename) %>

<%= t(".columns_found_html", columns: (@import.columns.keys.map { _1.to_s.humanize }.join(", "))) %>
<%= @import.importable.size %>
<%= t(".flights_to_import") %>
<%= hours(@import.total_tach_hours) %>
<%= t(".tach_hours") %>
<%= @import.count(:warning) %>
<%= t(".warnings_imported") %>
<%= @import.count(:error) %>
<%= t(".errors_skipped") %>
<%= @import.count(:duplicate) %>
<%= t(".already_imported") %>
<% if @import.importable.any? %> <%= form_with url: confirm_aircraft_flight_import_path(@aircraft), class: "space-y-3 border-t border-slate-100 p-4", data: { turbo_confirm: t(".import_flights", importable: @import.importable.size) } do |f| %> <%= hidden_field_tag :token, @token %> <%= hidden_field_tag :filename, @filename %> <%= hidden_field_tag :starting_tach, @starting_tach %> <%= hidden_field_tag :starting_hobbs, @starting_hobbs %> <% if last && last.tach_in > @aircraft.tach_time %> <% elsif last %>

<%= t(".the_aircraft_s_tach_is_html", tach_time: (hours(@aircraft.tach_time)), tach_in: (hours(last.tach_in))) %>

<% end %>
<%= f.submit t(".import_flights_2", importable: @import.importable.size), class: "btn-primary" %> <%= link_to t(".upload_a_different_file"), new_aircraft_flight_import_path(@aircraft), class: "btn-secondary" %>
<% if @import.count(:error) > 0 %>

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

<% end %> <% end %> <% else %>

<%= t(".nothing_to_import_html", link: (link_to t(".upload_a_different_file"), new_aircraft_flight_import_path(@aircraft), class: "link")) %>

<% end %>
<% if problems.any? %>

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

<% problems.each do |r| %> <% end %>
<%= t(".row") %><%= t(".date") %><%= t(".route") %><%= t(".tach") %><%= t(".issue") %>
<%= r.line %><%= r.date || "—" %> <%= [r.from, r.to].compact.join(" → ") %><%= r.tach_in %> <%= tag.span(r.status == :error ? t(".skipped") : t(".warning"), class: r.status == :error ? "badge-red" : "badge-orange") %> <%= r.messages.join("; ") %>
<% end %>
<%= t(".all_rows_html", rows: rows.size) %>
<% rows.each do |r| %> <% end %>
<%= t(".row") %><%= t(".date") %><%= t(".from") %><%= t(".to") %><%= t(".tach") %><%= t(".tach_hrs") %><%= t(".hobbs") %><%= t(".hobbs_hrs") %><%= t(".oil") %><%= t(".fuel") %>
<%= r.line %><%= fmt_date(r.date) %><%= r.from %><%= r.to %> <%= r.tach_in %><%= hours(r.tach_time) if r.tach_time %> <%= r.hobbs_in %><%= hours(r.hobbs_time) if r.hobbs_time %> <%= r.oil %><%= r.fuel %> <%= { ok: "", warning: tag.span("warning", class: "badge-orange"), error: tag.span("skipped", class: "badge-red"), duplicate: tag.span("duplicate", class: "badge-gray") }[r.status] %>