import { ACCESS_SETTING, UserDataState } from '@pos/base';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import IndexLog from './components/index-log';

export default function LogSetting() {
  const user = useRecoilValue(UserDataState);
  const navigate = useNavigate();

  function checkAllowAccessSetting() {
    const username = user?.username;
    const accessSetting = ACCESS_SETTING ?? '';

    const allowList = accessSetting.split('|');
    if (allowList.includes(username)) return true;
    return false;
  }

  useEffect(() => {
    if (!checkAllowAccessSetting()) {
      navigate('/app');
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  return (
    <div>
      <IndexLog />
    </div>
  );
}
