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

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

<% if owner? %>
<% if @attachable.any? %> <%= form_with url: attach_aircraft_airworthiness_directives_path(@aircraft), class: "flex gap-2" do |f| %> <%= f.select :airworthiness_directive_id, @attachable.map { ["#{_1.name} โ€“ #{_1.short_description.truncate(40)}", _1.id] }, {}, class: "input w-64" %> <%= f.submit t(".link_existing"), class: "btn-secondary" %> <% end %> <% end %> <%= link_to t(".new_ad"), new_aircraft_airworthiness_directive_path(@aircraft), class: "btn-primary" %>
<% end %>
<% if @rows.any? %>
<% @rows.each do |row| ad = row.ad %> <% end %>
<%= t(".ad_bulletin") %><%= t(".description") %><%= t(".recurrence") %><%= t(".last_complied") %><%= t(".next_due") %><%= t(".status") %>
<%= ad.bulletin_label %><%= ad_link(ad) %> <% if ad.document %><%= link_to "๐Ÿ“„", aircraft_document_path(@aircraft, ad.document), title: ad.document.name, "aria-label": t(".document", document: ad.document.name) %><% end %> <% unless ad.mandatory? %>
<%= t(".not_mandatory") %>
<% end %>
<%= ad.short_description %> <% if ad.effective_date || ad.product_type.present? %>
<%= [(ad.effective_date && t(".effective_2", effective_date: (fmt_date(ad.effective_date)))), ad.product_type.presence].compact.join(" ยท ") %>
<% end %> <% if ad.superseded_by.present? %>
<%= t(".superseded_by_html", superseded_by: ad.superseded_by) %>
<% end %> <% if ad.conditional? && ad.trigger_condition.present? %>
<%= t(".trigger_html", trigger_condition: ad.trigger_condition) %>
<% end %>
<%= ad.recurring? ? [ad.recurring_hours.to_f > 0 && "#{hours(ad.recurring_hours)} h", ad.recurring_interval_label].select(&:itself).join(" / ") : t(".one_time") %> <%= row.latest ? "#{row.latest.date_complied}#{' (permanent)' if row.latest.permanent?}" : "โ€”" %> <%= [row.next_due_date && l(row.next_due_date, format: :month_year), row.next_due_hours && t(".due_hours", hours: hours(row.next_due_hours), meter: Aircraft::TIME_BASES[@aircraft.time_basis].downcase, left: hours(row.next_due_hours - @aircraft.current_hours))].compact.join(" / ").presence || "โ€”" %> <%= compliance_badge(row.status) %> <% if owner? %> <%= link_to t(".comply"), new_aircraft_ad_compliance_path(@aircraft, ad_id: ad.id), class: "btn-secondary btn-sm" %> <% if row.status.in?(%w[no_compliance overdue due_soon conditional]) %><%= link_to "N/A", new_aircraft_ad_compliance_path(@aircraft, ad_id: ad.id, not_applicable: 1), class: "btn-secondary btn-sm", title: t(".record_that_this_ad_doesn") %><% end %> <%= link_to t(".edit"), edit_aircraft_airworthiness_directive_path(@aircraft, ad), class: "btn-secondary btn-sm" %> <% end %>
<% else %> <%= empty_state t(".no_ads_tracked_for_this") %> <% end %>
<% last_drs = @aircraft.drs_imports.latest_first.first %> <% missing = DrsImport.missing_models(@aircraft) %>

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

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

<% if owner? %><%= link_to t(".import_from_faa_drs"), new_aircraft_ad_import_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
<% if last_drs %>

<%= t(".last_import_by_ads_html", to_date: (fmt_date(last_drs.created_at.to_date)), display_name: (last_drs.user&.display_name || "โ€”"), ad_count: last_drs.ad_count, any: (t(".covering", to_sentence: (Array(last_drs.models_covered).to_sentence)) if Array(last_drs.models_covered).any?)) %>

<% if last_drs.created_at < DrsImport::RENEW_AFTER.ago %>

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

<% end %> <% else %>

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

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

<%= t(".never_imported_for_search_drs_html", missing: (missing.join(", "))) %>

<% end %>

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

<%= t(".searched_weekly_in_the_federal_html", components: (AdWatch.new(@aircraft).terms.map(&:label).uniq.to_sentence.presence || t(".the_aircraft_and_its_installed")), ad_watch_checked_at: (t(".last_checked_ago", ad_watch_checked_at: (time_ago_in_words(@aircraft.ad_watch_checked_at))) if @aircraft.ad_watch_checked_at)) %>

<% if owner? %><%= button_to t(".check_now"), check_aircraft_ad_alerts_path(@aircraft), class: "btn-secondary btn-sm", data: { turbo_submits_with: t(".checking") } %><% end %>
<% if @alerts.any? %> <% else %> <%= empty_state t(".nothing_new_to_review") %> <% end %> <% if owner? %> <%= form_with url: terms_aircraft_ad_alerts_path(@aircraft), method: :patch, class: "flex flex-wrap items-end gap-2 border-t border-slate-100 px-4 py-3" do %>
<%= label_tag :ad_watch_terms, t(".additional_search_terms"), class: "label" %> <%= text_field_tag :ad_watch_terms, @aircraft.ad_watch_terms, class: "input", placeholder: t(".e_g_an_stc_or") %>
<%= submit_tag t(".save"), class: "btn-secondary" %>

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

<% end %> <% end %>

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

<% if @history.any? %> <% @history.each do |c| %> <% ad = c.airworthiness_directive %> <% end %>
<%= t(".date") %><%= t(".ad") %><%= t(".hours") %><%= t(".next_due_tach") %><%= t(".notes") %>
<%= fmt_date(c.date_complied) %> <%= ad_link(ad) %> <% if ad.document %><%= link_to "๐Ÿ“„", aircraft_document_path(@aircraft, ad.document), title: ad.document.name, "aria-label": t(".document", document: ad.document.name) %><% end %>
<%= ad.short_description %><%= " ยท #{c.component}" if c.component %>
<%= hours(c.aircraft_hours_at_compliance) %> <%= c.not_applicable? ? "N/A" : c.permanent? ? t(".permanent") : (c.next_due_at_time.to_f > 0 ? hours(c.next_due_at_time) : "โ€”") %>
<%= c.method_label %><%= " ยท #{c.ad_revision}" if c.ad_revision.present? %>
<%= c.compliance_notes %> <% if c.logbook_entry || c.inspection_record %>
<% if c.logbook_entry %><%= link_to t(".logbook", date: fmt_date(c.logbook_entry.date)), aircraft_logbook_entry_path(@aircraft, c.logbook_entry), class: "link" %><% end %> <% if c.inspection_record %><%= link_to "#{c.inspection_record.inspection_type.name} #{fmt_date(c.inspection_record.date)}", aircraft_inspections_path(@aircraft), class: "link" %><% end %>
<% end %>
<% if owner? %><%= link_to t(".edit"), edit_aircraft_ad_compliance_path(@aircraft, c), class: "btn-secondary btn-sm" %><% end %>
<% else %> <%= empty_state t(".no_compliance_records") %> <% end %>