#==============================================================================
# ** Window_Settings
#==============================================================================----
#  This file contains all the "elements" of window_settings
#==============================================================================
class Window_Settings
  class SettingsElement
    def initialize(name, type, color = Color.new(255, 255, 255), custom_sound: nil)
      @name = name
      @type = type
      @color = color
      @custom_sound = custom_sound
    end

    def increment
      @type.increment
    end

    def decrement
      @type.decrement
    end

    def value
      @type.value
    end

    def type
      @type.class.name.downcase
    end

    def name
      @name
    end

    def type_class
      @type
    end

    def raw_value
      @type.raw_value
    end

    def color
      @color
    end

    def custom_sound
      return @custom_sound if !@custom_sound && @custom_sound.class != Proc
      return @custom_sound.call()
    end
  end

  # Variable -> Variable in string form (working without pointers here)
  class Slider
    attr_accessor :min
    attr_accessor :max
    attr_accessor :step

    def initialize(proxy, min, max, step = 1)
      @proxy = proxy
      @min = min
      @max = max
      @step = step
    end

    def increment()
      @proxy.call([@proxy.call() + @step, @max].min)
    end

    def decrement()
      @proxy.call([@proxy.call() - @step, @min].max)
    end

    def value
      return @proxy.call()
    end

    def raw_value
      return @proxy.call()
    end
  end

  class Boolean
    def initialize(proxy, true_text = "ON", false_text = "OFF")
      @proxy = proxy
      @true_text = true_text
      @false_text = false_text
    end

    def increment
      @proxy.call(!@proxy.call())
    end

    def decrement
      increment
    end

    def value
      return @proxy.call() ? @true_text : @false_text
    end

    def raw_value
      return @proxy.call()
    end
  end

  class List
    def initialize(proxy, list)
      @proxy = proxy
      @list = list
    end

    def increment
      @list.rotate!(1)
      @proxy.call(@list[0])
    end

    def decrement
      @list.rotate!(-1)
      @proxy.call(@list[0])
    end

    def value
      @proxy.call().upcase()
    end

    def raw_value
      @proxy.call()
    end
  end

  class LanguageElement
    def initialize
      @lang_index = 0
    end

    def increment
      @lang_index += 1
      @lang_index = 0 if @lang_index >= Language::LANGUAGES.length
      $persistent.lang = Language::LANGUAGES[@lang_index]
    end

    def decrement
      @lang_index -= 1
      @lang_index = Language::LANGUAGES.length - 1 if @lang_index < 0
      $persistent.lang = Language::LANGUAGES[@lang_index]
    end

    def value
      return Language::LANGUAGES[@lang_index] rescue Language::LANGUAGES[0]
    end

    def raw_value
      :ignore
    end
  end

  class Text
    def decrement
    end

    def increment
    end

    def value
    end

    def raw_value
      :ignore
    end
  end
end
