<%= turbo_stream.update "flash", partial: "layouts/flash" %>
<%# FIXME: change to local variables (find out how.. ;)) %>
<% if @status_changed %>
  <%= turbo_stream.remove @job %>
  <% case @job.status.to_sym %>
  <% when :canceled, :paid %>
    <%= turbo_stream.append :paidcanceledjobs, partial: "job_tr", locals: { job: @job} %>
  <% when :open %>
    <!-- Update the whole list because the order should be preserved -->
    <%= turbo_stream.update :openjobs, partial: "job_tr", collection: @openjobs, as: :job %>
  <% else %>
    <%= turbo_stream.append "#{@job.status}jobs", partial: "job_tr", locals: { job: @job} %>
  <% end %>
  <%= turbo_stream.replace "openjobs_status_card", partial: "job_status_card", locals: { jobs: @openjobs, status: :open } %>
  <%= turbo_stream.replace "printingjobs_status_card", partial: "job_status_card", locals: { jobs: @printingjobs, status: :printing } %>
  <%= turbo_stream.replace "pickupjobs_status_card", partial: "job_status_card", locals: { jobs: @pickupjobs, status: :pickup } %>
  <%= turbo_stream.replace "paidjobs_status_card", partial: "job_status_card", locals: { jobs: @paidjobs, status: :paid } %>
  <%= turbo_stream.replace "canceledjobs_status_card", partial: "job_status_card", locals: { jobs: @canceledjobs, status: :canceled } %>
  <%= turbo_stream.replace "start_next_job_btn", partial: "start_next_job_btn", locals: { jobs: @openjobs} %>
<% else %>
  <%= turbo_stream.replace @job, partial: "job_tr", locals: { job: @job } %>
<% end %>
