
    i                         d Z ddlmZ ddlmZmZmZmZmZm	Z	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 erdd
lmZ ddlmZ ddlmZ ddlmZ  eddd          ZdZ  G d dee                   Z!dS )a:  
The MIT License (MIT)

Copyright (c) 2015-present Rapptz

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotations)
TYPE_CHECKINGAnyDict	GeneratorListLiteralOptionalTypeVarUnionClassVar   )ItemTextDisplay   )ComponentType)get)Self)
LayoutView)DynamicItem)SectionComponentVr   T)bound	covariant)Sectionc                  X    e Zd ZU dZdZdZded<   dZddd; fdZd<dZ	e
d=d            Ze
d>d            Ze
d             Ze
d?d            Ze
d@d            Zej        dAd            ZdBdZdCd%ZdDd'ZdEd(Zd) Zd?d*ZdFd.ZdGd0ZdHd2ZdId3ZedJd6            ZdKd8ZdLd:Z xZS )Mr   a  Represents a UI section.

    This is a top-level layout component that can only be used on :class:`LayoutView`.

    .. versionadded:: 2.6

    Parameters
    ----------
    \*children: Union[:class:`str`, :class:`TextDisplay`]
        The text displays of this section. Up to 3.
    accessory: :class:`Item`
        The section accessory. This is usually either a :class:`Button` or :class:`Thumbnail`.
    id: Optional[:class:`int`]
        The ID of this component. This must be unique across the view.
    )	accessoryidTzClassVar[bool]__discord_ui_section__)	_children
_accessoryNr   childrenUnion[Item[V], str]r   Item[V]r   Optional[int]returnNonec                   t                                                       g | _        |D ]}|                     |           | |_        || _        || _        d S N)super__init__r!   add_item_parentr"   r   )selfr   r   r$   child	__class__s        S/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/ui/section.pyr-   zSection.__init__J   s`     	(* 	! 	!EMM%     	#,    strc                \    d| j         j         dt          | j                   d| j        dS )N<z
 children=z accessory=>)r2   __name__lenr!   r"   r0   s    r3   __repr__zSection.__repr__Y   s6    j4>*jjc$.6I6IjjVZVejjjjr4   Literal[ComponentType.section]c                    t           j        S r+   )r   sectionr;   s    r3   typezSection.type\   s    $$r4   List[Item[V]]c                4    | j                                         S )zCList[:class:`Item`]: The list of children attached to this section.)r!   copyr;   s    r3   r$   zSection.children`   s     ~""$$$r4   c                    dS )N    r;   s    r3   widthzSection.widthe   s    qr4   intc                0    dt          | j                  z   S )Nr   )r:   r!   r;   s    r3   _total_countzSection._total_counti   s     3t~&&&&r4   c                    | j         S )z':class:`Item`: The section's accessory.)r"   r;   s    r3   r   zSection.accessoryn   s     r4   valuec                    t          |t                    st          d|j        j        d          |                    | j                   | |_        || _        d S )NzExpected an Item, got z instead)	
isinstancer   	TypeErrorr2   r9   _update_viewviewr/   r"   )r0   rL   s     r3   r   zSection.accessorys   s\    %&& 	[YU_5MYYYZZZ49%%%r4   boolc                    dS NTrF   r;   s    r3   _is_v2zSection._is_v2|       tr4   baser   newr   	custom_idc                    | j                                         r#t          | j         dd           |k    r|| _         d S d S d S )NrY   )r   is_dispatchablegetattr)r0   rW   rX   rY   s       r3   
_swap_itemzSection._swap_item   sM    >))++ 	!UY0Z0Z^g0g0g DNNN	! 	!0g0gr4   Generator[Item[V], None, None]c              #  6   K   | j         E d{V  | j        V  dS )zAn iterator that recursively walks through all the children of this section
        and its children, if applicable. This includes the `accessory`.

        Yields
        ------
        :class:`Item`
            An item in this section.
        N)r$   r   r;   s    r3   walk_childrenzSection.walk_children   s6       =       nr4   c                N    || _         || j        _         | j        D ]	}||_         
d S r+   )_viewr   r!   )r0   rQ   r1   s      r3   rP   zSection._update_view   s7    
#^ 	 	EEKK	 	r4   c                    dS rT   rF   r;   s    r3   _has_childrenzSection._has_children   rV   r4   c                P    ddl m t          fd| j        D                       S )zK:class:`int`: Returns the total length of all text content in this section.r   r   c              3  `   K   | ](}t          |          t          |j                  V  )d S r+   )rN   r:   content).0itemr   s     r3   	<genexpr>z)Section.content_length.<locals>.<genexpr>   s=      aa:dT_C`C`a3t|$$aaaaaar4   )text_displayr   sumr!   )r0   r   s    @r3   content_lengthzSection.content_length   s:    ------aaaaaaaaaar4   ri   Union[str, Item[Any]]r   c                   t          | j                  dk    rt          d          t          |t          t
          f          st          d|j        j                   | j	        r| j	        
                    d           t          |t                    r|nt          |          }|                    | j                   | |_        | j                            |           | S )a7  Adds an item to this section.

        This function returns the class instance to allow for fluent-style
        chaining.

        Parameters
        ----------
        item: Union[:class:`str`, :class:`Item`]
            The item to append, if it is a string it automatically wrapped around
            :class:`TextDisplay`.

        Raises
        ------
        TypeError
            An :class:`Item` or :class:`str` was not passed.
        ValueError
            Maximum number of children has been exceeded (3) or (40)
            for the entire view.
           z'maximum number of children exceeded (3)zexpected Item or str not r   )r:   r!   
