%= form_with model: [:admin, evento], url: (evento.persisted? ? admin_evento_path(evento) : admin_eventos_path),
data: { turbo: false }, class: 'space-y-5' do |f| %>
<% if evento.errors.any? %>
<% evento.errors.full_messages.each do |msg| %><%= msg %> <% end %>
<% end %>
<%= f.label :nome, class: 'block text-gray-400 text-sm mb-1' %>
<%= f.text_field :nome, required: true, placeholder: 'Aviso de fechamento para a diretoria',
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
<%= f.label :gatilho, 'Gatilho (o que faz disparar)', class: 'block text-gray-400 text-sm mb-1' %>
<% if evento.sistema? %>
<%= evento.gatilho_label %>
Evento de sistema: o gatilho e a chave são fixos porque o código dispara por eles.
<% else %>
<%= f.select :gatilho, EventoNotificacao::GATILHOS.map { |g| [EventoNotificacao::GATILHO_LABEL[g], g] }, {},
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
<% end %>
<%= f.label :descricao, 'Descrição', class: 'block text-gray-400 text-sm mb-1' %>
<%= f.text_field :descricao,
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5 focus:outline-none focus:border-orange-500' %>
<%# Só faz sentido no gatilho `agendado`; deixo sempre visível para não
depender de JS, com a explicação de quando vale. %>
Agendamento (só vale no gatilho "Agendado")
<%= f.label :frequencia, 'Frequência', class: 'block text-gray-500 text-xs mb-1' %>
<%= f.select :frequencia, EventoNotificacao::FREQUENCIAS.map { |x| [x.capitalize, x] }, { include_blank: '—' },
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5' %>
<%= f.label :hora, 'Hora', class: 'block text-gray-500 text-xs mb-1' %>
<%= f.number_field :hora, min: 0, max: 23,
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5' %>
<%= f.label :dia_semana, 'Dia (semanal)', class: 'block text-gray-500 text-xs mb-1' %>
<%= f.select :dia_semana, Date::DAYNAMES.each_with_index.map { |nome, i| [nome, i] }, { include_blank: '—' },
class: 'w-full bg-[#1a1a1a] border border-white/10 rounded-xl text-white text-sm px-3 py-2.5' %>
<%= f.check_box :notificar_envolvido, class: 'mt-1 rounded border-white/20 bg-[#1a1a1a] text-orange-500' %>
Avisar também a pessoa envolvida no fato
Ex.: o motorista dono do pagamento, além dos grupos. Só se aplica aos gatilhos de consolidação/pagamento/valor.
<%= f.check_box :ativo, class: 'rounded border-white/20 bg-[#1a1a1a] text-orange-500' %>
Ativo
<%# Assinatura por grupo: TODOS os grupos ativos aparecem, marcados os que já
assinam. Sem isso a tela só mostraria os já configurados e não haveria por
onde adicionar. %>
Quais grupos recebem
<% if @linhas_assinatura.blank? %>
Nenhum grupo cadastrado ainda —
<%= link_to 'crie um grupo', new_admin_grupo_path, data: { turbo: false }, class: 'text-orange-400 underline' %>
antes.
<% end %>
<% Array(@linhas_assinatura).each do |linha| %>
<% grupo = linha[:grupo]; assinatura = linha[:assinatura] %>
<%= check_box_tag "assinaturas[#{grupo.id}][ativo]", '1', assinatura&.ativo,
class: 'rounded border-white/20 bg-[#1a1a1a] text-orange-500' %>
<%= grupo.nome %>
(<%= grupo.contatos.size %>)
<%= select_tag "assinaturas[#{grupo.id}][canal]",
options_for_select(GrupoEventoAssinatura::CANAIS.map { |c| [GrupoEventoAssinatura::CANAL_LABEL[c], c] }, assinatura&.canal || 'ambos'),
class: 'bg-[#141414] border border-white/10 rounded-xl text-white text-sm px-3 py-2' %>
<% end %>
<%= f.submit 'Salvar', class: 'px-4 py-2.5 rounded-xl text-sm font-semibold bg-orange-500 text-black hover:bg-orange-400 cursor-pointer' %>
<%= link_to 'Cancelar', admin_eventos_path, data: { turbo: false }, class: 'text-gray-400 hover:text-white text-sm' %>
<% end %>