import React, { ReactNode } from 'react';
import classNames from 'classnames/bind';
import styles from './LoginContainer.scss';
import useLogin from '@src/hooks/useLogin';
import { Link } from 'react-router-dom';
import URLInfo from '@src/constants/URLInfo';
import { useSelector } from 'react-redux';

const cx = classNames.bind(styles);

interface IOwnProps {
  containerStyle?: React.CSSProperties | undefined;
  children: ReactNode;
};

const LoginContainer: React.FC<IOwnProps> = ({ containerStyle, children }) => {
  const { isLogin } = useLogin();
  const { isUserInfoLoaded } = useSelector(store => store.user);

  return (
    <div className={cx('login_container')}>
      {isLogin ? (
        children
      ) : (
        <div style={containerStyle}>
          {isUserInfoLoaded && (
            <>
              <strong className={cx('login_txt')}>로그인이 필요합니다.</strong>
              <Link to={URLInfo.getLoginUrl(location.href)} className={cx('login_link')}>로그인 하러가기</Link>
            </>
          )}
        </div>
      )}
    </div>
  );
};

export default LoginContainer;
