# frozen_string_literal: true

# ErrorsHelper
module ErrorsHelper
  def error_messages(object)
    return unless object.errors.any?

    content_tag(:div, class: 'card bg-danger p-3 text-white') do
      concat error_messages_h4
      concat error_messages_ul(object)
    end
  end

  private

  def error_messages_h4
    content_tag(:h4) do
      concat content_tag(:i, '', class: 'fas fa-exclamation-circle')
      concat " #{I18n.t('errors_ocurred')}"
    end
  end

  def error_messages_ul(object)
    content_tag(:ul, class: 'm-0') do
      object.errors.full_messages.each do |message|
        concat content_tag(:li, message)
      end
    end
  end
end
