module TranslationHelper

  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 state_helper(value)
    value = value.to_s
    if ["brouillon","Reçue","A traiter", "En cours de vérification", "Manque RIB"].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"
      r = '<span class="badge badge-success">Commande</span>'
    elsif value == "livraison-en-cours"
      r = '<span class="badge badge-success" style="background:#036516;">Livr. en cours</span>'
    elsif ["Virement demandé"].include?(value)
      r = '<span class="badge badge-info">'+value+'</span>'
    elsif value =="facturée"
      r = '<span class="badge badge-primary">Facturée</span>'
    elsif value == "annulée"
      r = '<span class="badge badge-dark">Annulée</span>'
    elsif ["Erreur sur virement", "Refusé", "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>'
    
    else
      r = '<span class="badge badge-danger" style="background:rgba(0,0,0,0.8);">'+value+'</span>'
    end
    
    return raw(r)
  end

end
