
    i/                    &   d Z ddlmZ ddl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mZmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZmZ erddlm Z  ddl!m"Z# ddl$m%Z%  eddd          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.
    )annotationsN)
TYPE_CHECKINGAnyClassVarDict	GeneratorListLiteralOptionalTypeVarUnion   )ItemContainedItemCallbackType_ItemCallback)_component_to_item
LayoutView   )ComponentType)get)ColourColor)Self)	Container)DynamicItemSr   T)bound	covariantVr   c                      e Zd ZU dZi Zded<   dZded<   dZddd	dd
dD fdZdEdZ	dFdZ
dG fdZdHdZdIdZd  ZdJd&ZedKd(            ZedLd)            Zej        dMd+            ZeZedNd-            Zed.             ZedOd0            ZdHd1ZdPd3ZdQd5ZedRd9            ZdSd;ZdOd<ZdTd?ZdTd@Z dUdBZ!dVdCZ" xZ#S )Wr   a  Represents a UI container.

    This is a top-level layout component that can only be used on :class:`LayoutView`
    and can contain :class:`ActionRow`\s, :class:`TextDisplay`\s, :class:`Section`\s,
    :class:`MediaGallery`\s, :class:`File`\s, and :class:`Separator`\s in it.

    This can be inherited.


    .. versionadded:: 2.6

    Examples
    --------

    .. code-block:: python3

        import discord
        from discord import ui

        # you can subclass it and add components as you would add them
        # in a LayoutView
        class MyContainer(ui.Container):
            action_row = ui.ActionRow()

            @action_row.button(label='A button in a container!')
            async def a_button(self, interaction: discord.Interaction, button: discord.ui.Button):
                await interaction.response.send_message('You clicked a button!')

        # or use it directly on LayoutView
        class MyView(ui.LayoutView):
            container = ui.Container(ui.TextDisplay('I am a text display on a container!'))
            # or you can use your subclass:
            # container = MyContainer()

    Parameters
    ----------
    \*children: :class:`Item`
        The initial children of this container.
    accent_colour: Optional[Union[:class:`.Colour`, :class:`int`]]
        The colour of the container. Defaults to ``None``.
    accent_color: Optional[Union[:class:`.Colour`, :class:`int`]]
        The color of the container. Defaults to ``None``.
    spoiler: :class:`bool`
        Whether to flag this container as a spoiler. Defaults
        to ``False``.
    id: Optional[:class:`int`]
        The ID of this component. This must be unique across the view.
    zBClassVar[Dict[str, Union[ItemCallbackType[Self, Any], Item[Any]]]]__container_children_items__TzClassVar[bool]__discord_ui_container__accent_colourspoileridNF)r$   accent_colorr%   r&   childrenItem[V]r$   Optional[Union[Colour, int]]r'   Optional[Union[Color, int]]r%   boolr&   Optional[int]returnNonec                   t                                                       |                                 | _        |D ]}|                     |           || _        ||n|| _        || _        d S N)super__init___init_children	_childrenadd_itemr%   _colourr&   )selfr$   r'   r%   r&   r(   child	__class__s          U/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/ui/container.pyr3   zContainer.__init__u   st     	(,(;(;(=(= 	! 	!EMM%    $(5(A}}|    strc                L    d| j         j         dt          | j                   dS )N<z
 children=>)r:   __name__lenr5   r8   s    r;   __repr__zContainer.__repr__   s*    L4>*LLc$.6I6ILLLLr<   List[Item[Any]]c                0   g }i }| j                                         D ]\  }}t          |t                    rG|                                }| |_        t          | ||           |                    |           |||<   a |j        di |j	        }t          || |          |_        t          | |j        |           t          |dd           }|t          |j         d          |                    ||          j                            |           |S )N__discord_ui_parent__z$ is not a valid item for a Container )r!   items
