// This hook checks whether the current feed is a SelfServe List.
// @todo Remove this hook and all references to it after migrating to the new UI components.
import { useRouter } from 'next/router';

import { PCN_GET_SELF_SERVE_SOURCES } from '@/modules/@common/acl/constants';

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

import { useAppSelector } from '@/modules/@common/store/hooks';

export default function useIsSelfServeNewList() {
  const router = useRouter();
  const userPermissions = useAppSelector(getUserPermissionsSelector);

  const { params = [] } = router.query;
  const hasSelfServeSourcePermission = hasPermission(PCN_GET_SELF_SERVE_SOURCES, userPermissions);
  const isListOfFeedsViewRoute = params.length === 0;
  const shouldShowSelfServeList = hasSelfServeSourcePermission && isListOfFeedsViewRoute;

  return shouldShowSelfServeList;
}
