<% if local_assigns[:collection] %>
  <tr class="tr">
    <td class="td"><%= printful_shipment.created_at.in_time_zone('America/New_York') %></td>
    <td class="td">
      <%= printful_shipment.type_text %>: <%= printful_shipment.title_text %>
    </td>
    <td class="td"><%= printful_shipment.status_text %></td>
    <td class="td">
      <%= link_to "Open", show_lsv_path(LSV.slug_for(printful_shipment), printful_shipment.id),
                  onclick: "openIframeWindow(this.href, '#{printful_shipment.type_text}: #{printful_shipment.title_text}'); return false;", 
                  class: 'btn' %>
    </td>
  </tr>
<% else %>
  <% content_for :window_title do %>
    <%= printful_shipment.type_text %>: <%= printful_shipment.title_text %>
  <% end %>
  <div class="window-body">
    <div class="field-row" style="margin-bottom: 1rem;">
      <b style="margin: 0;"><%= printful_shipment.title_text %></b>
    </div>
    <div class="field-row" style="margin-bottom: 0.5rem;">
      <label style="width: 80px;">Type:</label>
      <span><%= printful_shipment.type_text %></span>
    </div>
    <div class="field-row" style="margin-bottom: 0.5rem;">
      <label style="width: 80px;">Status:</label>
      <span><%= printful_shipment.status_text %></span>
    </div>
    <% if printful_shipment.tracking_number %>
      <div class="field-row" style="margin-bottom: 0.5rem;">
        <label style="width: 80px;">Tracking:</label>
        <% if printful_shipment.tracking_link %>
          <%= link_to(printful_shipment.tracking_number, printful_shipment.tracking_link, target: "_blank", class: "link") %>
        <% else %>
          <span><%= printful_shipment.tracking_number %></span>
        <% end %>
      </div>
    <% end %>
    <% if printful_shipment.description %>
      <div class="field-row" style="margin-bottom: 0.5rem;">
        <label style="width: 80px;">Contents:</label>
        <% if printful_shipment.description.is_a? Array %>
          <ul class="tree-view" style="margin: 0;">
            <% printful_shipment.description.each do |item| %>
              <li><%= item %></li>
            <% end %>
          </ul>
        <% else %>
          <span><%= printful_shipment.description %></span>
        <% end %>
      </div>
    <% end %>
    <div class="field-row" style="margin-bottom: 0.5rem;">
      <label style="width: 80px;">Created:</label>
      <span><%= printful_shipment.created_at %></span>
    </div>
    <% back_office_tool do %>
      <% if printful_shipment.fields["%order:pretty_id"] %>
        <div class="field-row" style="margin-bottom: 0.5rem;">
          <label style="width: 80px;">Order:</label>
          <span>
            <%= link_to printful_shipment.fields["%order:pretty_id"], printful_shipment.fields["%order:dashboard_url"], target: "_blank", class: "link" %>
          </span>
        </div>
      <% end %>
      <% if printful_shipment.fields["packing_slip_url"] %>
        <div class="field-row" style="margin-bottom: 0.5rem;">
          <label style="width: 80px;">Packing:</label>
          <span>
            <%= link_to "View Packing Slip", printful_shipment.fields["packing_slip_url"], target: "_blank", class: "link" %>
          </span>
        </div>
      <% end %>
      <div class="field-row" style="margin-bottom: 0.5rem;">
        <label style="width: 80px;">Airtable:</label>
        <span class="internal"><%= link_to(printful_shipment.source_id, printful_shipment.source_url, target: "_blank") %></span>
      </div>
    <% end %>
    <%= render 'application/admin_inspector', record: printful_shipment %>
  </div>
<% end %> 