import streamlit as st from api_client import APIClient STATUS_CONFIG = [ ('novo', 'Novo', '#58A6FF'), ('contatado', 'Contatado', '#D29922'), ('respondeu', 'Respondeu', '#A371F7'), ('negociacao', 'Em Negociação', '#F0883E'), ('ganho', 'Ganho', '#3FB950'), ('perdido', 'Perdido', '#F85149') ] def render_kanban_board(leads: list, api_client: APIClient): cols = st.columns(len(STATUS_CONFIG)) # Agrupar leads por status leads_by_status = {key: [] for key, _, _ in STATUS_CONFIG} for l in leads: st_key = l.get('status_funil', 'novo') if st_key in leads_by_status: leads_by_status[st_key].append(l) for idx, (status_key, status_label, color) in enumerate(STATUS_CONFIG): with cols[idx]: col_leads = leads_by_status[status_key] st.markdown( f"""
{status_label} {len(col_leads)}
""", unsafe_allow_html=True ) for lead in col_leads: lead_id = lead['id'] nome = lead.get('nome_empresa', 'Empresa') ramo = lead.get('ramo_atividade', '') tel = lead.get('telefone', '') tel_san = lead.get('telefone_sanitizado', '') rating = lead.get('google_rating', 0.0) reviews = lead.get('total_avaliacoes', 0) maps_url = lead.get('google_maps_url', '') rating_str = f"⭐ {rating:.1f} ({reviews})" if rating > 0 else "Sem avaliação" # Container visual do Card with st.container(border=True): st.markdown(f"**{nome}**") st.caption(f"🏷️ {ramo} | 📍 {lead.get('bairro', '') or lead.get('cidade', '')}") st.caption(f"📊 {rating_str}") if tel_san: st.markdown( f'💬 WhatsApp ({tel})', unsafe_allow_html=True ) elif tel: st.caption(f"📞 {tel}") if maps_url: st.markdown(f"[📍 Abrir no Google Maps]({maps_url})") c1, c2 = st.columns([2, 1]) with c1: opts = [s[1] for s in STATUS_CONFIG] cur_idx = [s[0] for s in STATUS_CONFIG].index(status_key) new_label = st.selectbox( "Mover para:", opts, index=cur_idx, key=f"st_sel_{lead_id}", label_visibility="collapsed" ) new_st_key = [s[0] for s in STATUS_CONFIG][opts.index(new_label)] if new_st_key != status_key: api_client.update_lead(lead_id, {'status_funil': new_st_key}) st.rerun() with c2: if st.button("📝", key=f"btn_notes_{lead_id}", help="Editar notas e ver histórico"): st.session_state['selected_lead_id'] = lead_id st.rerun()