export const isVideoUnsafe = (video) => (video?.keywords ?? []).some((keyword) => keyword.category === 'BRAND_SAFETY');

export const getPercent = (partialValue = 0, totalValue = 0) =>
  totalValue <= 0 ? 0 : (partialValue * 100) / totalValue;

export const getTime = (time) => {
  const MAX_TIME_VALUE = 359999;
  if (time > MAX_TIME_VALUE) {
    return 'N/A';
  }
  const secNum = parseInt(time, 10);
  let hours = Math.floor(secNum / 3600);
  let minutes = Math.floor((secNum - hours * 3600) / 60);
  let seconds = secNum - hours * 3600 - minutes * 60;

  if (hours < 10) {
    hours = `0${hours}`;
  }
  if (minutes < 10) {
    minutes = `0${minutes}`;
  }
  if (seconds < 10) {
    seconds = `0${seconds}`;
  }
  return `${hours}:${minutes}:${seconds}`;
};
