
    {h                     b    d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZ  G d de      Zy)	    )ListViewListItem)Binding)Message)Text)AnyCallableOptionalc                        e Zd ZdZ G d de      ZdZ edddd	      gZd
e	e
gef   f fdZddedee
   fdZde
defdZd ZddZdeddfdZ xZS )GenericListz2A generic ListView for displaying a list of items.c                   ,     e Zd ZdZdeddf fdZ xZS )GenericList.ItemSelectedz)Message emitted when an item is selected.selected_itemreturnNc                 0    || _         t        | 	          y N)itemsuper__init__)selfr   	__class__s     f/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/atomic_assembler/widgets/generic_list.pyr   z!GenericList.ItemSelected.__init__   s    %DIG    )__name__
__module____qualname____doc__r   r   __classcell__r   s   @r   ItemSelectedr      s    7	# 	$ 	 	r   r    a   
    GenericList {
        height: 1fr;
        border: solid #AAAA00;
    }

    GenericList > ListItem {
        background: transparent;
    }

    GenericList > ListItem.--highlight {
        color: #000000;
        text-style: bold;
        background: #AAAA00 !important;
    }
    enterselectzSelect ItemT)priorityitem_rendererc                 L    t         |           g | _        || _        d| _        y)zInitialize the GenericList with a custom item renderer.

        Args:
            item_renderer (Callable[[Any], str]): A function that takes an item and returns its string representation.
        r   N)r   r   	item_listr$   highlighted_index)r   r$   r   s     r   r   zGenericList.__init__'   s'     	*!"r   N	new_itemshighlighted_itemc                     || _         | j                          |D ]"  }| j                  | j                  |             $ y)zUpdate the list with new items and optionally highlight one.

        Args:
            new_items (list): The list of items to display.
            highlighted_item (Optional[Any]): An item to highlight, if any.
        N)r&   clearappend_create_item)r   r(   r)   r   s       r   update_listzGenericList.update_list2   s:     #

 	1DKK))$/0	1r   r   r   c                 T     t               }|_        dt        f fd}||_        |S )zCreate a ListItem representing a given item.

        Args:
            item (Any): The item to represent in the list.

        Returns:
            ListItem: The ListItem created for the item.
        r   c                  8    t        j                               S )z1Render the item using the provided item renderer.)r   r$   )r   r   s   r   renderz(GenericList._create_item.<locals>.renderJ   s    **4011r   )r   	item_datar   r1   )r   r   	list_itemr1   s   ``  r   r-   zGenericList._create_item>   s0     J	"		2 	2 "	r   c                 v    | j                   }|r+| j                  | j                  |j                               yy)z5Handle the selection action for the highlighted item.N)highlighted_childpost_messager    r2   )r   r   s     r   action_selectzGenericList.action_selectQ   s4    ..d//0G0GHI r   c                 &    | j                   | _        y r   )r'   index)r   s    r   on_focuszGenericList.on_focusW   s    ++
r   r9   c                 R    || _         | j                          | j                          y r   )r'   blurfocus)r   r9   s     r   set_highlighted_indexz!GenericList.set_highlighted_indexZ   s    !&		

r   r   )r   N)r   r   r   r   r   r    DEFAULT_CSSr   BINDINGSr	   r   strr   listr
   r.   r   r-   r7   r:   intr>   r   r   s   @r   r   r      s    <w K$ 	=4@H	#hucz&: 	#
1T 
1Xc] 
1  &J,3 4 r   r   N)textual.widgetsr   r   textual.bindingr   textual.messager   	rich.textr   typingr   r	   r
   r    r   r   <module>rJ      s%    . # #  * *U( Ur   