
    er!                    (   d dl mZ d dlmZmZ d dl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mZ d	dlmZ erd dlmZ d dlmZ d dlmZ  G d dej                  Z G d de
          Z G d de          Z ee          ee<   dS )    )annotations)TYPE_CHECKINGOptionalN)CustomJS   )config)ReactiveHTML)classproperty   )_DATA_MODELSconstruct_data_model)CSS_URLSbundled_files)state)Document)Model)Commc                     e Zd Z ej        d          Z ej        dd          Z ej        d          Z	 ej        dd          Z
 ej        dd          Z ej        ddd	
          Z ej        d          ZddZdS )NotificationNdefault  T)r   constant )r   
precedencetype)r   r   labelFreturnNonec                T    ddl m} d| _        | j        j        D ]} ||           d S )Nr   )push_on_rootT)notebookr"   
_destroyednotification_area_models)selfr"   refs      6lib/python3.11/site-packages/panel/io/notifications.pydestroyzNotification.destroy&   sM    ******)1 	 	CL	 	    )r   r    )__name__
__module____qualname__paramColor
backgroundIntegerdurationStringiconmessage	Parameterr%   notification_typeBooleanr$   r*    r+   r)   r   r      s        T***Ju}TD999H5<%%%Del2555G'"EEE$TDOOOu---J     r+   r   c                      e Zd Z ej        i d          Z ej        e          Z ej	        dg d          Z
 ej        d          ZeZd	Zd
ZdZ fdZ	 	 dd  fdZd!dZd"dZd"dZd"dZd"dZd Zd Z xZS )#NotificationAreaBasea  
        A dictionary that configures notifications for specific Bokeh Document
        events, e.g.:

          {'connection_lost': {'type': 'error', 'message': 'Connection Lost!', 'duration': 5}}

        will trigger a warning on the Bokeh ConnectionLost event.)r   doc)	item_typebottom-right)	r?   zbottom-leftzbottom-centerztop-leftz	top-rightz
top-centerzcenter-centerzcenter-leftzcenter-right)r   objectsr   r   z
    <div id="pn-notifications" class="notifications" style="position: absolute; bottom: 0; ${position}: 0;">
    ${notifications}
    </div>
    notificationsTc                H     t                      j        di | i | _        d S )Nr:   )super__init___notification_watchers)r'   params	__class__s     r)   rD   zNotificationAreaBase.__init__L   s.    ""6"""&(###r+   Nr=   Optional[Document]commOptional[Comm]
preprocessboolr   'Model'c                ~   t                                          |||          }| j                                        D ]V\  }}|                    |t          d|d         d|                    dd           d|d         dd	|i
                     W|| j        |<   | |||ft          j	        |j
        d         <   |S )Nz3
            var config = {
              message: r6   z,
              duration: r3   r   z#,
              notification_type: r   z,
              _destroyed: false
            }
            notifications.data.notifications.push(config)
            notifications.data.properties.notifications.change.emit()
            rA   )codeargsid)rC   get_root	js_eventsitemsjs_on_eventr   get
_documentsr   _viewsr(   )r'   r=   rI   rK   rooteventnotificationrG   s          r)   rR   zNotificationAreaBase.get_rootP   s     wwT:66#'>#7#7#9#9 
	0 
	0E<OOE8 	2$Y/	2 	2 &))*a88	2 	2 #/v"6		2 	2 	2 '-	$/ 	$/ 	$/ 	0 	0 	0 	0  $(,dC'>TXd^$r+   r   c                    |                      |||| ||          }|j                            | j        d          | j        |<   | j                            |           | j                            d           |S )z7
        Sends a notification to the frontend.
        )r6   r3   r8   r%   r1   r5   r$   rA   )_notification_typer/   watch_remove_notificationrE   rA   appendtrigger)r'   r6   r3   r   r1   r5   r[   s          r)   sendzNotificationAreaBase.sendd   s     ..h$"z / 
 

 $$T%>MM 	#L1 	!!,///