ValueErrorrN   r   r5   rO   r2   r9   rb   
_add_countr   rP   rQ   r/   appendr0   ri   s     r3   r.   zSection.add_item   s    * t~!##FGGG$s,, 	SQ8OQQRRR: 	%J!!!$$$!$--Dtt;t3D3D$)$$$d###r4   	Item[Any]c                    	 | j                             |           | j        r| j                            d           n# t          $ r Y nw xY w| S )zRemoves an item from this section.

        This function returns the class instance to allow for fluent-style
        chaining.

        Parameters
        ----------
        item: :class:`Item`
            The item to remove from the section.
        )r!   removerb   rr   rq   rt   s     r3   remove_itemzSection.remove_item   si    	*N!!$''' z *
%%b)))	  	 	 	D	 s   > 
A
AOptional[Item[V]]c               H    t          |                                 |          S )ax  Gets an item with :attr:`Item.id` set as ``id``, or ``None`` if
        not found.

        .. warning::

            This is **not the same** as ``custom_id``.

        Parameters
        ----------
        id: :class:`int`
            The ID of the component.

        Returns
        -------
        Optional[:class:`Item`]
            The item found, or ``None``.
        r#   )
_utils_getr`   )r0   r   s     r3   	find_itemzSection.find_item   s#    $ $,,..26666r4   c                    | j         r-| j                             t          | j                              | j                                         | S )zRemoves all the items from the section.

        This function returns the class instance to allow for fluent-style
        chaining.
        )rb   rr   r:   r!   clearr;   s    r3   clear_itemszSection.clear_items   sJ     : 	8J!!3t~#6#6"6777r4   	componentr   c                    ddl m  |j        d           } | |j        |          |j        _        fd|j        D             _        S )Nr   )_component_to_item)r   r   c                (    g | ]} |          S rF   rF   )rh   cr   r0   s     r3   
<listcomp>z*Section.from_component.<locals>.<listcomp>  s'    RRR!,,Q55RRRr4   )rQ   r   r   r   r$   r!   )clsr   r   r   r0   s      @@r3   from_componentzSection.from_component   sp    ,,,,,,&&y':DAA	sili888,RRRRRy?QRRRr4   List[Dict[str, Any]]c                l    g }| j         D ])}|                    |                                           *|S r+   )r!   rs   to_component_dict)r0   
componentsr   s      r3   to_componentszSection.to_components  sA    
 	= 	=Ii99;;<<<<r4   Dict[str, Any]c                    | j         j        |                                 | j                                        d}| j        
| j        |d<   |S )N)r@   r   r   r   )r@   rL   r   r   r   r   )r0   datas     r3   r   zSection.to_component_dict  sO    IO,,..99;;
 

 7DJr4   )r$   r%   r   r&   r   r'   r(   r)   )r(   r5   )r(   r=   )r(   rA   )r(   rH   )r(   r&   )rL   r&   r(   r)   )r(   rR   )rW   r   rX   r   rY   r5   r(   r)   )r(   r^   )r(   r)   )ri   rn   r(   r   )ri   ru   r(   r   )r   rH   r(   rz   )r(   r   )r   r   r(   r   )r(   r   )r(   r   ) r9   
__module____qualname____doc____item_repr_attributes__r    __annotations__	__slots__r-   r<   propertyr@   r$   rG   rJ   r   setterrU   r]   r`   rP   rd   rm   r.   ry   r}   r   classmethodr   r   r   __classcell__)r2   s   @r3   r   r   .   sb            .21111I !	       k k k k % % % X% % % % X%   X ' ' ' X'    X           ! ! ! !        b b b b# # # #J   ,7 7 7 7(
 
 
 
    [          r4   r   N)"r   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   ri   r   rk   r   enumsr   utilsr   r|   typing_extensionsr   rQ   r   dynamicr   r   r   r   __all__r   rF   r4   r3   <module>r      s`   0 # " " " " " i i i i i i i i i i i i i i i i i i i i i i i i       % % % % % % ! ! ! ! ! ! % % % % % % .&&&&&&      $$$$$$------GC|t444
f f f f fd1g f f f f fr4   