module Playbook::Props

def clear_props

def clear_props
  props.keys.each { |prop_name| remove_method(prop_name) }
  props.clear
end

def dark_props

def dark_props
  dark ? "dark" : nil
end

def generate_classname(*name_parts, separator: "_")

def generate_classname(*name_parts, separator: "_")
  [
    name_parts.compact.join(separator),
    prop(:classname),
    spacing_props,
    dark_props,
    max_width_props,
    z_index_props,
  ].compact.join(" ")
end

def generate_classname_without_spacing(*name_parts, separator: "_")

def generate_classname_without_spacing(*name_parts, separator: "_")
  [
    name_parts.compact.join(separator),
    prop(:classname),
  ].compact.join(" ")
end

def initialize(prop_values = {}, &block)

def initialize(prop_values = {}, &block)
  self.values = { children: block }.merge(Hash(prop_values))
  self.class.props.each do |key, definition|
    definition.validate! values[key]
  end
end

def max_width_options

def max_width_options
  {
    max_width: "mw",
  }
end

def max_width_props

def max_width_props
  selected_mw_props = max_width_options.keys.select { |sk| try(sk) }
  return nil unless selected_mw_props.present?
  selected_mw_props.map do |k|
    width_value = send(k)
    "max_width_#{width_value}" if max_width_values.include? width_value
  end.compact.join(" ")
end

def max_width_values

def max_width_values
  %w[sm md lg xl]
end

def partial(path)

def partial(path)
  define_method(:to_partial_path) { path }
end

def prop(name)

def prop(name)
  self.class.props[name].value values[name]
end

def prop(name, type: Playbook::Props::String, **options)

def prop(name, type: Playbook::Props::String, **options)
  self.props = self.props.merge(name => type.new(options.merge(name: name, kit: self)))
  define_method(name) { prop(name) }
end

def spacing_options

def spacing_options
  {
    margin: "m",
    margin_bottom: "mb",
    margin_left: "ml",
    margin_right: "mr",
    margin_top: "mt",
    margin_x: "mx",
    margin_y: "my",
    padding: "p",
    padding_bottom: "pb",
    padding_left: "pl",
    padding_right: "pr",
    padding_top: "pt",
    padding_x: "px",
    padding_y: "py",
  }
end

def spacing_props

def spacing_props
  selected_props = spacing_options.keys.select { |sk| try(sk) }
  return nil unless selected_props.present?
  selected_props.map do |k|
    spacing_value = send(k)
    "#{spacing_options[k]}_#{spacing_value}" if spacing_values.include? spacing_value
  end.compact.join(" ")
end

def spacing_values

def spacing_values
  %w[none xs sm md lg xl]
end

def z_index_options

def z_index_options
  {
    z_index: "z-index",
  }
end

def z_index_props

def z_index_props
  selected_index_props = z_index_options.keys.select { |sk| try(sk) }
  return nil unless selected_index_props.present?
  selected_index_props.map do |k|
    index_value = send(k)
    "z_index_#{index_value}" if z_index_values.include? index_value
  end.compact.join(" ")
end

def z_index_values

def z_index_values
  %w[1 2 3 4 5 6 7 8 9 10]
end