class Avo::TabSwitcherComponent

def initialize(resource:, group:, current_tab:, active_tab_name:, view:)

def initialize(resource:, group:, current_tab:, active_tab_name:, view:)
  @active_tab_name = active_tab_name
  @resource = resource
  @group = group
  @current_tab = current_tab
  @tabs = group.items
  @view = view
end

def is_edit?

def is_edit?
  @view.in?([:edit, :update])
end

def is_initial_load?

def is_initial_load?
  params[:active_tab_name].blank?
end

def is_new?

def is_new?
  @view.in?([:new, :create])
end

def selected?(tab)

We do that so we don't get the wrongly selected item for a quick brief when first switching from one panel to another.
On initial load we want that each tab button to be the selected one.
def selected?(tab)
  if is_initial_load?
    current_tab.name.to_s == tab.name.to_s
  else
    tab.name.to_s == active_tab_name.to_s
  end
end

def tab_path(tab)

TOD: helper to record:
def tab_path(tab)
  if is_edit?
    helpers.edit_resource_path(resource: @resource, record: @resource.record, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id)
  elsif is_new?
    helpers.new_resource_path(resource: @resource, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id)
  else
    helpers.resource_path(resource: @resource, record: @resource.record, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id)
  end
end