isinstancer   copy_parentsetattrappend__discord_ui_model_type____discord_ui_model_kwargs__r   callbackrA   getattr
ValueErrorr   r5   )r8   r(   parentsnamerawitemparents          r;   r4   zContainer._init_children   s+   :@@BB 	C 	CID##t$$ Cxxzz#dD)))%%%# ;S:]]S=\]] -c4 > >clD111 !&=tDD>$%Z%Z%Z[[[FF++5<<TBBBB r<   c                j   t                                                       i }t          | j                  D ]s}|j                                        D ]W\  }}t          |t                    r|||<   t          |d          r(t          |dd           rt          j
        |          ||<   Xt|| _        d S )NrO   rG   )r2   __init_subclass__reversed__mro____dict__rI   rJ   r   hasattrrR   rK   r!   )clsr(   baserU   memberr:   s        r;   rZ   zContainer.__init_subclass__   s    !!###MOS[)) 	7 	7D $ 3 3 5 5 7 7ffd++ ,%+HTN6#>?? 7GFTkmqDrDr 7%)Yv%6%6HTN	7 ,4(((r<   c                R    || _         | j        D ]}|                    |           dS NT)_viewr5   _update_view)r8   viewr9   s      r;   re   zContainer._update_view   s6    
^ 	% 	%Et$$$$tr<   Container[V]c                    t          j        |           }|j        D ]}|                                 }||_        | j        |_        |                    | j                   |S r1   )rK   deepcopyr5   rL   re   rf   )r8   newr9   newchs       r;   rK   zContainer.copy   s\    mD!!] 	  	 EJJLLEEMMl###
r<   c                    dS rc   rH   rC   s    r;   _has_childrenzContainer._has_children       tr<   r`   r   rj   r   	custom_idc                N    | j                             |          }|| j         |<   d S r1   )r5   index)r8   r`   rj   ro   child_indexs        r;   
_swap_itemzContainer._swap_item   s)    n**400&){###r<   List[Item[V]]c                4    | j                                         S )z4List[:class:`Item`]: The children of this container.)r5   rK   rC   s    r;   r(   zContainer.children   s     ~""$$$r<   c                    | j         S )zaOptional[Union[:class:`discord.Colour`, :class:`int`]]: The colour of the container, or ``None``.)r7   rC   s    r;   r$   zContainer.accent_colour   s     |r<   valuec                    |8t          |t          t          f          st          d|j        j                  || _        d S )Nz expected an int, or Colour, not )rJ   intr   	TypeErrorr:   rA   r7   )r8   rw   s     r;   r$   zContainer.accent_colour   sB    ZV}%E%E[u?W[[\\\r<    Literal[ComponentType.container]c                    t           j        S r1   )r   	containerrC   s    r;   typezContainer.type   s    &&r<   c                    dS )N   rH   rC   s    r;   widthzContainer.width   s    qr<   ry   c                d    dt          t          |                                                     z   S )Nr   )rB   tuplewalk_childrenrC   s    r;   _total_countzContainer._total_count   s+     3uT//11223333r<   c                    dS rc   rH   rC   s    r;   _is_v2zContainer._is_v2   rn   r<   List[Dict[str, Any]]c                l    g }| j         D ])}|                    |                                           *|S r1   )r5   rN   to_component_dict)r8   
componentsis      r;   to_componentszContainer.to_components   sA    
 	5 	5Aa11334444r<   Dict[str, Any]c                    |                                  }d }| j        r-t          | j        t                    r| j        n| j        j        }| j        j        || j        |d}| j        
| j        |d<   |S )N)r~   r'   r%   r   r&   )r   r7   rJ   ry   rw   r~   r%   r&   )r8   r   colourr`   s       r;   r   zContainer.to_component_dict   s~    ''))
< 	[%/c%B%BZT\\HZF IO"|$	
 
 7DJr<   	componentContainerComponentr   c                r     | |j         |j        |j                  fd|j        D             _        S )Nr#   c                0    g | ]}t          |          S rH   )r   ).0cmpr8   s     r;   
