<% admin_layout "full-width" %>

<% admin_breadcrumb(link_to plural_resource_name(SolidusPromotions::Promotion), solidus_promotions.admin_promotions_path) %>
<% admin_breadcrumb(@promotion.name) %>

<%= content_for :head do %>
  <%= javascript_importmap_tags "backend/solidus_promotions", importmap: SolidusPromotions.importmap %>
  <%#= stylesheet_link_tag 'solidus_promotions/promotions' %>
<% end %>

<% content_for :page_actions do %>
  <li>
    <% if can?(:show, SolidusPromotions::PromotionCode) %>
      <%= link_to t('solidus_promotions.view_promotion_codes_list'), solidus_promotions.admin_promotion_promotion_codes_path(promotion_id: @promotion.id), class: 'btn btn-primary' %>

      <%= link_to t('solidus_promotions.download_promotion_codes_list'), solidus_promotions.admin_promotion_promotion_codes_path(promotion_id: @promotion.id, format: :csv), class: 'btn btn-primary' %>
    <% end %>

    <% if can?(:show, SolidusPromotions::PromotionCodeBatch) %>
      <%= link_to plural_resource_name(SolidusPromotions::PromotionCodeBatch), solidus_promotions.admin_promotion_promotion_code_batches_path(promotion_id: @promotion.id), class: 'btn btn-primary' %>
    <% end %>
  </li>
<% end %>

<%= form_for @promotion, url: object_url, method: :put do |f| %>
  <%= render partial: 'form', locals: { f: f } %>
  <% if can?(:update, @promotion) %>
    <%= render partial: 'spree/admin/shared/edit_resource_links' %>
  <% end %>
<% end %>

<fieldset>
  <legend align="center"><%= t("benefits", scope: :solidus_promotions) %></legend>
    <% if @promotion.benefits.any? %>
      <%= render partial: 'solidus_promotions/admin/benefits/benefit', collection: @promotion.benefits %>
    <% end %>

    <%= turbo_frame_tag @promotion, "new_benefit" do %>
      <%= link_to t(:add_benefit, scope: :solidus_promotions), solidus_promotions.new_admin_promotion_benefit_path(@promotion), class: 'btn btn-secondary' %>
    <% end %>
</fieldset>
