a
    Df!                     @  s   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mZ d	dlmZ erd dlmZ d dlmZ d dlmZ G dd dejZG dd de
ZG d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get_dist_path)state)Document)Model)Commc                   @  sx   e Zd ZejddZejdddZejddZ	ejdddZ
ejdddZejddd	d
ZejddZddddZdS )NotificationNdefault  T)r   constant )r   
precedencetype)r   r   labelFNone)returnc                 C  s,   ddl m} d| _| jjD ]}|| qd S )Nr
   )push_on_rootT)Znotebookr    
_destroyednotification_areaZ_models)selfr    ref r%   c/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/io/notifications.pydestroy&   s    zNotification.destroy)__name__
__module____qualname__paramColor
backgroundIntegerdurationStringiconmessage	Parameterr"   notification_typeBooleanr!   r'   r%   r%   r%   r&   r      s   r   c                      s   e Zd Zeji ddZejedZej	dg ddZ
ejddZeZd	Zd
ZdZ fddZd%ddddd fddZd&ddZd'ddZd(ddZd)ddZd*dd Zd!d" Zd#d$ Z  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)Z	item_typebottom-right)	r8   zbottom-leftzbottom-centerztop-leftz	top-rightz
top-centerzcenter-centerzcenter-leftzcenter-right)r   Zobjectsr   r   z
    <div id="pn-notifications" class="notifications" style="position: absolute; bottom: 0; ${position}: 0;">
    ${notifications}
    </div>
    notificationsTc                   s   t  jf i | i | _d S N)super__init___notification_watchers)r#   params	__class__r%   r&   r<   L   s    zNotificationAreaBase.__init__NzOptional[Document]zOptional[Comm]boolz'Model')r7   comm
preprocessr   c                   s   t  |||}| j D ]D\}}||td|d d|dd d|d dd	|id
 q|| j|< | |||ftj	|j
d < |S )Nz3
            var config = {
              message: r2   z,
              duration: r/   r   z#,
              notification_type: r   z,
              _destroyed: false
            }
            notifications.data.notifications.push(config)
            notifications.data.properties.notifications.change.emit()
            r9   )codeargsid)r;   get_root	js_eventsitemsZjs_on_eventr   getZ
_documentsr   Z_viewsr$   )r#   r7   rB   rC   rooteventnotificationr?   r%   r&   rG   P   s    
	


zNotificationAreaBase.get_rootr   c                 C  sH   | j |||| ||d}|j| jd| j|< | j| | jd |S )z7
        Sends a notification to the frontend.
        )r2   r/   r4   r"   r-   r1   r!   r9   )_notification_typer+   Zwatch_remove_notificationr=   r9   appendtrigger)r#   r2   r/   r   r-   r1   rM   r%   r%   r&   sendd   s    zNotificationAreaBase.sendc                 C  s   | j ||ddS )Nerrorr   rR   r#   r2   r/   r%   r%   r&   rS   s   s    zNotificationAreaBase.errorc                 C  s   | j ||ddS )NinforT   rU   rV   r%   r%   r&   rW   v   s    zNotificationAreaBase.infoc                 C  s   | j ||ddS )NsuccessrT   rU   rV   r%   r%   r&   rX   y   s    zNotificationAreaBase.successc                 C  s   | j ||ddS )NwarningrT   rU   rV   r%   r%   r&   rY   |   s    zNotificationAreaBase.warningc                 C  s    |  j d7  _ g | jd d < d S )Nr
   )_clearr9   )r#   r%   r%   r&   clear   s    zNotificationAreaBase.clearc                 C  s6   |j | jv r| j|j  |j j| j|j  d S r:   )objr9   remover+   Zunwatchr=   pop)r#   rL   r%   r%   r&   rO      s    z)NotificationAreaBase._remove_notification)NNT)r   NNN)r   )r   )r   )r   )r(   r)   r*   r+   DictrH   Listr   r9   ZSelectorpositionr.   rZ   rN   	_templateZ_extension_nameZ_NotificationAreaBase__abstractr<   rG   rR   rS   rW   rX   rY   r[   rO   __classcell__r%   r%   r?   r&   r6   -   s&     




r6   c                   @  s   e Zd Zejddddddddd	d
ddddgdZej dgZe	dd Z
e	dd Zdded dd iiZej ded gZe	dd ZdZdddddZed d! ZdS )"NotificationArearY   z#ffc107zfas fa-exclamation-triangleiZwhite)Z	classNameZtagNamecolor)r   r-   r1   rW   z#007bffzfas fa-info-circler   z/notyf@3/notyf.min.jsc                 C  s   t | S r:   )r   clsr%   r%   r&   __javascript__   s    zNotificationArea.__javascript__c                 C  s
   d| j iS )NZNotyf)ri   rg   r%   r%   r&   __js_skip__   s    zNotificationArea.__js_skip__pathsZnotyfr   Nz/notyf@3/notyf.min.csszfont-awesomec                 C  s   t | dt  dg S )Ncsszcss/notifications.css)r   r   rg   r%   r%   r&   __css__   s    
zNotificationArea.__css__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
      )renderr9   rZ   ra   c                 C  s   ddl m} ddlm}m}m}m}m} |ddd}|ddd	d
}|dg ddd}	|ddd}
|dd}|  }|j||||	|
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valueZDurationr   i'  )rw   rx   endType)rW   rY   rS   rX   ZcustomrW   )rw   optionsrx   r,   z#000000ZNotify)rw   )r9   msgr/   ntyperf   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()
            )rE   rD   )	Zlayoutrp   Zwidgetsrq   rr   rs   rt   ru   Zjs_on_click)rh   rp   rq   rr   rs   rt   ru   r|   r/   r}   r-   buttonr9   r%   r%   r&   demo   s$    
zNotificationArea.demo)r(   r)   r*   r+   r`   typesr   Znpm_cdnZ__javascript_raw__r	   ri   rj   Z__js_require__r   Z__css_raw__rn   rb   Z_scriptsclassmethodr   r%   r%   r%   r&   rd      sH   



 5rd   )
__future__r   typingr   r   r+   Zbokeh.modelsr   r   Zreactiver   utilr	   Z	datamodelr   r   	resourcesr   r   r   r   Zbokeh.documentr   Zbokeh.modelr   Zpyviz_commsr   ZParameterizedr   r6   rd   r%   r%   r%   r&   <module>   s$   \ 