<% content_for :title, @component.to_s %> <%= render "shared/aircraft_header", aircraft: @aircraft %>

<%= @component %> <%= life_badge(@component.life_status) %>

<% if can?(:manage_components) %>
<%= link_to t(".sub_component"), new_aircraft_component_path(@aircraft, parent_id: @component.id), class: "btn-secondary btn-sm" %> <%= link_to t(".edit"), edit_aircraft_component_path(@aircraft, @component), class: "btn-secondary btn-sm" %>
<% end %>
<%= t(".manufacturer") %>
<%= @component.manufacturer %>
<%= t(".model") %>
<%= @component.model %>
<%= t(".serial") %>
<%= @component.serial_number.presence || "—" %>
<%= t(".status") %>
<%= @component.status_label %>
<%= t(".parent") %>
<%= @component.parent_component ? link_to(@component.parent_component, aircraft_component_path(@aircraft, @component.parent_component), class: "link") : "—" %>
<%= t(".location") %>
<%= @component.install_location.presence || "—" %>
<%= t(".in_service_since") %>
<%= fmt_date(@component.date_in_service) %>
<%= t(".last_oh_service") %>
<%= fmt_date(@component.overhaul_date) %>
<%= t(".hours_in_service") %>
<%= hours(@component.hours_in_service) %>
<%= t(".since_oh_service") %>
<%= hours(@component.hours_since_overhaul) %>
<%= t(".tbo") %>
<%= @component.tbo_hours ? t(".h_remaining", tbo_hours: @component.tbo_hours, hours_to_tbo: (hours(@component.hours_to_tbo))) : "—" %>
<%= t(".replacement") %>
<%= [@component.replacement_hours && "#{@component.replacement_hours} h", @component.replacement_interval_label].compact.join(" / ").presence&.then { @component.replacement_from_install? ? t(".since_installed", interval: _1) : _1 } || "—" %> <% if (d = @component.next_replacement_date) %>
<%= t(".next_by_html", d: (fmt_date(d))) %>
<% end %>
<%= t(".flags") %>
<% { tbo_critical: t(".tbo_critical"), replacement_critical: t(".replacement_critical"), on_condition: t(".on_condition") }.each do |flag, label| %> <% if @component.public_send("#{flag}?") %><%= label %><% end %> <% end %>
<% if @component.notes.present? %>
<%= simple_format @component.notes %>
<% end %>
<% if can?(:manage_components) %>

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

<%= form_with url: reset_service_aircraft_component_path(@aircraft, @component), method: :post, class: "card-body space-y-3", data: { turbo_confirm: t(".reset_hours_for", component: @component) } do |f| %>

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

<%= f.submit t(".record_service"), class: "btn-primary" %> <% end %>
<% end %>
<% if @inspection_rows.any? || can?(:manage_inspections) %>

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

<% if can?(:manage_inspections) %><%= link_to t(".inspection"), new_aircraft_inspection_type_path(@aircraft, component_id: @component.id), class: "btn-secondary btn-sm" %><% end %>
<% if @inspection_rows.any? %> <% @inspection_rows.each do |row| %> <% end %>
<%= t(".inspection_2") %><%= t(".interval") %><%= t(".last_done") %><%= t(".next_due") %><%= t(".status") %>
<%= row.type.name %><%= tag.span(t(".advisory"), class: "text-xs text-slate-500") if row.type.advisory? %> <%= row.type.interval_description %> <%= row.latest ? "#{fmt_date(row.latest.date)} @ #{hours(row.latest.hours_at_inspection)} h" : "—" %> <%= [row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} h"].compact.join(" / ").presence || "—" %> <%= compliance_badge(row.status) %>
<% else %>

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

<% end %>
<% end %> <% if @squawks.any? %>

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

<%= render "squawks/table", squawks: @squawks, aircraft: @aircraft %>
<% end %>