
    Be!                       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 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)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 )Nr9   )super__init___notification_watchers)r&   params	__class__s     r(   rC   zNotificationAreaBase.__init__K   s.    ""6"""&(###r*   Nr<   Optional[Document]commOptional[Comm]
preprocessboolr   'Model'c                B   t                                          |||          }| j                                        D ]V\  }}|                    |t          d|d         d|                    dd           d|d         dd	|i
                     W|| j        |<   |S )Nz3
            var config = {
              message: r5   z,
              duration: r2   r   z#,
              notification_type: r   z,
              _destroyed: false
            }
            notifications.data.notifications.push(config)
            notifications.data.properties.notifications.change.emit()
            r@   )codeargs)rB   get_root	js_eventsitemsjs_on_eventr   get
_documents)r&   r<   rH   rJ   rooteventnotificationrF   s          r(   rP   zNotificationAreaBase.get_rootO   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  $r*   r   c                    |                      |||| ||          }|j                            | j        d          | j        |<   | j                            |           | j                            d           |S )z7
        Sends a notification to the frontend.
        )r5   r2   r7   r$   r0   r4   r#   r@   )_notification_typer.   watch_remove_notificationrD   r@   appendtrigger)r&   r5   r2   r   r0   r4   rX   s          r(   sendzNotificationAreaBase.sendc   s     ..h$"z / 
 

 $$T%>MM 	#L1 	!!,///
?+++r*   c                2    |                      ||d          S )Nerrorr   r_   r&   r5   r2   s      r(   ra   zNotificationAreaBase.errorr   s    yy(y999r*   c                2    |                      ||d          S )Ninforb   rc   rd   s      r(   rf   zNotificationAreaBase.infou   s    yy(y888r*   c                2    |                      ||d          S )Nsuccessrb   rc   rd   s      r(   rh   zNotificationAreaBase.successx       yy(y;;;r*   c                2    |                      ||d          S )Nwarningrb   rc   rd   s      r(   rk   zNotificationAreaBase.warning{   ri   r*   c                >    | xj         dz  c_         g | j        d d <   d S )Nr   )_clearr@   )r&   s    r(   clearzNotificationAreaBase.clear~   s)    q "111r*   c                    |j         | j        v r| j                            |j                    |j         j                            | j                            |j                              d S N)objr@   remover.   unwatchrD   pop)r&   rW   s     r(   r\   z)NotificationAreaBase._remove_notification   s\    9***%%ei000	 ; ? ?	 J JKKKKKr*   )NNT)r<   rG   rH   rI   rJ   rK   r   rL   )r   NNN)r   )r+   r,   r-   r.   DictrQ   Listr   r@   Selectorpositionr1   rm   rZ   	_template_extension_name_NotificationAreaBase__abstractrC   rP   r_   ra   rf   rh   rk   rn   r\   __classcell__)rF   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 )NotificationAreark   z#ffc107zfas fa-exclamation-triangleiwhite)	classNametagNamecolor)r   r0   r4   rf   z#007bffzfas fa-info-circler   z/notyf@3/notyf.min.jsc                     t          |           S rp   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
      )renderr@   rm   rx   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)rf   rk   ra   rh   customrf   )r   optionsr   r/   z#000000Notify)r   )r@   msgr2   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()
            )rO   rN   )	layoutr   widgetsr   r   r   r   r   js_on_click)r   r   r   r   r   r   r   r   r2   r   r0   buttonr@   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.   rv   typesr   npm_cdn__javascript_raw__r
   r   r   __js_require__r   __css_raw__r   ry   _scriptsclassmethodr   r9   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   bokeh.documentr   bokeh.modelr   pyviz_commsr   Parameterizedr   r;   r~   r9   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*   