class Avo::ActionsComponent

def action_css_class(action)

def action_css_class(action)
  helpers.class_names("flex items-center px-4 py-3 w-full font-semibold text-sm hover:bg-primary-100", {
    "text-gray-500": action.disabled?,
    "text-black": action.enabled?,
  })
end

def action_data_attributes(action)

def action_data_attributes(action)
  {
    action_name: action.action_name,
    "turbo-frame": Avo::MODAL_FRAME_ID,
    action: "click->actions-picker#visitAction",
    "actions-picker-target": action.standalone ? "standaloneAction" : "resourceAction",
    disabled: action.disabled?,
    turbo_prefetch: false,
    enabled_classes: "text-black",
    disabled_classes: "text-gray-500",
    resource_name: action.resource.model_key
  }
end

def after_initialize

def after_initialize
  filter_actions unless @custom_list
  # Hydrate each action action with the record when rendering a list on row controls
  if @as_row_control
    @actions.each do |action|
      action.hydrate(resource: @resource, record: @resource.record) if action.respond_to?(:hydrate)
    end
  end
end

def filter_actions

def filter_actions
  @actions = @actions.dup
  if @exclude.any?
    @actions.reject! { |action| @exclude.include?(action.class) }
  end
  if @include.any?
    @actions.select! { |action| @include.include?(action.class) }
  end
end

def icon(icon)

def icon(icon)
  svg icon, class: "h-5 shrink-0 mr-1 inline pointer-events-none"
end

def render?

def render?
  @actions.present?
end

def render_action_link(action, icon: nil)

def render_action_link(action, icon: nil)
  link_to action.link_arguments(resource: @resource, arguments: action.arguments).first,
    data: action_data_attributes(action),
    title: action.action_name,
    class: action_css_class(action) do
      raw("#{icon(icon || action.icon)} #{action.action_name}")
    end
end

def render_item(action)

def render_item(action)
  case action
  when Avo::Divider
    render Avo::DividerComponent.new(action.label)
  when Avo::BaseAction
    render_action_link(action)
  when defined?(Avo::Advanced::Resources::Controls::Action) && Avo::Advanced::Resources::Controls::Action
    render_action_link(action.action, icon: action.icon)
  when defined?(Avo::Advanced::Resources::Controls::LinkTo) && Avo::Advanced::Resources::Controls::LinkTo
    link_to action.args[:path],
      class: action.args.delete(:class) || "flex items-center px-4 py-3 w-full text-black font-semibold text-sm hover:bg-primary-100",
      **action.args.except(:path, :label, :icon) do
        raw("#{icon(action.args[:icon])} #{action.args[:label]}")
      end
  end
end