<%= page do %>
  <%= page_header do %>
    <%= page_header_back(solidus_admin.users_path) %>
    <%= page_header_title(t(".title", email: @user.email)) %>

    <%= page_header_actions do %>
      <%= render component("ui/button").new(
        "data-action": "click->#{stimulus_id}#actionButtonClicked",
        "data-#{stimulus_id}-url-param": solidus_admin.new_user_store_credit_path(user_id: @user.id, _turbo_frame: :new_store_credit_modal),
        text: t(".add_store_credit"),
      )%>
    <% end %>
  <% end %>

  <%= page_header do %>
    <% tabs.each do |tab| %>
      <%= render(component("ui/button").new(tag: :a, scheme: :ghost, text: tab[:text], 'aria-current': tab[:current], href: tab[:href])) %>
    <% end %>
  <% end %>

  <%= page_with_sidebar do %>
    <%= page_with_sidebar_main do %>

      <% if @store_credits.present? %>
        <% @store_credits.group_by(&:currency).each do |currency, credits| %>
          <% title = [t('spree.admin.store_credits.current_balance'), Spree::Money.new(credits.sum(&:amount_remaining), currency: currency)].join(" ") %>

          <%= render component('ui/panel').new(title: title) do %>
            <%= render component('ui/table').new(
                id: stimulus_id,
                data: {
                  class: model_class,
                  rows: credits,
                  fade: -> (_order) { false },
                  columns: columns,
                  url: -> { row_url(_1) },
                },
            )%>
          <% end %>
        <% end %>
      <% else %>
        <%= render component('ui/panel').new(title: t(".store_credit")) do %>
          <%= t(".no_credits_found") %>
          <%= render component("ui/button").new(
            "data-action": "click->#{stimulus_id}#actionButtonClicked",
            "data-#{stimulus_id}-url-param": solidus_admin.new_user_store_credit_path(user_id: @user.id, _turbo_frame: :new_store_credit_modal),
            text: t(".create_one"),
          )%>
        <% end %>
      <% end %>
    <% end %>

    <%= page_with_sidebar_aside do %>
      <%= render component("users/stats").new(user: @user) %>
    <% end %>
  <% end %>

  <% turbo_frames.each do |frame| %>
    <%= turbo_frame_tag frame %>
  <% end %>
<% end %>
