# frozen_string_literal: true

module FormElements
  class FieldsetResettableSettingComponent < ViewComponent::Base
    def initialize(tag: "li", key:, type: :text, title:, description: nil)
      @tag         = tag
      @positioning = :vertical
      @title       = title
      @description  = description
      @key         = key.to_sym
      @type        = type
      @resettable  = is_resettable?(@key)
    end

    def is_resettable?(key)
      default_value = Setting.get_field(key)[:default]
      default_value.present? && (default_value != Setting.send(key))
    end
  end
end
