<%= form_with model: [aircraft, component], class: "card card-body space-y-5 max-w-4xl" do |f| %> <%= f.errors_summary %>
<%= f.field :component_type_id, as: :select, label: "Type", collection: ComponentType.ordered.map { [_1.name, _1.id] }, include_blank: "— Select —" %> <%= text_field_tag :new_component_type, params[:new_component_type], class: "input mt-2", placeholder: "…or type a new one" %>
<%= f.field :manufacturer, required: true %> <%= f.field :model, required: true %> <%= f.field :serial_number %> <%= f.field :install_location, hint: "e.g. Left mag, #3 cylinder" %> <%= f.field :status, as: :select, collection: Component::STATUSES.invert %> <%= f.field :parent_component_id, as: :select, label: "Parent component", collection: [["— None —", nil]] + aircraft.components.where.not(id: component.id).includes(:component_type).map { [_1.to_s, _1.id] } %>
Time <%= f.field :date_in_service, as: :date, required: true %> <%= f.field :hours_in_service, as: :number, step: 0.1, label: "Total time (hours)" %> <%= f.field :overhaul_date, as: :date, label: "Last overhaul / service" %> <%= f.field :hours_since_overhaul, as: :number, step: 0.1, label: "Hours since OH / service" %> <%= f.field :overhaul_kind, as: :select, label: "Overhaul type", include_blank: "—", collection: Component::OVERHAUL_KINDS.invert, wrapper: { class: "sm:col-span-2" }, hint: "For engines and propellers: printed in logbook entries as SMOH, SFOH or SNEW." %>
Limits <%= f.field :replacement_hours, as: :number, label: "Replace every (hrs)" %> <%= f.field :replacement_days, as: :number, label: "Replace every (days)" %> <%= f.field :replacement_critical, as: :checkbox, label: "Replacement critical", hint: "Overdue replacement or expiry grounds the aircraft (oil, filters, ELT battery…)." %> <%= f.field :expires_on, as: :date, label: "Expires on", hint: "The date marked on the part, e.g. an ELT battery's replacement date (14 CFR 91.207(c): also replace it after 1 hour of cumulative use)." %> <%= f.field :tbo_hours, as: :number, label: "TBO (hrs)" %> <%= f.field :tbo_days, as: :number, label: "TBO (days)" %>
<%= f.field :tbo_critical, as: :checkbox, label: "Treat TBO as a hard limit", hint: "Under Part 91, TBO is usually the manufacturer's recommendation, unless an AD or the Airworthiness Limitations make it mandatory." %> <%= f.field :on_condition, as: :checkbox, label: "On condition (Part 91)" %>
<%= f.field :inspection_hours, as: :number, label: "Inspect every (hrs)" %> <%= f.field :inspection_days, as: :number, label: "Inspect every (days)" %> <%= f.field :inspection_critical, as: :checkbox, label: "Inspection critical" %>
<%= f.field :notes, as: :textarea, rows: 3 %>
<%= f.submit component.new_record? ? "Add Component" : "Save" %> <%= link_to "Cancel", aircraft_components_path(aircraft), class: "btn-secondary" %>
<% end %> <% if component.persisted? %>
<%= delete_button "Delete component", aircraft_component_path(aircraft, component), confirm: "Delete #{component} and its sub-components?" %>
<% end %>