module ApplicationHelper

  def menu_top(pages)
    ret = '<nav class="navbar navbar-expand-lg navbar-light fixed-top navbar-shrink" id="mainNav">'
    ret += '<div class="container-fluid">'
    ret += '<a class="navbar-brand" href="/">Ubezpieczenie-Należności.pl</a>'
    ret += '<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>'
    ret += '<div class="collapse navbar-collapse" id="navbarResponsive">'
    ret += '<ul class="navbar-nav ml-auto">'
    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
      ret += '<li class="nav-item">'
      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
      ret += '</li>'
    end
    ret += '<li class="nav-item">'
    ret += '<a class="nav-link ' + (action_name.to_s.include?('kontakt') ? 'active' : '') + '" href="/site/kontakt">Kontakt</a>'
    ret += '</li>'

    ret += '</ul></div></div></nav>'
  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
