<%# The Print label dialog: the label's lines (filled from the issue, estimate or invoice), a preview drawn the way the print agent draws it (assets/javascripts/qbo_labels.js), copies and printer %>
<% if @printers.empty? %>

<%= l(:text_qbo_labels_no_printers) %>

<% else %> <%= form_tag label_jobs_path, remote: true, id: 'qbo-label-form' do %> <%= hidden_field_tag :source_type, @source.type %> <%= hidden_field_tag :source_id, @source.id %> <% if @job&.errors&.any? %>
<% end %>
<% if @source.title %>
<%= @source.title %>
<% end %>

<%= text_field_tag 'lines[]', @lines[0], id: 'qbo_label_line_0', class: 'qbo-label-line', maxlength: LabelJob::MAX_LINE_LENGTH, autocomplete: 'off' %>

<% suggestions = @source.po_suggestions %> <%= text_field_tag 'lines[]', @lines[1], id: 'qbo_label_line_1', class: 'qbo-label-line', maxlength: LabelJob::MAX_LINE_LENGTH, autocomplete: 'off', list: ('qbo_label_po_numbers' if suggestions.any?), placeholder: ('E1234, I1234, W1234' if @lines[1].blank?) %> <% if suggestions.any? %> <% suggestions.each do |number, description| %><% end %> <%= l(:text_qbo_labels_po_suggestions) %> <% end %>

<%= number_field_tag :copies, @copies, id: 'qbo_label_copies', min: 1, max: LabelJob::MAX_COPIES, class: 'qbo-label-copies' %>

<% if @printers.size > 1 %>

<%= select_tag :printer_id, options_for_select(@printers.map { |p| ["#{p.name}#{" (#{l(:label_qbo_labels_offline)})" unless p.online?}", p.id] }, params[:printer_id] || @printers.find(&:online?)&.id), id: 'qbo_label_printer' %>

<% elsif !@printers.first.online? %>

<%= l(:text_qbo_labels_printer_offline, name: @printers.first.name) %>

<% end %>

<%= submit_tag l(:button_qbo_labels_print), class: 'qbo-label-submit', data: { disable_with: l(:button_qbo_labels_print) } %> <%= link_to_function l(:button_cancel), 'hideModal(this);' %>

<% end %> <% end %>