Ë
    Eêñi!  ã                  óæ   — d dl mZ d dlmZ d dlmZ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mZ erd dlmZ dddddddddddœ
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	„Z	 	 	 	 	 	 dd
„Zy)é    )Úannotations)ÚTYPE_CHECKING)ÚStreamlitAPIExceptionÚStreamlitInvalidBindValueError)Ú
BindOptionÚRegisterWidgetResultÚTÚValueFieldNameÚ
WidgetArgsÚWidgetCallbackÚWidgetDeserializerÚWidgetKwargsÚWidgetMetadataÚWidgetSerializerÚWidgetValuePresenterÚuser_key_from_element_id)ÚScriptRunContextNF)
Ú	callbacksÚon_change_handlerÚargsÚkwargsÚ	presenterÚbindÚformatted_optionsÚ	clearableÚmax_array_lengthÚallow_url_duplicatesc               ó  — |�|�t        d«      ‚|
�|
dk7  rt        |
«      ‚|
dk(  r%t        | «      }|€t        d«      ‚|€t        d«      ‚t	        | ||||||||r|j
                  nd|	|
||�|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.
    bind : BindOption
        Optional binding for the widget's value to external state.
        Currently only "query-params" is supported, which binds the widget
        value to a URL query parameter. Requires a user-provided key.
    formatted_options : list[str] or None
        **Temporary** - will be removed once all selection widgets use string-based
        wire formats. Currently used for index-based widgets (pills, segmented_control,
        select_slider) to convert indices back to human-readable option strings
        in URLs when auto-correcting filtered values.
    clearable : bool or None
        Whether the widget can be cleared to an empty state (reflects widget's UI
        behavior). When True, an empty URL param (e.g., ?foo=) will seed the widget
        with an empty value. When False, an empty URL param will be ignored.
        **Required when bind='query-params'**, otherwise defaults to False.

    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.zquery-paramsz”When using bind='query-params', the widget must have a unique 'key' parameter specified. This 'key' will be used as the name of the query parameter.zmclearable must be explicitly set when bind='query-params'. This is required for correct empty value handling.F)Ú
value_typeÚcallbackr   Úcallback_argsÚcallback_kwargsÚfragment_idr   r   r   r   r   r   )r   r   r   Ú
ValueErrorr   Úcurrent_fragment_idÚregister_widget_from_metadata)Ú
element_idÚdeserializerÚ
serializerÚctxr   r   r   r   r   r   r   r   r   r   r   Úuser_keyÚmetadatas                    úa/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/streamlit/runtime/state/widgets.pyÚregister_widgetr.   '   sÚ   € ðx Ð$¨Ð)>Ü#ØJó
ð 	
ð
 Ð˜D NÒ2Ü,¨TÓ2Ð2ð ˆ~ÒÜ+¨JÓ7ˆØÐÜ'ð#óð ð ÐÜðEóð ô ØØØØØ"ØØØÙ/2�C×+Ò+¸ØØØ+Ø(Ð4‘)¸%Ø)Ø1ô€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_idr+   s       r-   r&   r&   ±   sN   € ð €{ô $×+Ñ+¸×9NÑ9NÔOÐOà—‘€IÜ'¨	Ó2€Hà×Ñ×,Ñ,¨X°xÓ@Ð@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 | Noner   r   r   zlist[str] | Noner   zbool | Noner   z
int | Noner   ÚboolÚreturnúRegisterWidgetResult[T])r,   zWidgetMetadata[T]r*   r6   r8   r9   )Ú
__future__r   Útypingr   Ústreamlit.errorsr   r   Ústreamlit.runtime.state.commonr   r   r	   r
   r   r   r   r   r   r   r   r   Ústreamlit.runtime.scriptrunnerr   r.   r&   © r/   r-   ú<module>r@      s&  ðõ #å  ç R÷÷ ÷ ó ñ Ý?ð 37Ø/3Ø"Ø"&à-1Øð +/Ø!Ø#'Ø!&ñ%G8ØðG8ð (ðG8ð $ð	G8ð
 
!ðG8ð 0ðG8ð -ðG8ð ðG8ð  ðG8ð ðG8ð +ðG8ð ðG8ð (ðG8ð  ð!G8ð" !ð#G8ð$ ð%G8ð& ó'G8ðTAØðAà	 ðAð ôAr/   