?+++r+   c                2    |                      ||d          S )Nerrorr   rb   r'   r6   r3   s      r)   rd   zNotificationAreaBase.errors   s    yy(y999r+   c                2    |                      ||d          S )Ninfore   rf   rg   s      r)   ri   zNotificationAreaBase.infov   s    yy(y888r+   c                2    |                      ||d          S )Nsuccessre   rf   rg   s      r)   rk   zNotificationAreaBase.successy       yy(y;;;r+   c                2    |                      ||d          S )Nwarningre   rf   rg   s      r)   rn   zNotificationAreaBase.warning|   rl   r+   c                >    | xj         dz  c_         g | j        d d <   d S )Nr   )_clearrA   )r'   s    r)   clearzNotificationAreaBase.clear   s)    q "111r+   c                    |j         | j        v r| j                            |j                    |j         j                            | j                            |j                              d S N)objrA   remover/   unwatchrE   pop)r'   rZ   s     r)   r_   z)NotificationAreaBase._remove_notification   s\    9***%%ei000	 ; ? ?	 J JKKKKKr+   )NNT)r=   rH   rI   rJ   rK   rL   r   rM   )r   NNN)r   )r,   r-   r.   r/   DictrS   Listr   rA   Selectorpositionr2   rp   r]   	_template_extension_name_NotificationAreaBase__abstractrD   rR   rb   rd   ri   rk   rn   rq   r_   __classcell__)rG   s   @r)   r<   r<   -   s       
2 ,E F F FI EJ666Mu~n ? ? ?   H
 U]1%%%F%I &OJ) ) ) ) )
 FJ      (   : : : :9 9 9 9< < < << < < <# # #L L L L L L Lr+   r<   c            	          e Zd Z ej        ddddddddd	d
ddddg          Zej         dgZe	d             Z
e	d             Zdded         dd         iiZej         ded         gZe	d             ZdZdddddZed             ZdS )NotificationArearn   z#ffc107zfas fa-exclamation-triangleiwhite)	classNametagNamecolor)r   r1   r5   ri   z#007bffzfas fa-info-circler   z/notyf@3/notyf.min.jsc                     t          |           S rs   r   clss    r)   __javascript__zNotificationArea.__javascript__   s    S!!!r+   c                    d| j         iS )NNotyf)r   r   s    r)   __js_skip__zNotificationArea.__js_skip__   s    +,,r+   pathsnotyfr   Nz/notyf@3/notyf.min.csszfont-awesomec                "    t          | d          S )Ncssr   r   s    r)   __css__zNotificationArea.__css__   s    S%(((r+   r   z
        var [y, x] = data.position.split('-')
        state.toaster = new Notyf({
          dismissible: true,
          position: {x: x, y: y},
          types: data.types
        })
      a#  
        var notification = state.current || data.notifications[data.notifications.length-1]
        if (notification._destroyed) {
          return
        }
        var config = {
          duration: notification.duration,
          type: notification.notification_type,
          message: notification.message
        }
        if (notification.background != null) {
          config.background = notification.background;
        }
        if (notification.icon != null) {
          config.icon = notification.icon;
        }
        var toast = state.toaster.open(config);
        function destroy() {
          if (state.current !== notification) {
            notification._destroyed = true;
          }
        }
        toast.on('dismiss', destroy)
        if (notification.duration) {
          setTimeout(destroy, notification.duration)
        }
        if (notification.properties === undefined)
          return
        view.connect(notification.properties._destroyed.change, function () {
          state.toaster.dismiss(toast)
        })
      zstate.toaster.dismissAll()z
        script('_clear');
        script('render');
        for (notification of data.notifications) {
          state.current = notification;
          script('notifications');
        }
        state.current = undefined
      )renderrA   rp   r{   c                    ddl m} ddlm}m}m}m}m}  |dd          } |ddd	
          } |dg dd          }	 |dd          }
 |d          } |             }|                    ||||	|
dd            ||||	|
||          S )zH
        Generates a layout which allows demoing the component.
        r   )Column)ButtonColorPickerNumberInputSelect	TextInputMessagezThis is a message)namevalueDurationr   i'  )r   r   endType)ri   rn   rd   rk   customri   )r   optionsr   r0   z#000000Notify)r   )rA   msgr3   ntyper   a  
            var config = {
              message: msg.value,
              duration: duration.value,
              notification_type: ntype.value,
              _destroyed: false
            }
            if (ntype.value === 'custom') {
              config.background = color.color
            }
            notifications.data.notifications.push(config)
            notifications.data.properties.notifications.change.emit()
            )rP   rO   )	layoutr   widgetsr   r   r   r   r   js_on_click)r   r   r   r   r   r   r   r   r3   r   r1   buttonrA   s                r)   demozNotificationArea.demo   s5   
 	$#####	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 iY.ABBB;JaUCCC!R!R!R
 
 
 ![gY???
X&&&!.s 	 	 	
 	
 	
& vc8UJNNNr+   )r,   r-   r.   r/   ry   typesr   npm_cdn__javascript_raw__r
   r   r   __js_require__r   __css_raw__r   r|   _scriptsclassmethodr   r:   r+   r)   r   r      si       EJ 7 	
 	
  . 	
 	
    E& $^BBBC" " ]" - - ]- 	'-a0"56N
 >111 K
 ) ) ]) I

@ -
U3 3Hj %O %O [%O %O %Or+   r   )
__future__r   typingr   r   r/   bokeh.modelsr   r   reactiver	   utilr
   	datamodelr   r   	resourcesr   r   r   bokeh.documentr   bokeh.modelr   pyviz_commsr   Parameterizedr   r<   r   r:   r+   r)   <module>r      s   " " " " " " * * * * * * * *  ! ! ! ! ! !       # # # # # #             9 9 9 9 9 9 9 9 . . . . . . . .       !''''''!!!!!!          5&   .YL YL YL YL YL< YL YL YLxIO IO IO IO IO+ IO IO IOZ 21,??\   r+   