o
    ,&]i                     @  s   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 er8d dlmZ d dlmZ eeZG d	d
 d
eddZ		ddddZdS )    )annotations)TYPE_CHECKINGAny	TypedDictcast)Self)StreamlitAPIException)
get_logger)get_script_run_ctx)SessionState)WidgetValuePresenterc                   @  s   e Zd ZU ded< ded< dS )_TriggerPayloadstreventobjectvalueN)__name__
__module____qualname____annotations__ r   r   b/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/components/v2/presentation.pyr   !   s   
 r   F)totalNaggregator_idr   component_id
str | Noneallowed_state_keysset[str] | Nonereturnr   c                   s   d	 fdd}|S )
a  Return a presenter that merges trigger events into CCv2 state.

    This function returns a callable that takes a component's persistent state
    value and the current `SessionState` instance, and returns the user-visible
    value that should appear in `st.session_state`.

    The presenter is side-effect-free and does not mutate stored state or
    callback behavior. It is intended to be attached to the persistent state
    widget via the generic `presenter` hook.

    Parameters
    ----------
    aggregator_id
        The ID of the trigger aggregator widget that holds the event payloads.

    Returns
    -------
    WidgetValuePresenter
        A callable that merges the trigger event values into the component's
        base state for presentation in `st.session_state`.

    
base_valuer   session_stater   r   c              
     st  dfdd d }t | trtd| }|d urzjj}|d u s)|jdkr,| W S zj }W n ty>   d }Y nw |d u rFd }nt |trSd	d
 |D }nt |tr_td|g}nd }i }|d ur}|D ]}|d}t |t	r||d||< qit|}	|	
| G  fdddtt	tf }
|
|	W S  ty } ztjd||d | W  Y d }~S d }~ww | S )Nkr   r   Nonec                   s^   t  }|d ur) d ur+j } |jv s||jv r-td| d|  d| dd S d S d S )Nz`st.session_state..z3` cannot be modified after the component with key `z` is instantiated.)r
   _key_id_mapperget_key_from_idwidget_ids_this_runform_ids_this_runr   )r!   ctxuser_key)r   r    r   r   _check_modificationC   s   

zLmake_bidi_component_presenter.<locals>._present.<locals>._check_modificationdict[str, object]json_trigger_valuec                 S  s    g | ]}t |trtd |qS )r   )
isinstancedictr   ).0pr   r   r   
<listcomp>h   s    zCmake_bidi_component_presenter.<locals>._present.<locals>.<listcomp>r   r   r   c                      sj   e Zd Zd fddZdd
dZd fddZdddZd fddZd fddZ  Z	S ) zFmake_bidi_component_presenter.<locals>._present.<locals>._WriteThroughdatar+   r   r"   c                   s   t  | d S N)super__init__)selfr2   	__class__r   r   r5      s   zOmake_bidi_component_presenter.<locals>._present.<locals>._WriteThrough.__init__namer   r   c                 S  s
   |  |S r3   )get)r6   r9   r   r   r   __getattr__   s   
zRmake_bidi_component_presenter.<locals>._present.<locals>._WriteThrough.__getattr__r   c                   s$   | drt ||S || |< d S )N)___)
startswithr4   __setattr__)r6   r9   r   r7   r   r   r?      s   
zRmake_bidi_component_presenter.<locals>._present.<locals>._WriteThrough.__setattr__memodict[int, Any]r   c                 S  s   | |t | < | S r3   )id)r6   r@   r   r   r   __deepcopy__   s   zSmake_bidi_component_presenter.<locals>._present.<locals>._WriteThrough.__deepcopy__r!   vc              
     s   | d ur|vrd S t  || z}d ur(|jt|  W d S W d S  tyC } ztd| W Y d }~d S d }~ww )Nz'Failed to persist CCv2 state update: %s)r4   __setitem___new_widget_stateset_from_valuer.   	Exception_LOGGERdebug)r6   r!   rD   sse)r8   r*   r   r   r    r   r   rE      s    
zRmake_bidi_component_presenter.<locals>._present.<locals>._WriteThrough.__setitem__c              
     sr   | t  | z}d ur|jt|  W d S W d S  ty8 } ztd| W Y d }~d S d }~ww )Nz)Failed to persist CCv2 state deletion: %s)r4   __delitem__rF   rG   r.   rH   rI   rJ   )r6   r!   rK   rL   )r8   r*   r   r    r   r   rM      s   
zRmake_bidi_component_presenter.<locals>._present.<locals>._WriteThrough.__delitem__)r2   r+   r   r"   )r9   r   r   r   )r9   r   r   r   r   r"   )r@   rA   r   r   )r!   r   rD   r   r   r"   r!   r   r   r"   )
r   r   r   r5   r;   r?   rC   rE   rM   __classcell__r   )r*   r   r   r    r7   r   _WriteThrough   s    

rP   z7Failed to merge trigger events into component state: %s)exc_inforN   )r-   r.   r   rF   widget_metadatar:   
value_typeKeyErrorlistr   updater   rH   rI   rJ   )r   r    base_mapagg_metaagg_payloads_objpayloads_listevent_to_valpayloadevflatrP   rL   r   r   r   )r*   r    r   _presentB   s\   






"
8	z/make_bidi_component_presenter.<locals>._presentN)r   r   r    r   r   r   r   )r   r   r   r`   r   r_   r   make_bidi_component_presenter&   s    ra   )NN)r   r   r   r   r   r   r   r   )
__future__r   typingr   r   r   r   typing_extensionsr   streamlit.errorsr   streamlit.loggerr	   streamlit.runtime.scriptrunnerr
   streamlit.runtime.stater   streamlit.runtime.state.commonr   r   rI   r   ra   r   r   r   r   <module>   s   