import { VIDEO_DURATION_VALUES } from '@/modules/editorial/editorialSearchFilter/constants';

export const getVideoDurationFilterEnumValue = (duration) => {
  if (!Object.values(duration).length) {
    return '';
  }

  return Object.entries(VIDEO_DURATION_VALUES).reduce((acc, item) => {
    const [name, value] = item;

    if (value.from === +duration.from && (!value.to || value.to === +duration.to)) {
      return name;
    }
    return acc;
  }, '');
};

export const isVideoAvailable = (clip) => {
  if (typeof clip !== 'object') {
    return false;
  }

  const { distributionStatus, videoStatus, contentOwner } = clip;

  return !(distributionStatus !== 'ACTIVE' || videoStatus !== 'ACTIVE' || !contentOwner);
};

export const reorderVideos = (list, startIndex, endIndex) => {
  const result = Array.from(list);
  const [removed] = result.splice(startIndex, 1);
  result.splice(endIndex, 0, removed);
  return result;
};

export default {};
