
    h                        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rd dlmZ d dlmZ  G d de      Z G d d	e	      Z G d
 d      Zy)    )annotations)Enum)TYPE_CHECKINGAnyDictList
NamedTupleOptional)DeltaGenerator)SupportsStrc                      e Zd ZdZdZdZy)	ChildTypezEnumerator of the child type.MARKDOWN	EXCEPTIONN)__name__
__module____qualname____doc__r   r        v/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/callbacks/streamlit/mutable_expander.pyr   r      s    'HIr   r   c                  0    e Zd ZU dZded<   ded<   ded<   y)	ChildRecordzChild record as a NamedTuple.r   typeDict[str, Any]kwargsr   dgN)r   r   r   r   __annotations__r   r   r   r   r      s    '
Or   r   c                      e Zd ZdZddZedd       Zedd       ZddZddZ	ddd	 	 	 	 	 dd	Z
	 dddd
	 	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 ddZddZddZddZy)MutableExpanderzJStreamlit expander that can be renamed and dynamically expanded/collapsed.c                    || _         || _        |j                         | _        | j                  j	                  ||      | _        g | _        y)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)selfparent_containerlabelexpandeds       r   __init__zMutableExpander.__init__   sE    " !.446--66uhG13r   c                    | j                   S )zExpander's label string.)r"   r)   s    r   r+   zMutableExpander.label4   s     {{r   c                    | j                   S )z6True if the expander was created with `expanded=True`.)r#   r/   s    r   r,   zMutableExpander.expanded9   s     ~~r   c                v    | j                   j                         | _        | j                  j	                          y)zeRemove the container and its contents entirely. A cleared container can't
        be reused.
        N)r%   r$   r'   r(   clearr/   s    r   r2   zMutableExpander.clear>   s,     --335!!#r   c                    |j                   j                         }|D ](  }| j                  |j                  |j                         * y)z]Append a copy of another MutableExpander's children to this
        MutableExpander.
        N)r(   copy_create_childr   r   )r)   otherother_recordsrecords       r   append_copyzMutableExpander.append_copyE   s?     ,,113# 	;Fv{{FMM:	;r   N)	new_labelnew_expandedc               X   || j                   }|| j                  }| j                   |k(  r| j                  |k(  ry|| _         || _        | j                  j                  ||      | _        | j
                  }g | _        |D ](  }| j                  |j                  |j                         * y)z.Change the expander's label and expanded stateN)	r"   r#   r%   r&   r'   r(   r5   r   r   )r)   r:   r;   prev_recordsr8   s        r   updatezMutableExpander.updateM   s     I>>L;;)#,(F%--66y,O**  # 	;Fv{{FMM:	;r   )helpindexc                   |||d} | j                  |      j                  di |}t        t        j                  ||      }| j                  ||      S )z=Add a Markdown element to the container and return its index.)bodyunsafe_allow_htmlr?   r   )_get_dgmarkdownr   r   r   _add_record)r)   rB   rC   r?   r@   r   new_dgr8   s           r   rE   zMutableExpander.markdowne   sW     5FPTU-e$--77Y//@..r   )r@   c                   d|i} | j                  |      j                  di |}t        t        j                  ||      }| j                  ||      S )z?Add an Exception element to the container and return its index.	exceptionr   )rD   rI   r   r   r   rF   )r)   rI   r@   r   rG   r8   s         r   rI   zMutableExpander.exceptions   sS     y).e$..88Y00&&A..r   c                    |t         j                  k(  r | j                  di | y|t         j                  k(  r | j                  di | yt        d|       )z(Create a new child with the given paramszUnexpected child type Nr   )r   r   rE   r   rI   RuntimeError)r)   r   r   s      r   r5   zMutableExpander._create_child|   sS    9%%%DMM#F#Y(((DNN$V$!7v>??r   c                    ||| j                   |<   |S | j                   j                  |       t        | j                         dz
  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.
           )r(   appendlen)r)   r8   r@   s      r   rF   zMutableExpander._add_record   sK     )/D&L 	""6*4&&'!++r   c                    |Cd|cxk  rt        | j                        k  sn J d|        | j                  |   j                  S | j                  S )Nr   zBad index: )rO   r(   r   r'   )r)   r@   s     r   rD   zMutableExpander._get_dg   sU    8D$7$7 88OKw:OO8&&u-000 r   )r*   r   r+   strr,   bool)returnrQ   )rS   rR   )rS   None)r6   r    rS   rT   )r:   Optional[str]r;   zOptional[bool]rS   rT   )F)
rB   r   rC   rR   r?   rU   r@   Optional[int]rS   int)rI   BaseExceptionr@   rV   rS   rW   )r   r   r   r   rS   rT   )r8   r   r@   rV   rS   rW   )r@   rV   rS   r   )r   r   r   r   r-   propertyr+   r,   r2   r9   r>   rE   rI   r5   rF   rD   r   r   r   r    r       s    T4.    $; -1QU;);@N;	;6 #(/
 ##//  /
 / / 
/ CG/&/2?/	/@, r   r    N)
__future__r   enumr   typingr   r   r   r   r	   r
   streamlit.delta_generatorr   streamlit.type_utilr   r   r   r    r   r   r   <module>r_      s>    "  G G8/ * B Br   