
# Add these breakpoints to key locations for debugging

# 1. In filtered_flow_view.py - refresh_frame_types method
def refresh_frame_types(self):
    """Update frame type button counts and reorder by count (highest to left)"""
    import pdb; pdb.set_trace()  # BREAKPOINT: Start of refresh
    
    # Throttle button refresh to prevent race conditions
    import time
    current_time = time.time()
    if current_time - self._last_refresh_time < self._refresh_throttle_seconds:
        print(f"🚫 Refresh throttled (last: {self._last_refresh_time}, current: {current_time})")
        return  # Skip refresh if called too recently
    
    print(f"🔄 Starting refresh_frame_types at {current_time}")
    self._last_refresh_time = current_time
    
    # Get all detected frame types with their total packet counts
    frame_types = self._get_all_frame_types()
    print(f"📊 Frame types found: {frame_types}")
    
    # If no frame types yet, skip button update
    if not frame_types:
        print("⚠️  No frame types, skipping button update")
        return
    
    # BREAKPOINT: Before button removal/creation
    import pdb; pdb.set_trace()
    
    # Rest of method...

# 2. In filtered_flow_view.py - compose method  
def compose(self):
    """Create the filter bar and flow grid"""
    import pdb; pdb.set_trace()  # BREAKPOINT: Widget creation
    
    # Filter button bar at top
    with Horizontal(id="filter-bar"):
        # Overview button (hotkey 1) - compact format
        overview_btn = Button("1.Overview", id="btn-overview", classes="-active")
        self.frame_type_buttons["Overview"] = overview_btn
        print(f"✅ Created overview button: {overview_btn}")
        yield overview_btn
        
        # Create predefined frame type buttons at initialization
        hotkeys = ['2', '3', '4', '5', '6', '7', '8', '9', '0']
        for i, frame_type in enumerate(self.predefined_frame_types):
            if i < len(hotkeys):
                # Start with 0 count - will be updated during data refresh
                btn = FrameTypeButton(frame_type, hotkeys[i], 0)
                self.frame_type_buttons[frame_type] = btn
                print(f"✅ Created predefined button {i+1}: {btn} for {frame_type}")
                yield btn
    
    # BREAKPOINT: After all buttons created
    import pdb; pdb.set_trace()

# 3. Strategic print statements for tracking
def debug_button_lifecycle():
    """Add this to track button lifecycle"""
    
    def log_button_state(self, phase):
        print(f"\n🔍 BUTTON STATE - {phase}:")
        print(f"   Buttons dict: {len(self.frame_type_buttons)} entries")
        for name, btn in self.frame_type_buttons.items():
            if hasattr(btn, 'parent'):
                parent_status = "has parent" if btn.parent else "NO PARENT"
            else:
                parent_status = "no parent attr"
            print(f"     {name}: {btn} ({parent_status})")
