
    xiX                        U 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 d dlmZ d d	lmZmZ d d
lmZ d dlmZ erd dlmZ d dlmZ d dlmZ ed   Z de!d<   	 	 	 	 ddZ"ddZ# G d de
      Z$y)    )annotations)TYPE_CHECKINGLiteral	TypeAliascast)Self)DeltaGenerator)compute_and_register_element_id)StreamlitAPIException)Block)
ForwardMsg)enqueue_messageget_script_run_ctx)register_widget)validate_icon_or_emoji)TracebackType)Cursor)WidgetCallback)smalllargemediumr   DialogWidthc                    | dk(  r$t         j                  j                  j                  S | dk(  r$t         j                  j                  j                  S t         j                  j                  j
                  S )zMaps the user-provided literal to a value of the DialogWidth proto enum.

    Returns the mapped enum field for "small" by default and otherwise the mapped type.
    r   r   )
BlockProtoDialogr   LARGEMEDIUMSMALL)widths    i/var/www/html/chatbot/card-advisor-bot/venv/lib/python3.12/site-packages/streamlit/elements/lib/dialog.py_process_dialog_width_inputr!   *   s\       ,,222  ,,333((...    c                `    t               }| r"|r|j                  rt        d      d|_        yyy)a  Check whether a dialog has already been opened in the same script run.

    Only one dialog is supposed to be opened. The check is implemented in a way
    that for a script run, the open function can only be called once.
    One dialog at a time is a product decision and not a technical one.

    Raises
    ------
    StreamlitAPIException
        Raised when a dialog has already been opened in the current script run.
    zOnly one dialog is allowed to be opened at the same time. Please make sure to not call a dialog-decorated function more than once in a script run.TN)r   has_dialog_openedr   )should_openscript_run_ctxs     r    !_assert_first_dialog_to_be_openedr'   9   s@     ()N ~++'k  ,0( &{r"   c                       e Zd Zeddddd	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 	 	 	 	 	 d fdZddZdd	Zdd
Zd fdZ		 	 	 	 	 	 	 	 d fdZ
 xZS )r   Tr   Nignore)dismissibler   icon
on_dismissc                  |dvrt        |      st        d| d      t               }||j                  _        ||j                  _        t        |      |j                  _        t        |      |j                  _	        t        dd d| ||||t        |      st        |      nd	      }||_        |dk7  }|r;t               }	||j                  _        t        |t        |      r|nd d	 d
 |	d       | j                  j                   r | j                  j                   j"                  ng }
t%        d| j'                  |t(                    }|
|_        ||_        |S )N)r)   rerunzYou have passed zI to `on_dismiss`. But only 'ignore', 'rerun', or a callable is supported.dialogFcallback)user_keykey_as_main_identitydgtitler*   r   r+   r,   r)   c                    | S N xs    r    <lambda>z Dialog._create.<locals>.<lambda>   s    q r"   c                    | S r6   r7   r8   s    r    r:   z Dialog._create.<locals>.<lambda>   s    Q r"   trigger_value)on_change_handlerdeserializer
serializerctx
value_typer   )block_protodg_type)callabler   r   r/   r4   r*   r!   r   r   r+   r
   stridr   r   
_active_dg_cursor
delta_pathr   _blockr   _delta_path_current_proto)parentr4   r*   r   r+   r,   rB   
element_idis_dismiss_activatedr@   rI   r/   s               r    _createzDialog._createS   sd    00*9M'":, /7 7 
 !l#( )4&#>u#E "8"> 5!&#.6z.Bs:



 $  *X5 %&C %/K!080D*$(&* 5;4E4E4M4MF%%00SU 	 h+v VW' +r"   c                F    t         |   ||||       d | _        d | _        y r6   )super__init__rL   rK   )selfroot_containercursorrM   
block_type	__class__s        r    rS   zDialog.__init__   s*     	D 26-1r"   c                   | j                   | j                  t        d      t        |       t	               }| j                  |j
                  j                  dd |j                  j                  j                  | j                          ||j                  j                  j                  _        |j                  j                  | _         t        |       y)zISend an updated proto message to indicate the open-status for the dialog.Nz;Dialog not correctly initialized. This should never happen.)rL   rK   RuntimeErrorr'   r   metadatarI   delta	add_blockCopyFromr/   is_openr   )rT   r%   msgs      r    _updatezDialog._update   s     &$*:*:*BM  	*+6l%)%5%5"		$$T%8%89-8		""*!ii11r"   c                &    | j                  d       y )NTra   rT   s    r    openzDialog.open   s    Tr"   c                &    | j                  d       y )NFrc   rd   s    r    closezDialog.close   s    Ur"   c                $    t         |           | S r6   )rR   	__enter__)rT   rX   s    r    ri   zDialog.__enter__   s     	r"   c                &    t         |   |||      S r6   )rR   __exit__)rT   exc_typeexc_valexc_tbrX   s       r    rk   zDialog.__exit__   s     w'6::r"   )rM   r	   r4   rE   r*   boolr   r   r+   
str | Noner,   z+Literal['ignore', 'rerun'] | WidgetCallbackreturnr   )
rU   z
int | NonerV   zCursor | NonerM   zDeltaGenerator | NonerW   rp   rq   Noner%   ro   rq   rr   )rq   rr   )rq   r   )rl   ztype[BaseException] | Nonerm   zBaseException | Nonern   zTracebackType | Nonerq   zLiteral[False])__name__
__module____qualname__staticmethodrP   rS   ra   re   rg   ri   rk   __classcell__)rX   s   @r    r   r   R   s    
 !$BJMMM 	M
 M M @M 
M M^2"2 2 &	2
 2 
2";,; &; %	;
 
; ;r"   r   N)r   r   rq   z'BlockProto.Dialog.DialogWidth.ValueTypers   )%
__future__r   typingr   r   r   r   typing_extensionsr   streamlit.delta_generatorr	   streamlit.elements.lib.utilsr
   streamlit.errorsr   streamlit.proto.Block_pb2r   r   streamlit.proto.ForwardMsg_pb2r   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   streamlit.runtime.stater   streamlit.string_utilr   typesr   streamlit.cursorr   r   r   __annotations__r!   r'   r   r7   r"   r    <module>r      ss    # : : " 4 H 2 9 5 4 8#'6 !;<Y <//,/02B;^ B;r"   