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';

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

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

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