import {
  TYPE_INTELLIGENT,
  TYPE_INTELLIGENT_AMP,
  TYPE_OUTSTREAM,
  TYPE_STORIES,
  TYPE_STORIES_AMP,
  TYPE_VERTICAL,
} from '@/modules/@common/constants/playerTypes';
import { FLOATING_PAGE_WIDTH_MODE, FLOATING_PAGE_WIDTH_WITH_PILLARBOXING } from '@/modules/players/Editor/constants';

export const isIntelligentType = (id) => TYPE_INTELLIGENT === id;
export const isIntelligentAmpType = (id) => TYPE_INTELLIGENT_AMP === id;
export const isVerticalType = (id) => TYPE_VERTICAL === id;
export const isStoriesTypes = (id) => [TYPE_STORIES, TYPE_STORIES_AMP].includes(id);
export const isAmpTypes = (id) => [TYPE_INTELLIGENT_AMP, TYPE_STORIES_AMP].includes(id);
export const isOutstreamType = (id) => TYPE_OUTSTREAM === id;

export const getDefaultFloatingMobilePosition = (style, options) => {
  const filterField = [FLOATING_PAGE_WIDTH_MODE, FLOATING_PAGE_WIDTH_WITH_PILLARBOXING].includes(style)
    ? 'isDefaultForPageWidth'
    : 'isDefault';
  return options.find((option) => option[filterField])?.value;
};

export const getDependentFieldsDefaultValuesObj = (value, options) => {
  const option = options.find((option$) => option$.value === value);
  if (option.dependentFieldsDefaults) {
    return option.dependentFieldsDefaults;
  }
  return {};
};

export const castToInt = (value) => Math.floor(+value.replace(/^0+/, '')) || 0;
