module TranslationHelper

  def qi_render_collection(collec, step=4)

    render(:partial => "qi/render_collection", :locals => {:collec => collec, :step => step})
  end

  def qit(slug, content = nil, &block)

    content = capture(&block) if block_given?

    content = slug if !content or content == ""
    slug = slug.to_slug
    t = Translation.where(:key => slug, :locale => I18n.locale).first
    if t

    else
      t = Translation.create(:key => slug, :locale => "fr", :value => content)
      t = Translation.create(:key => slug, :locale => "en", :value => content)

    end

    if @debug_translation
      raw ("[["+slug.to_slug+"]"+t.value.to_s+"]")
    else
      raw t.value
    end
  end


  def diag(show_icon=true, &block)
    content = capture(&block) if block_given?
    r = ""

    if current_admin and current_admin.id == 1
      r += "<span class='admin_diag'>"
      r += ic(:"stethoscope") if show_icon

      r += content
      r+= "</span>"
    end

    return raw(r)

  end

  def state_helper(value)
    value = value.to_s
    if ["brouillon","Reçue", "Panier web", "AV BPA"].include?(value)
      r = '<span class="badge badge-pill badge-warning">'+value+'</span>'
    elsif ["Virement envoyé", "Validé"].include?(value)
      r = '<span class="badge badge-success">'+value+'</span>'
    elsif value == "commande" or value == "Commande" or value == "Réglée" or value == "PAS BPA"
      r = '<span class="badge badge-success">'+value+'</span>'
    elsif value == "En cours d'expédition" or value == "Expédiée" or value == "BPA"
      r = '<span class="badge badge-success" style="background:#036516;">'+value+'</span>'
    elsif ["Virement demandé"].include?(value)
      r = '<span class="badge badge-info">'+value+'</span>'
    elsif value =="Livrée"
      r = '<span class="badge badge-primary">'+value+'</span>'
    elsif value == "annulée"
      r = '<span class="badge badge-dark">'+value+'</span>'
    elsif ["Erreur sur virement", "Refusé", "Refusée","refusée"].include?(value)
      r = '<span class="badge badge-danger">'+value+'</span>'
    elsif ["En cours de traitement"].include?(value)
      r = '<span class="badge badge-danger" style="background:#865F7C;">'+value+'</span>'

    elsif ["Disponible en boutique", "Disponible en point retrait"].include?(value)
      r = '<span class="badge badge-danger" style="background:#76bdf2;">'+value+'</span>'
    else
      r = '<span class="badge badge-danger" style="background:rgba(0,0,0,0.8);">'+value+'</span>'
    end

    return raw(r)
  end

end
