
    e                         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e          Z G 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                       e Zd ZU dZ ej        i d          Z ej        dgd          Z ej        ddid          Z	 ej        d	
          Z
e dgZeee                  ed<   eZ fdZ ej        dd          d             Z ej        dd          d             Z ej        dd          d             Zd Z x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-iconszThe CSS classes of the widget.favorite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                 b     t                      j        di | |                                  d S )N )super__init___render_icons)selfparams	__class__s     /lib/python3.11/site-packages/panel/chat/icon.pyr   zChatReactionIcons.__init__6   s8    ""6"""    optionsT)watchc                 r   i | _         | j                                        D ]e\  }}| j                            |d          }t          |||| j        v |d          }|j                            | j	        d           || j         |<   ft          | j                                                   | j        d d <   d S )N r   )iconactive_iconvaluenamemarginr#   )_rendered_iconsr   itemsactive_iconsgetr
   r#   paramr   _update_valuelistvalues
_composite)r   optionr!   r"   s       r   r   zChatReactionIcons._render_icons:   s    ! L..00 
	0 
	0LFD+//;;K'
*  D JT/999+/D ((!$"6"="="?"?@@r   r#   c                 `    | j                                         D ]\  }}|| j        v |_        d S N)r&   r'   r#   r   r/   r!   s      r   _update_iconszChatReactionIcons._update_iconsJ   s>     06688 	. 	.LFD4:-DJJ	. 	.r   r(   c                     | j                                         D ]%\  }}| j                            |d          |_        &d S )Nr    )r&   r'   r(   r)   r"   r2   s      r   _update_active_iconsz&ChatReactionIcons._update_active_iconsO   sP     06688 	A 	ALFD#044VR@@D	A 	Ar   c                     |j         j        }|j        }| j                                        }|r|| j        vr|                    |           n |s|| j        v r|                    |           || _        d S r1   )objr$   newr#   copyappendremove)r   eventreaction
icon_value	reactionss        r   r+   zChatReactionIcons._update_valueT   s    9>Y
JOO%%	 	'($*44X&&&& 	'DJ 6 6X&&&


r   )__name__
__module____qualname____doc__r*   Dictr(   r   css_classesr   r#   r   r   r   str__annotations__r   _composite_typer   dependsr   r3   r5   r+   __classcell__)r   s   @r   r   r      s         * 5:b /R S S SL %*&6%7=]^^^Kej*g!6 =- . . .G EJ2333E,4)Q)Q)Q(RL(49%RRRO     U]9D)))A A *)A U]7$'''. . ('. U]>...A A /.A      r   r   c                       e Zd ZU  ej        dd          Z ej        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.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>
    copy_to_clipboardz
        navigator.clipboard.writeText(`${data.value}`);
        data.fill = "currentColor";
        setTimeout(() => data.fill = "none", 50);
    zcss/chat_copy_icon.cssr   )r@   rA   rB   r*   Stringfillr#   	_template_scriptsr   r   r   r   rF   rG   r   r   r   rL   rL   _   s         5<,IJJJDEL+OPPPEI& $ & 	H -5)L)L)L(ML(49%MMMMMr   rL   )rC   typingr   r   r*   io.resourcesr   layoutr   reactiver   widgets.baser	   widgets.iconr
   r   rL   r   r   r   <module>rY      s     " ! ! ! ! ! ! !  # # # # # #       # # # # # # * * * * * * % % % % % %L L L L L L L L^N N N N N< N N N N Nr   