Ë
    Eêñiy.  ã                  ó8  — U d dl mZ d dlmZmZmZmZmZ d dlm	Z	 d dl
mZmZ 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 d dlmZ erd dlm Z  d dlm!Z!m"Z"m#Z# dZ$de%d<   dZ&de%d<   dZ'de%d<   dd„Z(	 	 	 	 dd„Z) G d„ d«      Z* G d„ d«      Z+y)é    )Úannotations)ÚTYPE_CHECKINGÚFinalÚLiteralÚcastÚoverload)Úcurrent_form_id)ÚWidthÚcreate_layout_config)Úcheck_widget_policies)ÚKeyÚcompute_and_register_element_idÚsave_for_app_testingÚto_key)ÚStreamlitAPIException)ÚFeedback)Úgather_metrics)Úget_script_run_ctx)Úregister_widget)ÚDeltaGenerator)Ú
WidgetArgsÚWidgetCallbackÚWidgetKwargsé   r   Ú_NUM_THUMBS_OPTIONSé   Ú_NUM_FACES_OPTIONSÚ_NUM_STARS_OPTIONSc                ó:   — | dk(  rt         S | dk(  rt        S t        S )z6Get the number of options for the given feedback type.ÚthumbsÚfaces)r   r   r   ©Úfeedback_types    úe/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/streamlit/elements/widgets/feedback.pyÚ_get_num_optionsr%   :   s$   € à˜Ò Ü"Ð"Ø˜ÒÜ!Ð!ÜÐó    c                ó²   — | dk(  rt         j                  j                  S | dk(  rt         j                  j                  S t         j                  j                  S )z7Convert a feedback type string to the proto enum value.r    r!   )ÚFeedbackProtoÚFeedbackTypeÚTHUMBSÚFACESÚSTARSr"   s    r$   Ú_feedback_type_to_protor-   C   sJ   € ð ˜Ò Ü×)Ñ)×0Ñ0Ð0Ø˜ÒÜ×)Ñ)×/Ñ/Ð/Ü×%Ñ%×+Ñ+Ð+r&   c                  ó*   — e Zd ZdZddd„Zdd„Zd	d„Zy)
ÚFeedbackSerdeaÈ  Serializer/deserializer for feedback widget values.

    Uses string as the wire format to distinguish three states:
    - None (field not set): No UI interaction yet -> use default_value
    - "" (empty string): User explicitly cleared -> return None
    - "2" (string with value): User selected -> return int value

    This allows clearing to work correctly even when a default is set.
    The session state and return values are always int | None.
    Nc                ó   — || _         y ©N©Údefault_value)Úselfr3   s     r$   Ú__init__zFeedbackSerde.__init__Z   s
   € Ø*ˆÕr&   c                ó    — |€dS t        |«      S )z.Serialize int value to string for wire format.Ú )Ústr)r4   Úvalues     r$   Ú	serializezFeedbackSerde.serialize]   s   € à�]ˆrÐ2¬¨E«
Ð2r&   c                ó@   — |€| j                   S |dk(  ryt        |«      S )z1Deserialize string wire format back to int value.Nr7   )r3   Úint)r4   Úui_values     r$   ÚdeserializezFeedbackSerde.deserializea   s(   € àÐØ×%Ñ%Ð%Ø�rŠ>ØÜ�8‹}Ðr&   r1   )r3   ú
int | None)r9   r?   Úreturnr8   )r=   z
str | Noner@   r?   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   r:   r>   © r&   r$   r/   r/   N   s   „ ñ	ô+ó3ôr&   r/   c            
      ó  — e Zd Ze	 d
ddddddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Ze	 d
ddddddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Z ed«      	 dddddddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Zedd	„«       Zy)ÚFeedbackMixinNFÚcontent)ÚkeyÚdefaultÚdisabledÚ	on_changeÚargsÚkwargsÚwidthc                ó   — y r1   rE   ©	r4   ÚoptionsrI   rJ   rK   rL   rM   rN   rO   s	            r$   ÚfeedbackzFeedbackMixin.feedbackk   s   € ð  #r&   c                ó   — y r1   rE   rQ   s	            r$   rS   zFeedbackMixin.feedbacky   s   € ð ),r&   rS   c          
     ó  — |dvrt        d|› d�«      ‚t        |«      }	|�!|dk  s||	k\  rt        d|› d|	dz
  › d	|› �«      ‚t        |«      }t        |d
