%= content_tag :div,
id: "element_#{element.id}",
data: {'element-id' => element.id, 'element-name' => element.name},
class: element.css_classes do %>
<% unless element.fixed? %>
<%= render 'alchemy/admin/elements/header', element: element %>
<% end %>
<% if element.expanded? || element.fixed? %>
<%= render 'alchemy/admin/elements/toolbar', element: element %>
<% element.definition[:message].tap do |message| %>
<%= render_message(:info, sanitize(message)) if message %>
<% end %>
<% element.definition[:warning].tap do |warning| %>
<%= render_message(:warning, sanitize(warning)) if warning %>
<% end %>
<% if element.editable? %>
<%= form_for [alchemy, :admin, element], remote: true,
html: {id: "element_#{element.id}_form".html_safe, class: 'element-content'} do |f| %>
<%= render element.ingredients.select { |i| !i.definition[:group] }, element_form: f %>
<% element.ingredients.select { |i| i.definition[:group] }.group_by { |i| i.definition[:group] }.each do |group, ingredients| %>
<%= link_to '#', id: "element_#{element.id}_content_group_#{group.parameterize.underscore}_header", class: 'content-group-header', data: { toggle_content_group: true } do %>
<%= element.translated_group group %>
<% end %>
<%= content_tag :div, id: "element_#{element.id}_content_group_#{group.parameterize.underscore}", class: 'content-group-contents' do %>
<%= render ingredients, element_form: f %>
<% end %>
<% end %>
<% end %>
<%= render element.contents.select { |c| !c.definition[:group] } %>
<% element.contents.select { |c| c.definition[:group] }.group_by { |c| c.definition[:group] }.each do |group, contents| %>
<%= link_to '#', id: "element_#{element.id}_content_group_#{group.parameterize.underscore}_header", class: 'content-group-header', data: { toggle_content_group: true } do %>
<%= element.translated_group group %>
<% end %>
<%= content_tag :div, id: "element_#{element.id}_content_group_#{group.parameterize.underscore}", class: 'content-group-contents' do %>
<%= render contents, element_form: f %>
<% end %>
<% end %>
<% if element.taggable? %>
<%= f.label :tag_list %>
<%= render 'alchemy/admin/partials/autocomplete_tag_list', f: f %>
<% end %>
<% end %>
<%= render 'alchemy/admin/elements/footer', element: element %>
<% end %>
<% end %>
<% if element.nestable_elements.any? %>
<%= content_tag :div,
class: "nested-elements", data: {
'droppable-elements' => element.nestable_elements.join(' ')
} do %>
<%= render element.all_nested_elements.map { |element|
Alchemy::ElementEditor.new(element)
} %>
<% end %>
<%= render "alchemy/admin/elements/add_nested_element_form", element: element %>
<% end %>
<% end %>