const React = require('react');
const PropTypes = require('prop-types');

// Default mock permissions
const defaultPermissions = [
  { Path: '/dashboard', Permission_Id: '1', ShowInMenu: true },
  { Path: '/users', Permission_Id: '1', ShowInMenu: true },
  { Path: '/user-profile', Permission_Id: '1', ShowInMenu: true },
  { Path: '/manage-users', Permission_Id: '1', ShowInMenu: true },
];

// Default mock user
const defaultUser = {
  user_email: 'test@example.com',
  user_role_id: '20',
};

// Mock context value
const mockContextValue = {
  user: defaultUser,
  permissions: defaultPermissions,
  login: () => {},
  logout: () => {},
  setUserPermissions: () => Promise.resolve(defaultPermissions),
  openRoleChangedPopup: false,
  setOpenRoleChangedPopup: () => {},
};

const UserContext = React.createContext(mockContextValue);

export const useUser = () => mockContextValue;

export const UserProvider = ({ children }) => {
  return React.createElement(
    UserContext.Provider,
    { value: mockContextValue },
    children
  );
};

UserProvider.propTypes = {
  children: PropTypes.node.isRequired,
};

export default UserContext;