¬«      }
t	        | j
                  |||¬«       t        «       }t        | j
                  «      }t        d|dh| j
                  |||¬«      }t        «       }||_
        t        |«      |_        ||_        ||_        |�||_        t!        |¬«      }t#        |j                  ||||j$                  |j&                  |d¬«      }|j(                  r$|j*                  �|j*                  |_        d
|_        |rt/        ||d«       | j
                  j1                  d||
¬«       |j*                  S )a›  Display a feedback widget.

        A feedback widget is an icon-based button group available in three
        styles, as described in ``options``. It is commonly used in chat and AI
        apps to allow users to rate responses.

        Parameters
        ----------
        options : "thumbs", "faces", or "stars"
            The feedback options displayed to the user. ``options`` can be one
            of the following:

            - ``"thumbs"`` (default): Streamlit displays a thumb-up and
              thumb-down button group.
            - ``"faces"``: Streamlit displays a row of five buttons with
              facial expressions depicting increasing satisfaction from left to
              right.
            - ``"stars"``: Streamlit displays a row of star icons, allowing the
              user to select a rating from one to five stars.

        key : str, int, or None
            An optional string or integer to use as the unique key for
            the widget. If this is ``None`` (default), a key will be
            generated for the widget based on the values of the other
            parameters. No two widgets may have the same key. Assigning
            a key stabilizes the widget's identity and preserves its
            state across reruns even when other parameters change.

            .. note::
               Changing ``options`` resets the widget even when a key is
               provided.

            A key lets you read or update the widget's value via
            ``st.session_state[key]``. For more details, see `Widget
            behavior <https://docs.streamlit.io/develop/concepts/architecture/widget-behavior>`_.

            Additionally, if ``key`` is provided, it will be used as a
            CSS class name prefixed with ``st-key-``.

        default : int or None
            Default feedback value. This must be consistent with the feedback
            type in ``options``:

            - 0 or 1 if ``options="thumbs"``.
            - Between 0 and 4, inclusive, if ``options="faces"`` or
              ``options="stars"``.

        disabled : bool
            An optional boolean that disables the feedback widget if set
            to ``True``. The default is ``False``.

        on_change : callable
            An optional callback invoked when this feedback widget's value
            changes.

        args : list or tuple
            An optional list or tuple of args to pass to the callback.

        kwargs : dict
            An optional dict of kwargs to pass to the callback.

        width : "content", "stretch", or int
            The width of the feedback widget. This can be one of the following:

            - ``"content"`` (default): The width of the widget matches the
              width of its content, but doesn't exceed the width of the parent
              container.
            - ``"stretch"``: The width of the widget matches the width of the
              parent container.
            - An integer specifying the width in pixels: The widget has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the widget matches the width
              of the parent container.

        Returns
        -------
        int or None
            An integer indicating the user's selection, where ``0`` is the
            lowest feedback. Higher values indicate more positive feedback.
            If no option was selected, the widget returns ``None``.

            - For ``options="thumbs"``, a return value of ``0`` indicates
              thumbs-down, and ``1`` indicates thumbs-up.
            - For ``options="faces"`` and ``options="stars"``, return values
              range from ``0`` (least satisfied) to ``4`` (most satisfied).

        Examples
        --------
        Display a feedback widget with stars, and show the selected sentiment:

        >>> import streamlit as st
        >>>
        >>> sentiment_mapping = ["one", "two", "three", "four", "five"]
        >>> selected = st.feedback("stars")
        >>> if selected is not None:
        >>>     st.markdown(f"You selected {sentiment_mapping[selected]} star(s).")

        .. output::
            https://doc-feedback-stars.streamlit.app/
            height: 200px

        Display a feedback widget with thumbs, and show the selected sentiment:

        >>> import streamlit as st
        >>>
        >>> sentiment_mapping = [":material/thumb_down:", ":material/thumb_up:"]
        >>> selected = st.feedback("thumbs")
        >>> if selected is not None:
        >>>     st.markdown(f"You selected: {sentiment_mapping[selected]}")

        .. output::
            https://doc-feedback-thumbs.streamlit.app/
            height: 200px

        >   r!   Ústarsr    zjThe options argument to st.feedback must be one of ['thumbs', 'faces', 'stars']. The argument passed was 'z'.Nr   zThe default value in 'z!' must be a number between 0 and é   z. The passed default value is T)rO   Úallow_content_widthr2   rS   rR   )Úuser_keyÚkey_as_main_identityÚdgrR   rJ   rO   Ústring_value)Úon_change_handlerrM   rN   ÚdeserializerÚ
