a
    bg                     @  s   d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 erTd dlmZ d dlmZ G dd deZG dd	 d	e	ZG d
d dZdS )    )annotations)Enum)TYPE_CHECKINGAnyDictList
NamedTupleOptional)DeltaGenerator)SupportsStrc                   @  s   e Zd ZdZdZdZdS )	ChildTypezEnumerator of the child type.MARKDOWN	EXCEPTIONN)__name__
__module____qualname____doc__r   r    r   r   /var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/callbacks/streamlit/mutable_expander.pyr      s   r   c                   @  s*   e Zd ZU dZded< ded< ded< dS )	ChildRecordzChild record as a NamedTuple.r   typeDict[str, Any]kwargsr
   dgN)r   r   r   r   __annotations__r   r   r   r   r      s   
r   c                   @  s   e Zd ZdZddddddZeddd	d
ZeddddZddddZd ddddZ	dddddddddZ
d3dddddddddd d!Zdd"d#ddd$d%d&Zd'd(dd)d*d+Zd,ddd-d.d/Zddd0d1d2ZdS )4MutableExpanderzJStreamlit expander that can be renamed and dynamically expanded/collapsed.r
   strbool)parent_containerlabelexpandedc                 C  s0   || _ || _| | _| j||| _g | _dS )a;  Create a new MutableExpander.

        Parameters
        ----------
        parent_container
            The `st.container` that the expander will be created inside.

            The expander transparently deletes and recreates its underlying
            `st.expander` instance when its label changes, and it uses
            `parent_container` to ensure it recreates this underlying expander in the
            same location onscreen.
        label
            The expander's initial label.
        expanded
            The expander's initial `expanded` value.
        N)_label	_expandedempty_parent_cursorexpander
_container_child_records)selfr   r   r    r   r   r   __init__   s
    
zMutableExpander.__init__)returnc                 C  s   | j S )zExpander's label string.)r!   r(   r   r   r   r   4   s    zMutableExpander.labelc                 C  s   | j S )z6True if the expander was created with `expanded=True`.)r"   r+   r   r   r   r    9   s    zMutableExpander.expandedNonec                 C  s   | j  | _| j  dS )zeRemove the container and its contents entirely. A cleared container can't
        be reused.
        N)r$   r#   r&   r'   clearr+   r   r   r   r-   >   s    zMutableExpander.clear)otherr*   c                 C  s(   |j  }|D ]}| |j|j qdS )z]Append a copy of another MutableExpander's children to this
        MutableExpander.
        N)r'   copy_create_childr   r   )r(   r.   Zother_recordsrecordr   r   r   append_copyE   s    
zMutableExpander.append_copyN)	new_labelnew_expandedzOptional[str]zOptional[bool])r3   r4   r*   c                C  sz   |du r| j }|du r| j}| j |kr4| j|kr4dS || _ || _| j||| _| j}g | _|D ]}| |j|j q`dS )z.Change the expander's label and expanded stateN)	r!   r"   r$   r%   r&   r'   r0   r   r   )r(   r3   r4   Zprev_recordsr1   r   r   r   updateM   s    zMutableExpander.updateF)helpindexr   zOptional[int]int)bodyunsafe_allow_htmlr6   r7   r*   c                C  s<   |||d}|  |jf i |}ttj||}| ||S )z=Add a Markdown element to the container and return its index.)r9   r:   r6   )_get_dgmarkdownr   r   r   _add_record)r(   r9   r:   r6   r7   r   new_dgr1   r   r   r   r<   e   s    	zMutableExpander.markdown)r7   BaseException)	exceptionr7   r*   c                C  s8   d|i}|  |jf i |}ttj||}| ||S )z?Add an Exception element to the container and return its index.r@   )r;   r@   r   r   r   r=   )r(   r@   r7   r   r>   r1   r   r   r   r@   s   s    zMutableExpander.exceptionr   r   )r   r   r*   c                 C  sJ   |t jkr| jf i | n*|t jkr8| jf i | ntd| dS )z(Create a new child with the given paramszUnexpected child type N)r   r   r<   r   r@   RuntimeError)r(   r   r   r   r   r   r0   |   s
    

zMutableExpander._create_childr   )r1   r7   r*   c                 C  s0   |dur|| j |< |S | j | t| j d S )zAdd a ChildRecord to self._children. If `index` is specified, replace
        the existing record at that index. Otherwise, append the record to the
        end of the list.

        Return the index of the added record.
        N   )r'   appendlen)r(   r1   r7   r   r   r   r=      s
    
zMutableExpander._add_record)r7   r*   c                 C  sD   |d ur>d|  kr"t | jk s2n J d| | j| jS | jS )Nr   zBad index: )rD   r'   r   r&   )r(   r7   r   r   r   r;      s    *zMutableExpander._get_dg)F)r   r   r   r   r)   propertyr   r    r-   r2   r5   r<   r@   r0   r=   r;   r   r   r   r   r      s(   	 		r   N)
__future__r   enumr   typingr   r   r   r   r   r	   Zstreamlit.delta_generatorr
   Zstreamlit.type_utilr   r   r   r   r   r   r   r   <module>   s    