<listcomp>z,Container.from_component.<locals>.<listcomp>
  s$    VVVC,S$77VVVr<   )r$   r%   r&   r(   r5   )r_   r   r8   s     @r;   from_componentzContainer.from_component  sP    s#1%|
 
 

 WVVV9CUVVVr<   Generator[Item[V], None, None]c              #     K   | j         D ]4}|V  |                                r|                                E d{V  5dS )zAn iterator that recursively walks through all the children of this container
        and its children, if applicable.

        Yields
        ------
        :class:`Item`
            An item in the container.
        N)r(   rm   r   )r8   r9   s     r;   r   zContainer.walk_children  se       ] 	1 	1EKKK""$$ 1 ..000000000		1 	1r<   c                j    ddl m t          fd|                                 D                       S )zM:class:`int`: Returns the total length of all text content in this container.r   )TextDisplayc              3  `   K   | ](}t          |          t          |j                  V  )d S r1   )rJ   rB   content)r   rW   r   s     r;   	<genexpr>z+Container.content_length.<locals>.<genexpr>!  s>      ggTXZeIfIfg3t|$$ggggggr<   )text_displayr   sumr   )r8   r   s    @r;   content_lengthzContainer.content_length  sD    ------gggg1C1C1E1Eggggggr<   rW   	Item[Any]c                *   t          |t                    st          d|j        j                   | j        r| j                            |j                   | j        	                    |           |
                    | j                   | |_        | S )a  Adds an item to this container.

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

        Parameters
        ----------
        item: :class:`Item`
            The item to append.

        Raises
        ------
        TypeError
            An :class:`Item` was not passed.
        ValueError
            Maximum number of children has been exceeded (40) for the entire view.
        zexpected Item not )rJ   r   rz   r:   rA   rd   
_add_countr   r5   rN   re   rf   rL   r8   rW   s     r;   r6   zContainer.add_item#  s    $ $%% 	LJ1HJJKKK: 	5J!!$"3444d###$)$$$r<   c                    	 | j                             |           | j        r | j                            |j                    n# t
          $ r Y nw xY w| S )a  Removes an item from this container.

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

        Parameters
        ----------
        item: :class:`Item`
            The item to remove from the container.
        )r5   removerd   r   r   rS   r   s     r;   remove_itemzContainer.remove_item@  so    	:N!!$''' z :
%%t'8&8999	  	 	 	D	
 s   A 
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   )r8   r&   s     r;   	find_itemzContainer.find_itemU  s#    $ $,,..26666r<   c                    | j         rG| j                             t          t          |                                                                 | j                                         | S )zRemoves all the items from the container.

        This function returns the class instance to allow for fluent-style
        chaining.
        )rd   r   rB   r   r   r5   clearrC   s    r;   clear_itemszContainer.clear_itemsi  s]     : 	EJ!!3uT-?-?-A-A'B'B#C#C"CDDDr<   )r(   r)   r$   r*   r'   r+   r%   r,   r&   r-   r.   r/   )r.   r=   )r.   rE   )r.   r/   )r.   r,   )r.   rg   )r`   r   rj   r   ro   r=   r.   r/   )r.   rt   )r.   r*   )rw   r*   r.   r/   )r.   r{   )r.   ry   )r.   r   )r.   r   )r   r   r.   r   )r.   r   )rW   r   r.   r   )r&   ry   r.   r   )r.   r   )$rA   
__module____qualname____doc__r!   __annotations__r"   __item_repr_attributes__r3   rD   r4   rZ   re   rK   rm   rs   propertyr(   r$   setterr'   r~   r   r   r   r   r   classmethodr   r   r   r6   r   r   r   __classcell__)r:   s   @r;   r   r   ;   s        / /b hj iiii/33333  7;48        "M M M M   :4 4 4 4 4 4        * * * * % % % X%    X     !L' ' ' X'   X 4 4 4 X4         "    [1 1 1 1 h h h h   :   *7 7 7 7(
 
 
 
 
 
 
 
r<   ))r   
__future__r   rK   typingr   r   r   r   r   r	   r
   r   r   r   rW   r   r   ItemCallbackTyper   rf   r   r   enumsr   utilsr   r   r   r   r   typing_extensionsr   r   r   r   dynamicr   r   r   __all__rH   r<   r;   <module>r      s   0 # " " " " "                         U T T T T T T T T T 0 0 0 0 0 0 0 0 ! ! ! ! ! ! % % % % % % " " " " " " " " %&&&&&&<<<<<<$$$$$$GC{d333GC|t444
x x x x xQ x x x x xr<   