import noop from 'lodash/noop';
import { useCreation } from 'ahooks';

import LoggedIn from './components/logged-in';
import UnLogin from './components/un-login';
import type { Locale, Session } from '../type';
import { PROFILE_URL } from '../Util/constant';

export interface SessionUserProps {
  session: Session;
  onBindWallet?: () => void;
  locale?: Locale;
  size?: number;
  popperType?: 'hover' | 'click';
  profileUrl?: string;
}

export default function SessionUser({
  session,
  onBindWallet = noop,
  locale = 'en',
  size = 24,
  popperType = 'click',
  profileUrl = PROFILE_URL,
}: SessionUserProps) {
  const isBlocklet = useCreation(() => {
    return !!globalThis?.blocklet;
  }, []);

  if (session.user) {
    return (
      <LoggedIn
        isBlocklet={isBlocklet}
        session={session}
        onBindWallet={onBindWallet}
        locale={locale}
        size={size}
        popperType={popperType}
        profileUrl={profileUrl}
      />
    );
  }
  return <UnLogin session={session} locale={locale} size={size} />;
}
