a
    pDf"                     @   s|   d 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 G d
d deZG dd de
ZdS )zL
The icon module provides a low-level API for rendering chat related icons.
    )ClassVarListN   )CDN_DIST)Column)ReactiveHTML)CompositeWidget)
ToggleIconc                       s   e Zd ZU dZeji ddZejdgddZejddiddZ	ejd	d
Z
e dgZeee  ed< eZ fddZejddddd Zejddddd Zejddddd Zdd Z  ZS )ChatReactionIconsa  
    A widget to display reaction icons that can be clicked on.

    Parameters
    ----------
    value : List
        The selected reactions.
    options : Dict
        A key-value pair of reaction values and their corresponding tabler icon names
        found on https://tabler-icons.io.
    active_icons : Dict
        The mapping of reactions to their corresponding active icon names;
        if not set, the active icon name will default to its "filled" version.

    Reference: https://panel.holoviz.org/reference/chat/ChatReactionIcons.html

    :Example:

    >>> ChatReactionIcons(value=["like"], options={"like": "thumb-up", "dislike": "thumb-down"})
    z
        The mapping of reactions to their corresponding active icon names.
        If not set, the active icon name will default to its "filled" version.defaultdoczreaction-iconsThe CSS classes of the widget.ZfavoriteZheartz
        A key-value pair of reaction values and their corresponding tabler icon names
        found on https://tabler-icons.io.zThe active reactions.)r   zcss/chat_reaction_icons.css_stylesheetsc                    s   t  jf i | |   d S N)super__init___render_icons)selfparams	__class__ \/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/chat/icon.pyr   6   s    zChatReactionIcons.__init__optionsT)watchc                 C   sz   i | _ | j D ]L\}}| j|d}t|||| jv dd}||_|j	| j
d || j |< qt| j  | jd d < d S )N r   )iconactive_iconvaluemarginr   )_rendered_iconsr   itemsactive_iconsgetr	   r   	_reactionparamr   _update_valuelistvaluesZ
_composite)r   optionr   r   r   r   r   r   :   s    zChatReactionIcons._render_iconsr   c                 C   s$   | j  D ]\}}|| jv |_q
d S r   )r!   r"   r   r   r*   r   r   r   r   _update_iconsJ   s    zChatReactionIcons._update_iconsr#   c                 C   s(   | j  D ]\}}| j|d|_q
d S )Nr   )r!   r"   r#   r$   r   r+   r   r   r   _update_active_iconsO   s    z&ChatReactionIcons._update_active_iconsc                 C   sT   |j j}|j}| j }|r2|| jvr2|| n|sJ|| jv rJ|| || _d S r   )objr%   newr   copyappendremove)r   eventZreactionZ
icon_valueZ	reactionsr   r   r   r'   T   s    

zChatReactionIcons._update_value)__name__
__module____qualname____doc__r&   Dictr#   r   css_classesr   r   r   r   r   str__annotations__r   Z_composite_typer   dependsr   r,   r-   r'   __classcell__r   r   r   r   r
      s   



r
   c                   @   sb   e Zd ZU ejdddZejdddZejdgddZdZ	d	d
iZ
e dgZeee  ed< dS )ChatCopyIconnonezThe fill color of the icon.r   Nz"The text to copy to the clipboard.z	copy-iconr   a  
        <div
            type="button"
            id="copy-button"
            onclick="${script('copy_to_clipboard')}"
            style="cursor: pointer; width: ${model.width}px; height: ${model.height}px;"
            title="Copy message to clipboard"
        >
            <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" id="copy-icon"
                width="${model.width}" height="${model.height}" viewBox="0 0 24 24"
                stroke-width="2" stroke="currentColor" fill=${fill} stroke-linecap="round" stroke-linejoin="round"
            >
                <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                <path d="M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z"></path>
                <path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
            </svg>
        </div>
    Zcopy_to_clipboardz
        navigator.clipboard.writeText(`${data.value}`);
        data.fill = "currentColor";
        setTimeout(() => data.fill = "none", 50);
    zcss/chat_copy_icon.cssr   )r4   r5   r6   r&   Stringfillr   r   r9   	_templateZ_scriptsr   r   r   r:   r;   r   r   r   r   r>   _   s   
r>   )r7   typingr   r   r&   Zio.resourcesr   Zlayoutr   Zreactiver   Zwidgets.baser   Zwidgets.iconr	   r
   r>   r   r   r   r   <module>   s   O