
    /_i                        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 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)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    \/var/www/html/land_sniper/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&   8   s@     ()N ~++'k  ,0( &{r!   c                       e Zd Ze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   ignore)dismissibler   
on_dismissc               v   |dvrt        |      st        d| d      t               }||j                  _        ||j                  _        t        |      |j                  _        |dk7  }d }|rdt               }t        dd d| |||t        |      st        |      nd      }||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.r(   dialogFcallback)user_keykey_as_main_identitydgtitler)   r   r*   c                    | S N xs    r   <lambda>z Dialog._create.<locals>.<lambda>   s    q r!   c                    | S r4   r5   r6   s    r   r8   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-   r2   r)   r    r   r   r
   stridr   
_active_dg_cursor
delta_pathr   _blockr   _delta_path_current_proto)parentr2   r)   r   r*   r@   is_dismiss_activated
element_idr>   rG   r-   s              r   _createzDialog._createR   sH    00*9M'":, /7 7 
 !l#( )4&#>u#E   *X5
 %&C8%*'2::2F3z?J	J %/K!080D*$(&* 5;4E4E4M4MF%%00SU 	 h+v VW' +r!   c                F    t         |   ||||       d | _        d | _        y r4   )super__init__rJ   rI   )selfroot_containercursorrK   
block_type	__class__s        r   rQ   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.)rJ   rI   RuntimeErrorr&   r   metadatarG   delta	add_blockCopyFromr-   is_openr   )rR   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r_   rR   s    r   openzDialog.open   s    Tr!   c                &    | j                  d       y )NFra   rb   s    r   closezDialog.close   s    Ur!   c                $    t         |           | S r4   )rP   	__enter__)rR   rV   s    r   rg   zDialog.__enter__   s     	r!   c                &    t         |   |||      S r4   )rP   __exit__)rR   exc_typeexc_valexc_tbrV   s       r   ri   zDialog.__exit__   s     w'6::r!   )rK   r	   r2   rC   r)   boolr   r   r*   z+Literal['ignore', 'rerun'] | WidgetCallbackreturnr   )
rS   z
int | NonerT   zCursor | NonerK   zDeltaGenerator | NonerU   z
str | Nonern   Noner$   rm   rn   ro   )rn   ro   )rn   r   )rj   ztype[BaseException] | Nonerk   zBaseException | Nonerl   zTracebackType | Nonern   zLiteral[False])__name__
__module____qualname__staticmethodrN   rQ   r_   rc   re   rg   ri   __classcell__)rV   s   @r   r   r   Q   s    
 !$BJ=== 	=
 = @= 
= =~2"2 2 &	2
 2 
2";,; &; %	;
 
; ;r!   r   N)r   r   rn   z'BlockProto.Dialog.DialogWidth.ValueTyperp   )#
__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   typesr   streamlit.cursorr   r   r   __annotations__r    r&   r   r5   r!   r   <module>r      sp    # : : " 4 H 2 9 5 4#'6 !;<Y <//,/02r;^ r;r!   