module ApplicationHelper

  def menu_top(pages)
    ret = ''
    friendly_id = nil
    if params[:id]
      if pp = PublishedPage.where('id = ? OR slug = ?',params[:id],params[:id]).first
        friendly_id = pp.type_of == 3 ? pp.article_friendly : params[:id]
      end
    end
    for page in pages
      if !friendly_id.blank?
        ret += '<a class="nav-link ' + (friendly_id.include?(page.friendly_id) ? 'active' : '') + '" href="/site/' + page.friendly_id + '">' + page.name + '</a>'
      else
        ret += '<a class="nav-link" href="/site/' + page.friendly_id + '">' + page.name + '</a>'
      end
    end

    ret
  end
  # generate errors html
  def errors_to_html(errors)
    ret = '<div class="row"><div class="col-lg-12 col-md-12 panel-danger"><div class="content-box-header panel-heading"><div class="panel-title">'
    ret += I18n.t("activerecord.errors.messages.record_invalid", errors: errors.count)
    ret += '</div></div><div class="content-box-large box-with-header" style="background:#f9dddd"><ul>'
    errors.full_messages.each do |msg|
      ret += "<li>#{msg}</li>"
    end
    ret += "</ul></div></div></div>"
    ret
  end

end
