class Playbook::PbButton::Button

def classname

def classname
  button_class = generate_classname("pb_button_kit", variant, full_width_class, disabled_class, loading_class)
  button_class + size_class
end

def disabled_class

def disabled_class
  disabled ? "disabled" : "enabled"
end

def full_width_class

def full_width_class
  full_width ? "block" : "inline"
end

def link_options

def link_options
  options.tap do |option|
    option[:href] = link
    option[:role] = "link"
    option[:target] = target_attribute if target_attribute.present?
    option[:tabindex] = 0
  end
end

def loading_class

def loading_class
  loading ? "loading" : nil
end

def options

def options
  {
    aria: aria,
    class: classname,
    data: data,
    disabled: disabled,
    id: id,
    role: "button",
    tabindex: 0,
    type: type,
    value: value,
    form: form,
  }.compact
end

def size_class

def size_class
  size ? " size_#{size}" : ""
end

def tag

def tag
  link ? "a" : "button"
end

def target_attribute

def target_attribute
  if target && link
    target
  elsif new_window
    "_blank"
  end
end