# app/helpers/application_helper.rb module ApplicationHelper # Formata valor monetário → "R$ 1.250,00" def moeda(valor) "R$ #{format('%.2f', valor.to_f).gsub('.', ',')}" end # Link ativo na sidebar def nav_link_to(nome, path, icon: nil, **opts) ativo = current_page?(path) || request.path.start_with?(path.to_s) classes = [ 'flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-medium transition-all', ativo ? 'bg-[#f97316] text-white shadow-lg shadow-orange-500/20' : 'text-gray-400 hover:text-white hover:bg-white/5' ].join(' ') link_to path, class: classes, **opts do concat content_tag(:span, icon, class: 'text-lg w-5 text-center') if icon concat content_tag(:span, nome) end end # Badge colorido por status de consolidação def badge_status(status) config = { 'aberta' => { bg: 'bg-yellow-500/20', text: 'text-yellow-400', label: 'Aberta' }, 'em_revisao' => { bg: 'bg-blue-500/20', text: 'text-blue-400', label: 'Em Revisão' }, 'fechada' => { bg: 'bg-green-500/20', text: 'text-green-400', label: 'Fechada' }, 'aprovada' => { bg: 'bg-[#f97316]/20', text: 'text-[#f97316]', label: 'Aprovada' }, 'cancelada' => { bg: 'bg-red-500/20', text: 'text-red-400', label: 'Cancelada' } } c = config[status.to_s] || { bg: 'bg-gray-500/20', text: 'text-gray-400', label: status.to_s.humanize } content_tag(:span, c[:label], class: "inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-medium #{c[:bg]} #{c[:text]}") end # Badge de role do usuário def badge_role(role) config = { 'admin' => { bg: 'bg-purple-500/20', text: 'text-purple-400', label: 'Admin' }, 'gerente' => { bg: 'bg-blue-500/20', text: 'text-blue-400', label: 'Gerente' }, 'operador' => { bg: 'bg-cyan-500/20', text: 'text-cyan-400', label: 'Operador' }, 'motorista'=> { bg: 'bg-green-500/20', text: 'text-green-400', label: 'Motorista' } } c = config[role.to_s] || { bg: 'bg-gray-500/20', text: 'text-gray-400', label: role.to_s.humanize } content_tag(:span, c[:label], class: "inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-medium #{c[:bg]} #{c[:text]}") end # Badge de status ativo/inativo do usuário def badge_status_usuario(ativo) if ativo content_tag(:span, 'Ativo', class: 'inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-medium bg-green-500/20 text-green-400') else content_tag(:span, 'Inativo', class: 'inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-medium bg-red-500/20 text-red-400') end end # Barra de progresso def progress_bar(percentual, color: '#f97316') perc = [[percentual.to_i, 0].max, 100].min content_tag(:div, class: 'w-full bg-white/10 rounded-full h-2') do content_tag(:div, '', class: 'h-2 rounded-full transition-all duration-500', style: "width: #{perc}%; background-color: #{color}") end end # Opções de role para select def role_options_for_select User.roles.keys.map { |r| [r.humanize, r] } end # Classe base para inputs def input_class 'w-full px-4 py-3 bg-[#0a0a0a] border border-white/10 rounded-xl text-white ' \ 'placeholder-gray-600 focus:outline-none focus:border-[#f97316] focus:ring-1 ' \ 'focus:ring-[#f97316] transition-colors' end end