class Playbook::PbTable::TableHeader

def active_item

def active_item
  active_item = {}
  sort_menu.each do |item|
    active_item = item if item[:active] == true
  end
  active_item
end

def active_or_first_item(items)

def active_or_first_item(items)
  active_item = items.find { |hash| hash[:active] == true }
  if active_item.present?
    active_item
  else
    items[0]
  end
end

def align_class

def align_class
  align.present? ? "align_#{align}" : nil
end

def classname

def classname
  generate_classname("pb_table_header_kit", align_class, header_style_class) + tag_class
end

def header_style_class

def header_style_class
  case header_style
  when "borderless"
    "header-borderless"
  when "floating"
    "header-floating"
  end
end

def link_style

def link_style
  active_item.any? ? "" : "color: #687887;"
end

def next_link(sort_item: "")

def next_link(sort_item: "")
  sort_menu_for = if sort_item.blank?
                    sort_menu
                  else
                    sort_items_for(sort_item)
                  end
  return sort_menu_for[0][:link] if sort_menu_for.all? { |item| item[:active] == false }
  link = ""
  sort_menu_for.each_with_index do |item, index|
    if item[:active] == true
      next_index = (index + 1) % sort_menu_for.length
      link = sort_menu_for[next_index][:link]
    end
  end
  link
end

def sort_icon(direction, active)

def sort_icon(direction, active)
  case direction
  when "asc"
    active ? "sort-amount-up" : ""
  when "desc"
    active ? "sort-amount-down" : ""
  else
    "arrow-up-arrow-down"
  end
end

def sort_items

def sort_items
  sort_menu.map { |hash| hash[:item] }.uniq
end

def sort_items_for(sort_item)

def sort_items_for(sort_item)
  sort_menu.find_all { |hash| hash[:item] == sort_item }
end

def sorting_style?

def sorting_style?
  sort_menu != [{}]
end

def tag_class

def tag_class
  " pb_table_th"
end

def use_dropdown_select

def use_dropdown_select
  sort_menu != [{}] && (object.colspan > 1 || sort_dropdown)
end