%ul.deliveryList
  - if message.queued_message && message.queued_message.locked?
    %li.deliveryList__item.deliveryList__item--header
      %p Message is currently being processed.
  - elsif message.queued_message && message.queued_message.retry_after
    %li.deliveryList__item.deliveryList__item--header
      %p This message will be retried automatically in #{distance_of_time_in_words_to_now message.queued_message.retry_after}.
      %p= link_to "Retry delivery now", retry_organization_server_message_path(organization, @server, message.id), :class => "button button--small", :remote => true, :method => :post
  - elsif message.held?
    %li.deliveryList__item.deliveryList__item--header
      %p
        This message has been held. By releasing the message, we will allow it to continue on its way to its destination.
        - if @message.hold_expiry
          It will be held until #{@message.hold_expiry.to_s(:long)}.
      %p.buttonSet
        = link_to "Release message", retry_organization_server_message_path(organization, @server, message.id), :class => "button button--small", :remote => true, :method => :post
        = link_to "Cancel hold", cancel_hold_organization_server_message_path(organization, @server, message.id), :class => "button button--small button--danger", :remote => true, :method => :post
  - elsif @server.mode == 'Development'
    %li.deliveryList__item.deliveryList__item--header
      %p This server is in development mode so this message can be redelivered as if it had just been received.
      %p= link_to "Redeliver message", retry_organization_server_message_path(organization, @server, message.id), :class => "button button--small", :remote => true, :method => :post
  - else
    %li.deliveryList__item.deliveryList__item--header
      %p This message can be redelivered as if it had just been received.
      %p= link_to "Redeliver message", retry_organization_server_message_path(organization, @server, message.id), :class => "button button--small", :remote => true, :method => :post

  - if message.deliveries.empty?
    %li.deliveryList__item
      .noData.noData--clean
        %h2.noData__text No delivery attempts yet.
  - else
    - for delivery in message.deliveries.reverse
      %li.deliveryList__item
        .deliveryList__top
          .deliveryList__time
            = delivery.timestamp.to_s(:long)
          .deliveryList__status
            - if delivery.sent_with_ssl
              = image_tag 'icons/lock.svg', :class => 'deliveryList__secure'
            %span.label.label--large{:class => "label--messageStatus-#{delivery.status.underscore}"}= delivery.status.underscore.humanize
        - if delivery.details
          %p.deliveryList__error= format_delivery_details(@server, delivery.details)
        - if delivery.log_id || delivery.output
          = link_to "Show technical details", '#', :class => 'js-toggle js-tech-link deliveryList__techLink', :data => {:element => '.js-tech-link, .js-tech-output'}
          .deliveryList__error.deliveryList__error--output.js-tech-output.is-hidden
            %p.deliveryList__error--output-text= delivery.output
            - if delivery.time
              %p.deliveryList__error--output-ref Time: #{delivery.time}s
            - if delivery.log_id
              %p.deliveryList__error--output-ref Support Ref: #{delivery.log_id}
- if message.queued_message && !message.queued_message.locked?
  %p.deliveryList-removeLink= link_to "Remove from queue", remove_from_queue_organization_server_message_path(organization, @server, message.id), :method => :delete, :remote => true, :data => {:disable_with => "Removing...", :confirm => "Are you sure you wish to remove this message from the queue?"}, :class => "u-link"
