<% resource_id = @resource.id if @resource -%>

<table class="data">
  <thead>
  <tr>
    <% unless key_field(property) -%>
      <%= hidden_field_tag "auto_generate[#{property.key}]", true -%>
    <% end -%>
    <% property.fields.each do |field| -%>
      <th>
        <%= field_name(property, field) -%>
        <% desc = field_description(property, field) -%>
        <% unless desc.blank? %>
          <p class="note"><%= desc -%></p>
        <% end -%>
      </th>
    <% end -%>
    <th></th>
  </tr>
  </thead>

  <tbody>
  <% set_keys = Property.values(property.key, resource_id) -%>
  <% set_keys = [''] if set_keys.all?(&:blank?) -%>
  <% set_keys.each_with_index do |set_key, index| -%>
    <%= render 'settings/set_instance', :property => property, :set_key => set_key, :resource_id => resource_id, :hide_delete => (index == 0) %>
  <% end -%>
  <%= render 'settings/set_instance', :property => property, :set_key => nil, :resource_id => resource_id, :hide_delete => false %>
  </tbody>

  <tfoot>
  <tr>
    <td colspan="<%= property.fields.size + 1 -%>">
      <button class="add_value"><%= message('settings.add') -%></button>
    </td>
  </tr>
  </tfoot>
</table>
