
    ^i4                          d Z ddlmZ ddlmZmZmZ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 dd	lmZmZmZmZmZ  G d
 de      Zy)zhContains the base class :class:`.BaseListPrompt` which can be used to create a prompt involving choices.    )abstractmethod)AnyCallableListOptional)	Condition)Keys)BaseComplexPrompt)InquirerPyUIListControl)	Separator)InquirerPyKeybindingsInquirerPyMessageInquirerPySessionResultInquirerPyStyleInquirerPyValidatec            +           e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#dedee   dedededed	ed
edee	e
ge
f      dee	e
ge
f      dee   dededee   dedededededee   ddf* fdZedefd       Zej$                  deddfd       Zede
fd       Zede
fd       Zedee
   fd       ZdefdZdefd Zed$d!       Zededdfd"       Z xZS )%BaseListPrompta  A base class to create a complex prompt involving choice selections (i.e. list) using `prompt_toolkit` Application.

    Note:
        This class does not create :class:`~prompt_toolkit.layout.Layout` nor :class:`~prompt_toolkit.application.Application`,
        it only contains the necessary attributes and helper functions to be consumed.

    See Also:
        :class:`~InquirerPy.prompts.list.ListPrompt`
        :class:`~InquirerPy.prompts.fuzzy.FuzzyPrompt`
    Nmessagestylevi_modeqmarkamarkinstructionlong_instructionbordertransformerfiltervalidateinvalid_messagemultiselectkeybindingscycle
wrap_linesraise_keyboard_interrupt	mandatorymandatory_messagesession_resultreturnc                     t            |||||||	|
|||||||||         | _        t         fd       _        | _        |si }ddid j                   dd j                  dgddid	 j                   dd
 j                  dgddigdt        j                  igdt        j                  igddiddigddiddigg d| _
        d j                  igd j                  igd j                  igd j                  id j                  igd j                  id j                  igd j                  ig j                  dgdg j                  dgdgd _        y )N)r   r   r   r   r   r   r   r   r   r   r   r   r#   r$   r%   r&   r'   c                       j                   S N)_multiselectselfs   ^/mnt/e/genesis-system/.venvs/browser-army/lib/python3.12/site-packages/InquirerPy/base/list.py<lambda>z)BaseListPrompt.__init__.<locals>.<lambda>M   s    1B1B     keydownzc-n)r2   r   jupzc-pkspacezalt-rzc-rzalt-azc-a)r3   r5   toggleztoggle-downz	toggle-upz
toggle-allztoggle-all-trueztoggle-all-falsefuncT)r9   argsF)super__init__r,   r   _is_multiselect_cycle_is_vim_editr	   TabBackTabkb_maps_handle_down
_handle_up_handle_toggle_choice_handle_toggle_allkb_func_lookup)r.   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   	__class__s   `                    r/   r<   zBaseListPrompt.__init__    s    . 	#+#-!%=/)# 	 	
( 	'()BCK $*;*;);<t'8'89 $*;*;);<t'8'89   ! %  
    !#9
: ;
B d//01DOO,- : :;<334**+
 334) #D$;$;<=)-)@)@4& QR*.*A*AE7!S T
r1   c                 >    | j                   st        | j                   S )aa  Get the content controller object.

        Needs to be an instance of :class:`~InquirerPy.base.control.InquirerPyUIListControl`.

        Each :class:`.BaseComplexPrompt` requires a `content_control` to display custom
        contents for the prompt.

        Raises:
            NotImplementedError: When `self._content_control` is not found.
        )_content_controlNotImplementedErrorr-   s    r/   content_controlzBaseListPrompt.content_control   s     $$%%$$$r1   valuec                     || _         y r+   )rJ   )r.   rM   s     r/   rL   zBaseListPrompt.content_control   s
     %r1   c                     | j                   r| j                  D cg c]  }|d   	 c}S 	 | j                  j                  d   S c c}w # t        $ r Y yw xY w)zGet the result value that should be printed to the terminal.

        In multiselect scenario, return result as a list.
        name r,   selected_choicesrL   	selection
IndexErrorr.   choices     r/   result_namezBaseListPrompt.result_name   s^     151F1FGvF6NGG++55f== H     AA	 		AAc                     | j                   r| j                  D cg c]  }|d   	 c}S 	 | j                  j                  d   S c c}w # t        $ r Y yw xY w)zxGet the result value that should return to the user.

        In multiselect scenario, return result as a list.
        rM   rQ   rR   rV   s     r/   result_valuezBaseListPrompt.result_value   s^     262G2GHF7OHH++55g>> I  rY   c                 Z    d }t        t        || j                  j                              S )z)List[Any]: Get all user selected choices.c                 2    t        | t               xr | d   S )Nenabled)
isinstancer   )rW   s    r/   filter_choicez6BaseListPrompt.selected_choices.<locals>.filter_choice   s    !&)44J	9JJr1   )listr   rL   choices)r.   r`   s     r/   rS   zBaseListPrompt.selected_choices   s(    	K F=$*>*>*F*FGHHr1   c                    | j                   r@| j                  j                  dz   | j                  j                  z  | j                  _        y| j                  xj                  dz  c_        | j                  j                  | j                  j                  k\  r)| j                  j                  dz
  | j                  _        yy)zHandle event when user attempts to move down.

        Returns:
            Boolean indicating if the action hits the cap.
           FTr>   rL   selected_choice_indexchoice_countr.   _s     r/   rC   zBaseListPrompt._handle_down   s     ;;$$::Q>$$11:2D  6   66!;6$$::''445 ((559 $$: r1   c                 0   | j                   r@| j                  j                  dz
  | j                  j                  z  | j                  _        y| j                  xj                  dz  c_        | j                  j                  dk  rd| j                  _        yy)zHandle event when user attempts to move up.

        Returns:
            Boolean indicating if the action hits the cap.
        rd   Fr   Tre   rh   s     r/   rD   zBaseListPrompt._handle_up   s     ;;$$::Q>$$11:2D  6   66!;6##99A==>$$:r1   c                      y)zDHandle event when user attempting to toggle the state of the chocie.N )r.   events     r/   rE   z$BaseListPrompt._handle_toggle_choice        	r1   c                      y)zDHandle event when user attempting to alter the state of all choices.Nrl   )r.   rm   rM   s      r/   rF   z!BaseListPrompt._handle_toggle_all   rn   r1   )NF?rp   rQ   rQ   FNNNzInvalid inputFNTTTTzMandatory promptN)r(   N)__name__
__module____qualname____doc__r   r   r   boolstrr   r   r   r   r   r<   propertyr   rL   setterrX   r[   r   rS   rC   rD   r   rE   rF   __classcell__)rH   s   @r/   r   r      sQ   	 ,0 "6:1515.!7;)-!3<@+b
"b
 (b
 	b

 b
 b
 b
 b
 b
 hucz23b
 3%*-.b
 -.b
 b
 b
 34b
  !b
" #b
$ #'%b
& 'b
( )b
* !!89+b
, 
-b
H %!8 % % &%< & & & S   c   I$s) I I .t $   t   r1   r   N)rt   abcr   typingr   r   r   r   prompt_toolkit.filters.baser   prompt_toolkit.keysr	   InquirerPy.base.complexr
   InquirerPy.base.controlr   InquirerPy.separatorr   InquirerPy.utilsr   r   r   r   r   r   rl   r1   r/   <module>r      s9    n  0 0 1 $ 5 ; * Z& Zr1   