import React from 'react';
import { useState } from 'react';
import EducoderAccount from '../EducoderAccount';

function Profile({
  children,
  sureFunc,
  showCompeleteDialog , 
  completeProfile, 
  className , 
  current_user
}) {
  const [ giteaVisible , setGiteaVisible ] = useState(false);
 
  function checkProfile() {
    if(current_user && current_user.login){
      if(!current_user.has_gitea_user || (current_user.has_gitea_user && !current_user.is_sync_pwd)){
        setGiteaVisible(true);
      }else{
        if(!completeProfile){
          showCompeleteDialog && showCompeleteDialog();
        }else{
          sureFunc();
        }
      }
    }
  }

  return(
    <React.Fragment>
      <EducoderAccount visible={giteaVisible} onCancel={()=>setGiteaVisible(false)} current_user={current_user}/>
      <a className={className} onClick={checkProfile}>{children}</a>
    </React.Fragment>
  )
}
export default Profile;