<%= content_tag :div, data: { 'model-id': @resource.model.id, selected_resources_name: @resource.model_key, selected_resources: [@resource.model.id], **@resource.stimulus_data_attributes } do %> <%= render Avo::PanelComponent.new(title: title, description: @resource.resource_description, display_breadcrumbs: @reflection.blank?, index: 0, data: { panel_id: "main" }) do |c| %> <% c.tools do %> <% if @reflection.present? && @resource.model.present? %> <% if can_detach? %> <%= a_button url: detach_path, icon: 'detach', method: :delete, form_class: 'flex flex-col sm:flex-row sm:inline-flex', style: :text, data: { confirm: "Are you sure you want to detach this #{title}." } do %> <%= t('avo.detach_item', item: title).capitalize %> <% end %> <% end %> <%= render Avo::ActionsComponent.new actions: @actions, resource: @resource, view: @view %> <% if can_see_the_edit_button? %> <%= a_link edit_path, color: :primary, style: :primary, icon: 'edit' do %> <%= t('avo.edit').capitalize %> <% end %> <% end %> <% else %> <%= a_link back_path, style: :text, icon: 'arrow-left' do %> <%= t('avo.go_back') %> <% end %> <% if can_see_the_destroy_button? %> <%= a_button url: helpers.resource_path(model: @resource.model, resource: @resource), method: :delete, local: true, style: :text, loading: true, confirm: t('avo.are_you_sure', item: @resource.model.model_name.name.downcase), color: :red, icon: 'trash', form_class: 'flex flex-col sm:flex-row sm:inline-flex', data: { control: :destroy, 'resource-id': @resource.model.id, } do %> <%= t('avo.delete').capitalize %> <% end %> <% end %> <%= render Avo::ActionsComponent.new actions: @actions, resource: @resource, view: @view %> <% if @resource.authorization.authorize_action(:edit, raise_exception: false) %> <%= a_link edit_path, color: :primary, style: :primary, icon: 'edit' do %> <%= t('avo.edit').capitalize %> <% end %> <% end %> <% end %> <% end %> <% if main_panel.present? %> <% c.body do %>
<% main_panel.items.each_with_index do |field, index| %> <%= render field.hydrate(resource: @resource, model: @resource.model, user: @resource.user, view: view) .component_for_view(view) .new(field: field, resource: @resource, index: index) %> <% end %>
<% end %> <% end %> <% end %> <% if @reflection.blank? %> <%= content_tag :div, class: 'space-y-12 mt-12' do %> <% @resource.get_items.each_with_index do |item, index| %> <% next if item.nil? %> <%= render Avo::ItemSwitcherComponent.new resource: @resource, reflection: @reflection, item: item, index: index + 1, view: @view %> <% end %> <% end %> <% end %> <% if should_display_invalid_fields_errors? %> <% end %> <% end %>