o
    e                     @  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                      sR   e Zd ZdZdZ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 )'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_widthr   strr   'Literal['primary', 'secondary', 'stop']r   Literal['sm', 'lg'] | Noner   
str | Noner   r   boolr   r   r   list[str] | str | Noner   
int | Noner   c                  sN   t  j|f||||||||	|
|d
| tjd ur |   d S 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__ ND:\Projects\ConvertPro\env\Lib\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)fnZinputsZoutputsZ_js)Zclick_js_open_if_not_logged_inZattach_load_event_check_login_status)r$   r(   r(   r)   r!   >   s   zLoginButton.activaterequestr	   returndict[str, Any]c                 C  sX   t |dd pt |jdd }|d u sd|vr| jdddS |d d }| jd| ddS )	NsessionZoauth_profiler   T)r   Zpreferred_usernamezSigned in as F)getattrr-   update)r$   r-   r0   usernamer(   r(   r)   r,   F   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/   )	__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');
        }
    }
}
)r7   
__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