% content_for :title, "Defer inoperative item" %>
<%= render "shared/aircraft_header", aircraft: @aircraft %>
<%= form_with url: defer_aircraft_squawk_path(@aircraft, @squawk), method: :patch, class: "card card-body max-w-2xl space-y-4" do %>
Defer as inoperative (14 CFR 91.213(d))
Without a Minimum Equipment List, an aircraft may fly with an inoperative instrument or piece of equipment only if all of the following are true. Deferring stops this squawk grounding the aircraft. It stays open, and shows as inoperative, until it's fixed.
Item: <%= @squawk.issue_reported %><%= " ยท #{@squawk.component}" if @squawk.component %>
<% if @squawk.errors.any? %>
<% @squawk.errors.full_messages.each do |m| %><%= m %> <% end %>
<% end %>
Confirm each one
<% Squawk::DEFERRAL_CHECKS.each do |key, text| %>
<%= check_box_tag "checks[]", key, Array(params[:checks]).include?(key), id: "check_#{key}", class: "mt-0.5 h-4 w-4 shrink-0 rounded border-slate-300" %>
<%= text %>
<% end %>
<%= label_tag :deferral_action, "What was done", class: "label" %>
<%= select_tag :deferral_action, options_for_select(Squawk::DEFERRAL_ACTIONS.invert, params[:deferral_action] || @squawk.deferral_action), class: "input" %>
Deactivating or removing it is maintenance, recorded under Part 43 unless the pilot may do it as preventive maintenance.
<%= label_tag :deferred_by_name, "Determined by", class: "label" %>
<%= text_field_tag :deferred_by_name, params[:deferred_by_name] || current_user.display_name, class: "input", required: true %>
<%= label_tag :deferred_by_role, "As", class: "label" %>
<%= select_tag :deferred_by_role, options_for_select(Squawk::DEFERRAL_ROLES.invert, params[:deferred_by_role]), class: "input" %>
<%= label_tag :deferral_notes, "Notes", class: "label" %>
<%= text_area_tag :deferral_notes, params[:deferral_notes], rows: 2, class: "input", placeholder: "e.g. breaker pulled and collared; equipment list reviewed" %>
<%= submit_tag "Defer item", class: "btn-primary" %>
<%= link_to "Cancel", aircraft_squawks_path(@aircraft), class: "btn-secondary" %>
<% end %>