serializerÚctxÚ
value_type)Úlayout_config)r   r%   r   r   r   r[   r   r	   r   r(   Úidr-   ÚtyperK   Úform_idrJ   r/   r   r>   r:   Úvalue_changedr9   Ú	set_valuer   Ú_enqueue)r4   rR   rI   rJ   rK   rL   rM   rN   rO   Únum_optionsrb   r`   re   Ú
element_idÚprotoÚserdeÚwidget_states                    r$   rS   zFeedbackMixin.feedback‡   s²  € ð@ Ð6Ñ6Ü'ð,à,3¨9°Bð8óð ô ' wÓ/ˆàÐ G¨a¢K°7¸kÒ3IÜ'Ø(¨¨	Ð1RÐS^ÐabÑSbÐRcð d0Ø07¨yð:óð ô
 �S‹kˆÜ,°5ÈdÔSˆä˜dŸg™g s¨IÀWÕMä Ó"ˆÜ! $§'¡'Ó*ˆä4ØØØ"+ Ø�w‰wØØØô
ˆ
ô “ˆØˆŒÜ,¨WÓ5ˆŒ
Ø!ˆŒØˆŒàÐØ#ˆEŒMä¨GÔ4ˆä&Ø�H‰HØ'ØØØ×*Ñ*Ø—‘ØØ%ô	
ˆð ×%Ò%Ø×!Ñ!Ð-Ø*×0Ñ0�”Ø"ˆEŒOáÜ   j°$Ô7à�‰×Ñ˜ U¸-ÐÔHà×!Ñ!Ð!r&   c                ó   — t        d| «      S )zGet our DeltaGenerator.r   )r   )r4   s    r$   r[   zFeedbackMixin.dgK  s   € ô Ð$ dÓ+Ð+r&   ).)rR   zLiteral['thumbs']rI   ú
Key | NonerJ   r?   rK   ÚboolrL   úWidgetCallback | NonerM   úWidgetArgs | NonerN   úWidgetKwargs | NonerO   r
   r@   zLiteral[0, 1] | None)rR   zLiteral['faces', 'stars']rI   ro   rJ   r?   rK   rp   rL   rq   rM   rr   rN   rs   rO   r
   r@   zLiteral[0, 1, 2, 3, 4] | None)r    )rR   ú#Literal['thumbs', 'faces', 'stars']rI   ro   rJ   r?   rK   rp   rL   rq   rM   rr   rN   rs   rO   r
   r@   r?   )r@   r   )rA   rB   rC   r   rS   r   Úpropertyr[   rE   r&   r$   rG   rG   j   sÎ  „ Øð &)ð#ð Ø"ØØ+/Ø"&Ø&*Ø ñ#à"ð#ð ð	#ð
 ð#ð ð#ð )ð#ð  ð#ð $ð#ð ð#ð 
ò#ó ð#ð ð .1ð,ð Ø"ØØ+/Ø"&Ø&*Ø ñ,à*ð,ð ð	,ð
 ð,ð ð,ð )ð,ð  ð,ð $ð,ð ð,ð 
'ò,ó ð,ñ �JÓð 8@ðA"ð Ø"ØØ+/Ø"&Ø&*Ø ñA"à4ðA"ð ð	A"ð
 ðA"ð ðA"ð )ðA"ð  ðA"ð $ðA"ð ðA"ð 
òA"ó  ðA"ðF ò,ó ñ,r&   rG   N)r#   rt   r@   r<   )r#   rt   r@   z$FeedbackProto.FeedbackType.ValueType),Ú
__future__r   Útypingr   r   r   r   r   Ú!streamlit.elements.lib.form_utilsr	   Ú#streamlit.elements.lib.layout_utilsr
   r   Ústreamlit.elements.lib.policiesr   Ústreamlit.elements.lib.utilsr   r   r   r   Ústreamlit.errorsr   Ústreamlit.proto.Feedback_pb2r   r(   Ústreamlit.runtime.metrics_utilr   Ú7streamlit.runtime.scriptrunner_utils.script_run_contextr   Ústreamlit.runtime.stater   Ústreamlit.delta_generatorr   r   r   r   r   Ú__annotations__r   r   r%   r-   r/   rG   rE   r&   r$   ú<module>rƒ      s¢   ðö #÷õ õ >÷õ B÷ó õ 3Ý BÝ 9Ý VÝ 3áÝ8÷ñ ð Ð �UÓ ØÐ �EÓ ØÐ �EÓ óð,Ø6ð,à)ó,÷ñ ÷8d,ò d,r&   