
    ^i                          d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZmZ ddlmZ ddlmZmZ d	d
gZe G d d	             Z G d d
e      Zy)zEContains the content control class :class:`.InquirerPyUIListControl`.    )abstractmethod)asdict	dataclass)AnyCallableDictListOptionalTuplecast)FormattedTextControl)InvalidArgumentRequiredKeyNotFound)	Separator)InquirerPyListChoicesInquirerPySessionResultChoiceInquirerPyUIListControlc                   D    e Zd ZU dZeed<   dZee   ed<   dZ	e
ed<   d Zy)r   aR  Class to create choices for list type prompts.

    A simple dataclass that can be used as an alternate to using :class:`dict`
    when working with choices.

    Args:
        value: The value of the choice when user selects this choice.
        name: The value that should be presented to the user prior/after selection of the choice.
            This value is optional, if not provided, it will fallback to the string representation of `value`.
        enabled: Indicates if the choice should be pre-selected.
            This only has effects when the prompt has `multiselect` enabled.
    valueNnameFenabledc                 R    | j                   t        | j                        | _         yy)z-Assign strinify value to name if not present.N)r   strr   selfs    a/mnt/e/genesis-system/.venvs/browser-army/lib/python3.12/site-packages/InquirerPy/base/control.py__post_init__zChoice.__post_init__"   s     99DJJDI     )__name__
__module____qualname____doc__r   __annotations__r   r
   r   r   boolr    r   r   r   r      s+     JD(3-GT(r   c                   
    e Zd ZdZ	 	 	 ddedededee   ddf
 fdZ	de
e   dede
eeef      fd	Zedefd
       Zej"                  deddfd       Zede
eeef      fd       Zej"                  de
eeef      ddfd       ZddZde
eeef      fdZddZede
eeef      fd       Zede
eeef      fd       Zedefd       Zedeeef   fd       Zedefd       Zej"                  deddfd       Z xZS )r   a  A base class to create :class:`~prompt_toolkit.layout.UIControl` to display list type contents.

    Args:
        choices(InquirerPyListChoices): List of choices to display as the content.
            Can also be a callable or async callable that returns a list of choices.
        default: Default value, this will affect the cursor position.
        multiselect: Indicate if the current prompt has `multiselect` enabled.
        session_result: Current session result.
    Nchoicesdefaultmultiselectsession_resultreturnc                    |xs i | _         d| _        d | _        || _        t	        |t
              s|n t        t
        |      | j                         | _        t	        |t
              s|n t        t
        |      | j                         | _        | j                  | j                  | j                        | _
        | j                          | j                          t        | 9  | j                         y )Nr   )_session_result_selected_choice_index_choice_func_multiselect
