<% creative_concept = @creative_concept %>
<% context ||= creative_concept %>
<% collection ||= :collaborators %>
<% hide_actions ||= false %>
<% hide_back ||= false %>

<%= render 'account/shared/box' do |box| %>
  <% box.title t(".contexts.#{context.class.name.underscore}.header") %>
  <% box.description t(".contexts.#{context.class.name.underscore}.description") %>

  <% box.table do %>
    <% if collaborators.any? %>
      <table class="table">
        <thead>
          <tr>
            <th><%= t('.fields.membership_id.heading') %></th>
            <th><%= t('.fields.role_ids.heading') %></th>
            <%# 🚅 super scaffolding will insert new field headers above this line. %>
            <th class="text-right"></th>
          </tr>
        </thead>
        <tbody>
          <% collaborators.each do |collaborator| %>
            <tr data-id="<%= collaborator.id %>">
              <td><%= link_to collaborator.membership.label_string, [:account, collaborator] %></td>
              <td>
                <% if collaborator.roles_without_defaults.present? %>
                  <%= collaborator.roles_without_defaults.map { |role| t("#{collaborator.class.to_s.pluralize.underscore}.fields.role_ids.options.#{role.key}.label") }.to_sentence %>
                <% else %>
                  <%= t(".fields.role_ids.none") %>
                <% end %>
              </td>
              <%# 🚅 super scaffolding will insert new fields above this line. %>
              <td class="buttons">
                <% unless hide_actions %>
                  <% if can? :edit, collaborator %>
                    <%= link_to t('.buttons.shorthand.edit'), [:edit, :account, collaborator], class: 'button-secondary button-smaller' %>
                  <% end %>
                  <% if can? :destroy, collaborator %>
                    <%= button_to t('.buttons.shorthand.destroy'), [:account, collaborator], method: :delete, data: { confirm: t('.buttons.confirmations.destroy', model_locales(collaborator)) }, class: 'button-secondary button-smaller' %>
                  <% end %>
                <% end %>
              </td>
            </tr>
          <% end %>
        </tbody>
      </table>
    <% end %>
  <% end %>

  <% box.actions do %>
    <% unless hide_actions %>
      <% if context == creative_concept %>
        <% if can? :create, Scaffolding::AbsolutelyAbstract::CreativeConcepts::Collaborator.new(creative_concept: creative_concept) %>
          <%= link_to t('.buttons.new'), [:new, :account, creative_concept, :collaborator], class: 'button' %>
        <% end %>
      <% end %>

      <% unless hide_back %>
        <%= link_to t('global.buttons.back'), [:account, context], class: 'button-secondary' %>
      <% end %>
    <% end %>
  <% end %>
<% end %>