a
    d                     @  s   d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ e	d	 e G d
d deZdZdS )zAPredefined button to sign in with Hugging Face in a Gradio Space.    )annotationsN)AnyLiteral)documentset_documentation_group)Button)Context)Request	componentc                      sp   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ddddddd fddZdd ZdddddZ  ZS )LoginButtonzO
    Button that redirects the user to Sign with Hugging Face using OAuth.
    TSign in with Hugging FaceZ	secondaryNzAhttps://huggingface.co/front/assets/huggingface_logo-noborder.svgr   )valuevariantsizeiconlinkvisibleinteractiveelem_idelem_classesscale	min_widthstrz'Literal['primary', 'secondary', 'stop']zLiteral['sm', 'lg'] | Nonez
str | Noneboolzlist[str] | str | Nonez
int | Nonec                  sL   t  j|f||||||||	|
|d
| tjd ur>|   n
td d S )N)
r   r   r   r   r   r   r   r   r   r   zoLoginButton created outside of a Blocks context. May not work unless you call its `activate()` method manually.)super__init__r   Z
root_blockactivatewarningswarn)selfr   r   r   r   r   r   r   r   r   r   r   kwargs	__class__ g/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/gradio/components/login_button.pyr      s*    

zLoginButton.__init__c                 C  s&   | j d | gd td | | jd  d S )N)fninputsoutputsZ_js)Zclick_js_open_if_not_logged_inZattach_load_event_check_login_status)r   r#   r#   r$   r   >   s    zLoginButton.activater	   zdict[str, Any])requestreturnc                 C  s\   t |dd pt |jdd }|d u s*d|vr8| jdddS |d d }| jd| ddS d S )	NsessionZoauth_profiler   T)r   Zpreferred_usernamezSigned in as F)getattrr*   update)r   r*   r,   usernamer#   r#   r$   r)   F   s    zLoginButton._check_login_status)	__name__
__module____qualname____doc__Zis_templater   r   r)   __classcell__r#   r#   r!   r$   r      s    *&r   a  
(buttonValue) => {
    if (!buttonValue.includes("Signed in")) {
        if ( window !== window.parent ) {
            window.open('/login/huggingface', '_blank');
        } else {
            window.location.assign('/login/huggingface');
        }
    }
}
)r3   
__future__r   r   typingr   r   Zgradio_client.documentationr   r   Zgradio.componentsr   Zgradio.contextr   Zgradio.routesr	   r   r(   r#   r#   r#   r$   <module>   s   D