isinstancer   r   _default_raw_choices_get_choices_choices_safety_check_format_choicessuper__init___get_formatted_choices)r   r(   r)   r*   r+   	__class__s        r   r:   z InquirerPyUIListControl.__init__3   s      .3+,# ' gx0 (h()=)=> 	 gx0 (h()=)=> 	
 ))$*;*;T]]K445r   c           	         g }	 t        |d      D ]>  \  }}t        |t              rR|d   |k(  r|| _        |j	                  t        |d         |d   | j                  r|j                  dd      ndd       it        |t              rN| j                  |k(  r | j                  dz   t        |      z  | _        |j	                  t        |      |dd       t        |t              r>t        |      }|d   |k(  r|| _        | j                  sd|d<   |j	                  |       ||k(  r|| _        |j	                  t        |      |dd       A 	 |S # t        $ r t        d	      w xY w)
a  Process the raw user input choices and format it into dictionary.

        Args:
            choices: List of chices to display.
            default: Default value, this will affect the :attr:`.InquirerPyUIListControl.selected_choice_index`

        Returns:
            List of choices.

        Raises:
            RequiredKeyNotFound: When the provided choice is missing the `name` or `value` key.
        r   )startr   r   r   F)r   r   r      z@dictionary type of choice require a 'name' key and a 'value' key)	enumerater2   dictselected_choice_indexappendr   r1   getr   lenr   r   KeyErrorr   )r   r(   r)   processed_choicesindexchoicedict_choices          r   r5   z$InquirerPyUIListControl._get_choicesM   s    35&	!*7!!< !vfd+g'15:2%,,$'v$7%+G_#00 (.zz)U'C!&  	211U: 66:L6)2 &,,!$Vv%P  /"(.K"7+w65:2,,16I.%,,[9(5:2%,,!$Vv%P?!L ! 	  	%R 	s   EE E+c                     | j                   S )zint: Current highlighted index.r/   r   s    r   rB   z-InquirerPyUIListControl.selected_choice_index   s     ***r   r   c                     || _         y NrL   r   r   s     r   rB   z-InquirerPyUIListControl.selected_choice_index   s
    &+#r   c                     | j                   S )z0List[Dict[str, Any]]: Get all processed choices.r6   r   s    r   r(   zInquirerPyUIListControl.choices        }}r   c                     || _         y rN   rQ   rO   s     r   r(   zInquirerPyUIListControl.choices   	    r   c                     | j                   st        d      d}| j                   D ]  }t        |d   t              rd} n |st        d      y)zValidate processed choices.

        Check if the choices are empty or if it only contains :class:`~InquirerPy.separator.Separator`.
        z argument choices cannot be emptyFr   Tz<argument choices should contain choices other than separatorN)r(   r   r2   r   )r   should_proceedrI   s      r   r7   z%InquirerPyUIListControl._safety_check   s_    
 ||!"DEE$ll 	FfWoy9!%	 !N  r   c                     g }t        | j                        D ]N  \  }}|| j                  k(  r|| j                  |      z  }n|| j	                  |      z  }|j                  d       P |r|j                          |S )zxGet all choices in formatted text format.

        Returns:
            List of choices in formatted text form.
        ) 
)r@   r(   rB   _get_hover_text_get_normal_textrC   pop)r   display_choicesrH   rI   s       r   r;   z.InquirerPyUIListControl._get_formatted_choices   s     &t||4 	/ME62224#7#7#??4#8#8#@@"":.	/ !r   c                      y)zPerform post processing on the choices.

        Additional customisation to the choices after :meth:`.InquirerPyUIListControl._get_choices` call.
        Nr&   r   s    r   r8   z'InquirerPyUIListControl._format_choices   s    
 	r   c                      y)z~Generate the formatted text for hovered choice.

        Returns:
            Formatted text in list of tuple format.
        Nr&   r   rI   s     r   rZ   z'InquirerPyUIListControl._get_hover_text        	r   c                      y)zGenerate the formatted text for non-hovered choices.

        Returns:
            Formatted text in list of tuple format.
        Nr&   r`   s     r   r[   z(InquirerPyUIListControl._get_normal_text   ra   r   c                 ,    t        | j                        S )zint: Total count of choices.)rE   r(   r   s    r   choice_countz$InquirerPyUIListControl.choice_count   s     4<<  r   c                 4    | j                   | j                     S )z(Dict[str, Any]: Current selected choice.)r(   rB   r   s    r   	selectionz!InquirerPyUIListControl.selection   s     ||D6677r   c                     | j                   S )z1bool: Indicate if the content control is loading._loadingr   s    r   loadingzInquirerPyUIListControl.loading   rR   r   c                     || _         y rN   rh   rO   s     r   rj   zInquirerPyUIListControl.loading   rT   r   )NFN)r,   N)r    r!   r"   r#   r   r   r%   r
   r   r:   r	   r   r   r5   propertyintrB   setterr(   r7   r   r;   r8   r   rZ   r[   rd   rf   rj   __classcell__)r<   s   @r   r   r   (   s
    !<@6&6 6 	6
 !!896 
645!DI 5! 5!T#s(^@T 5!n +s + + !!,3 ,4 , ", d38n-   ^^T$sCx.1 d  "U38_(= $ eCHo)>   $uS#X*?   !c ! ! 84S> 8 8    ^^T d  r   N)r#   abcr   dataclassesr   r   typingr   r   r   r	   r
   r   r   prompt_toolkit.layout.controlsr   InquirerPy.exceptionsr   r   InquirerPy.separatorr   InquirerPy.utilsr   r   __all__r   r   r&   r   r   <module>rx      sV    K  ) C C C ? F * K.
/ ( ( (0{2 {r   