import React, { useState, useEffect } from 'react';
import AdminSidebar from './AdminSidebar';
import EmployeeSidebar from './EmployeeSidebar';

const Sidebar = () => {
  const [user, setUserData] = useState(null);

  useEffect(() => {
    // Retrieve user data from localStorage
    const storedUserData = localStorage.getItem('loggedInUser');
    if (storedUserData) {
      setUserData(JSON.parse(storedUserData));
    }
  }, []);

  if (!user) return null; // Ensure user is not null before accessing its properties

  return user.role === 'admin' ? <AdminSidebar /> : <EmployeeSidebar />;
};

export default Sidebar;
