import { HUB_ADMIN_ROLE } from '@/modules/@common/user/constants/roles';

import {
  getPublisherIdsSelector,
  getUserAccountSelector,
  getUserRoleSelector,
} from '@/modules/@common/user/redux/selectors';

export function shouldAddAllOptionsSelector(state) {
  const userRole = getUserRoleSelector(state);
  const userAccount = getUserAccountSelector(state);
  const userHubsIds = getPublisherIdsSelector(state);

  if (!userAccount) return true;

  const userHubs = userAccount.publishers.filter((hub) => userHubsIds.includes(hub.id));
  const isAllHubsMatched = userAccount.publishers.length > 1 && userAccount.publishers.length === userHubs.length;
  const isNotHubAdmin = userRole?.name !== HUB_ADMIN_ROLE;

  return isAllHubsMatched && isNotHubAdmin;
}
