import { useSelector } from 'react-redux';
import { useRouter } from 'next/router';

import { PCN_POST_LIVE_EVENTS, PCN_PUT_LIVE_EVENTS } from '@/modules/@common/acl/constants';

import { hasPermission } from '@/modules/@common/user/helpers';
import { getUserPermissionsSelector } from '@/modules/@common/user/redux/selectors';

export default function useIsAllowedToCreateOrEdit() {
  const router = useRouter();
  const { id } = router.query;
  const userPermissions = useSelector(getUserPermissionsSelector);
  const isAllowedToCreateOrEdit = +id
    ? hasPermission(PCN_PUT_LIVE_EVENTS, userPermissions)
    : hasPermission(PCN_POST_LIVE_EVENTS, userPermissions);

  return isAllowedToCreateOrEdit;
}
