
    {hB	                     f    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ  G d de      Zy	)
    )List)reactive)Widget)Message)Binding)PRIMARY_COLOR
MenuOptionc                        e Zd ZdZ G d de      Z ed      Z edddd	       ed
dd       eddd      gZ	de
e   f fdZddZdefdZddZddZddZdeddfdZ xZS )
MenuWidgetz)A widget that displays a selectable menu.c                   (     e Zd ZdZdef fdZ xZS )MenuWidget.ItemSelectedz!Emitted when an item is selected.indexc                 0    || _         t        | 	          y )N)r   super__init__)selfr   	__class__s     ^/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/atomic_assembler/widgets/menu.pyr   z MenuWidget.ItemSelected.__init__   s    DJG    )__name__
__module____qualname____doc__intr   __classcell__r   s   @r   ItemSelectedr      s    /	# 	 	r   r   r   enterselectzSelect itemT)priorityupmove_upzMove updown	move_downz	Move down
menu_itemsc                 >    t         |           || _        d| _        y)z
        Initialize the MenuWidget.

        Args:
            menu_items (List[MenuOption]): A list of MenuOption instances representing menu options.
        TN)r   r   _menu_items	can_focus)r   r%   r   s     r   r   zMenuWidget.__init__   s     	%r   returnNc                 $    | j                          y)z&Set focus to this widget when mounted.N)focusr   s    r   on_mountzMenuWidget.on_mount&   s    

r   c                 
   g }t        | j                        D ]Y  \  }}|| j                  k(  }|rdt         d|j                   dt         dnd|j                   d}|j                  d| d       [ dj                  |      S )	z
        Render the menu items with the current selection highlighted.

        Returns:
            str: The rendered menu items as a string.
        [z bold][ z ][/z bold]z  z[center]z	[/center]
)	enumerater'   _selected_indexr   labelappendjoin)r   rendered_menu_itemsr   itemis_selected	menu_texts         r   renderzMenuWidget.render*   s     !$T%5%56 	HKE44#7#77KT_!M?(4::,d=/Pgijnjtjtiuuwex   &&)I'FG	H yy,--r   c                 &    | j                  d       y)zMove the selection up.N_move_selectionr,   s    r   action_move_upzMenuWidget.action_move_up;   s    R r   c                 &    | j                  d       y)zMove the selection down.   Nr=   r,   s    r   action_move_downzMenuWidget.action_move_down?   s    Qr   c                 X    | j                  | j                  | j                               y)z$Handle the selection of a menu item.N)post_messager   r2   r,   s    r   action_selectzMenuWidget.action_selectC   s!    $++D,@,@ABr   	directionc                 X    | j                   |z   t        | j                        z  | _         y)z<Move the selection up or down, wrapping around if necessary.N)r2   lenr'   )r   rF   s     r   r>   zMenuWidget._move_selectionG   s%     $ 4 4y @CHXHXDYYr   )r)   N)r   r   r   r   r   r   r   r2   r   BINDINGSr   r	   r   r-   strr:   r?   rB   rE   r   r>   r   r   s   @r   r   r   	   s    3w  qkO 	=4@i+[1H	4
#3 	. ."! CZ Z Zr   r   N)typingr   textual.reactiver   textual.widgetr   textual.messager   textual.bindingr   atomic_assembler.constantsr   r	   r    r   r   <module>rR      s'     % ! # # @@Z @Zr   