// js/components/widgets/VendaTimelineEvents.jsx
// [Wave 15 v223.40 20260520] Extraído de VendaTimeline.jsx L323-345
// Lista de eventos timeline (cronológica desc) com icon + title + sub + data
//
// Props: timeline (array de {type, icon, color, date, title, sub})
// Deps runtime: window.fmtDateTime (fallback ISO slice)
(function(){
  'use strict';

  function VendaTimelineEvents(props){
    const timeline = props.timeline || [];
    const fmtDateBr = function(iso){
      if (!iso) return '—';
      return typeof window.fmtDateTime === 'function' ? window.fmtDateTime(iso) : String(iso).slice(0, 16);
    };

    return (
      <div className="card">
        <div style={{fontSize:13,fontWeight:700,color:'#9CA3AF',marginBottom:12,textTransform:'uppercase',letterSpacing:1}}>
          📅 Timeline ({timeline.length})
        </div>
        {timeline.length === 0 ? (
          <div style={{color:'#6B7280',fontSize:13,padding:20,textAlign:'center'}}>
            Sem eventos registrados ainda.
          </div>
        ) : (
          <div style={{maxHeight:540,overflowY:'auto',paddingRight:4}}>
            {timeline.map(function(e, i){
              return (
                <div key={i} style={{display:'flex',gap:12,padding:'10px 0',borderBottom:i<timeline.length-1?'1px solid #F3F4F6':'none'}}>
                  <div style={{fontSize:18,minWidth:24}}>{e.icon}</div>
                  <div style={{flex:1,minWidth:0}}>
                    <div style={{fontSize:13,fontWeight:600,color:e.color}}>{e.title}</div>
                    {e.sub && <div style={{fontSize:11,color:'#6B7280',marginTop:2}}>{e.sub}</div>}
                  </div>
                  <div style={{fontSize:10,color:'#9CA3AF',whiteSpace:'nowrap'}}>{fmtDateBr(e.date)}</div>
                </div>
              );
            })}
          </div>
        )}
      </div>
    );
  }

  window.ZNX = window.ZNX || {};
  window.ZNX.components = window.ZNX.components || {};
  window.ZNX.components.VendaTimelineEvents = VendaTimelineEvents;
  window.VendaTimelineEvents = VendaTimelineEvents;
})();
