o
    e~#g                      @  s   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZ dd	lmZ e	rDdd
lmZ e G dd deZdZdS )zAPredefined button to sign in with Hugging Face in a Gradio Space.    )annotationsN)Sequence)TYPE_CHECKINGLiteral)document)Button	Component)get_blocks_context)Request)Timerc                      s^   e Zd ZdZdZ		d,dddddddddddddddd- fd#d$Zd%d& Zd.d*d+Z  ZS )/LoginButtonzY
    Creates a button that redirects the user to Sign with Hugging Face using OAuth.
    TSign in with Hugging FaceLogout ({})NhuggingfacezAhttps://huggingface.co/front/assets/huggingface_logo-noborder.svgeveryinputsvariantsizeiconlinkvisibleinteractiveelem_idelem_classesrenderkeyscale	min_widthvaluestrlogout_valuer   Timer | float | Noner   7Component | Sequence[Component] | set[Component] | Noner   6Literal['primary', 'secondary', 'stop', 'huggingface']r   Literal['sm', 'lg'] | Noner   
str | Noner   r   boolr   r   r   list[str] | str | Noner   r   int | str | Noner   
int | Noner   c                  sP   || _ t j||||||||	|
||||||d t r!|   dS td dS )z
        Parameters:
            logout_value: The text to display when the user is signed in. The string should contain a placeholder for the username with a call-to-action to logout, e.g. "Logout ({})".
        r   zoLoginButton created outside of a Blocks context. May not work unless you call its `activate()` method manually.N)r!   super__init__r	   activatewarningswarn)selfr   r!   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	__class__ /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/gradio/components/login_button.pyr,      s.   zLoginButton.__init__c                 C  s:   t dt| j}| jd | gd |d | | jd  d S )NBUTTON_DEFAULT_VALUE)fnr   outputsjs)_js_handle_redirectreplacejsondumpsr   clickattach_load_event_check_login_status)r0   _jsr3   r3   r4   r-   O   s
   zLoginButton.activaterequestr
   returnc                 C  s   t |dd pt |jdd }|d u sd|vrt| jddS |d }|d}|d ur<|t k r<|dd  t| jddS |d d }t| j|ddS )Nsession
oauth_infoT)r   
expires_atuserinfopreferred_username)	getattrrA   r   r   gettimepopr!   format)r0   rA   rC   rD   rE   usernamer3   r3   r4   r?   Z   s   
zLoginButton._check_login_status)r   r   ) r   r    r!   r    r   r"   r   r#   r   r$   r   r%   r   r&   r   r&   r   r'   r   r'   r   r&   r   r(   r   r'   r   r)   r   r*   r   r*   )rA   r
   rB   r   )	__name__
__module____qualname____doc__is_templater,   r-   r?   __classcell__r3   r3   r1   r4   r      s.    2r   a  
(buttonValue) => {
    uri = buttonValue === BUTTON_DEFAULT_VALUE ? '/login/huggingface' : '/logout';
    window.parent?.postMessage({ type: "SET_SCROLLING", enabled: true }, "*");
    setTimeout(() => {
        window.location.assign(uri + window.location.search);
    }, 500);
}
)rQ   
__future__r   r;   rJ   r.   collections.abcr   typingr   r   gradio_client.documentationr   gradio.componentsr   r   gradio.contextr	   gradio.routesr
   r   r   r9   r3   r3   r3   r4   <module>   s     ]