
    ȯei                        d dl mZ 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mZmZmZmZmZ erd dlmZ dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
dZ	 	 	 	 	 	 dd	Zy)    )annotations)TYPE_CHECKING)StreamlitAPIException)RegisterWidgetResultTValueFieldName
WidgetArgsWidgetCallbackWidgetDeserializerWidgetKwargsWidgetMetadataWidgetSerializerWidgetValuePresenteruser_key_from_element_id)ScriptRunContextN)	callbackson_change_handlerargskwargs	presenterc       	        ~    ||t        d      t        | ||||||||r|j                  nd|	
      }
t        |
|      S )a  Register a widget with Streamlit, and return its current value.
    NOTE: This function should be called after the proto has been filled.

    Parameters
    ----------
    element_id : str
        The id of the element. Must be unique.
    deserializer : WidgetDeserializer[T]
        Called to convert a widget's protobuf value to the value returned by
        its st.<widget_name> function.
    serializer : WidgetSerializer[T]
        Called to convert a widget's value to its protobuf representation.
    ctx : ScriptRunContext or None
        Used to ensure uniqueness of widget IDs, and to look up widget values.
    callbacks : dict[str, WidgetCallback] or None
        A dictionary of callbacks for multi-callback support.
    on_change_handler : WidgetCallback or None
        An optional callback invoked when the widget's value changes.
    args : WidgetArgs or None
        Positional arguments to pass to the `on_change_handler` or `callbacks`.
    kwargs : WidgetKwargs or None
        Keyword arguments to pass to the `on_change_handler` or `callbacks`.
    value_type: ValueFieldName
        The value_type the widget is going to use.
        We use this information to start with a best-effort guess for the value_type
        of each widget. Once we actually receive a proto for a widget from the
        frontend, the guess is updated to be the correct type. Unfortunately, we're
        not able to always rely on the proto as the type may be needed earlier.
        Thankfully, in these cases (when value_type == "trigger_value"), the static
        table here being slightly inaccurate should never pose a problem.
    presenter : WidgetValuePresenter or None
        An optional hook that allows a widget to customize how its value should be
        presented.


    Returns
    -------
    register_widget_result : RegisterWidgetResult[T]
        Provides information on which value to return to the widget caller,
        and whether the UI needs updating.

        - Unhappy path:
            - Our ScriptRunContext doesn't exist (meaning that we're running
            as a "bare script" outside streamlit).
            - We are disconnected from the SessionState instance.
            In both cases we'll return a fallback RegisterWidgetResult[T].
        - Happy path:
            - The widget has already been registered on a previous run but the
            user hasn't interacted with it on the client. The widget will have
            the default value it was first created with. We then return a
            RegisterWidgetResult[T], containing this value.
            - The widget has already been registered and the user *has*
            interacted with it. The widget will have that most recent
            user-specified value. We then return a RegisterWidgetResult[T],
            containing this value.

        For both paths a widget return value is provided, allowing the widgets
        to be used in a non-streamlit setting.
    Nz<Cannot provide both `on_change` and `callbacks` to a widget.)
value_typecallbackr   callback_argscallback_kwargsfragment_idr   )r   r   current_fragment_idregister_widget_from_metadata)
element_iddeserializer
serializerctxr   r   r   r   r   r   metadatas              a/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/streamlit/runtime/state/widgets.pyregister_widgetr%   &   sc    P $)>#J
 	

 "/2C++H )377    c                    | t        j                  | j                        S | j                  }t	        |      }|j
                  j                  | |      S )a$  Register a widget and return its value, using an already constructed
    `WidgetMetadata`.

    This is split out from `register_widget` to allow caching code to replay
    widgets by saving and reusing the completed metadata.

    See `register_widget` for details on what this returns.
    )r    )r   failurer    idr   session_stater%   )r#   r"   	widget_iduser_keys       r$   r   r      sN     { $++9N9NOOI'	2H,,Xx@@r&   )r   strr    zWidgetDeserializer[T]r!   zWidgetSerializer[T]r"   ScriptRunContext | Noner   z dict[str, WidgetCallback] | Noner   zWidgetCallback | Noner   zWidgetArgs | Noner   zWidgetKwargs | Noner   r   r   zWidgetValuePresenter | NonereturnRegisterWidgetResult[T])r#   zWidgetMetadata[T]r"   r.   r/   r0   )
__future__r   typingr   streamlit.errorsr   streamlit.runtime.state.commonr   r   r   r	   r
   r   r   r   r   r   r   streamlit.runtime.scriptrunnerr   r%   r    r&   r$   <module>r7      s    #   2    ? 37/3""&-1Z8Z8 (Z8 $	Z8
 
!Z8 0Z8 -Z8 Z8  Z8 Z8 +Z8 Z8zAA	 A Ar&   