text: import isString from 'lodash.isstring';
  import { luckyNumberAnimationStep, luckyNumberPartCssMap } from '~/constants/luckyNumbers';
  
  export const getLuckyNumberPart = (cellClasses) => luckyNumberPartCssMap.find((item) => cellClasses.includes(item.key));
  
  /** Init the animation steps based on game settings cmoing from open message response */
  export const getAnimationSteps = (luckyNumbersDelay) =>
      luckyNumbersDelay.map(
          (item, index) => ({ className: luckyNumberAnimationStep[index], interval: item }),
      );
  
  // Caltulate animations delay by auth offset from AUTH in case of NMB round status
  export const getAnimationStepsByAuthOffset = (luckyNumbersDelay, authOffset) => {
      const steps = getAnimationSteps(luckyNumbersDelay);
  
      if (!authOffset) {
          return steps;
      }
  
      const modifiedSteps = steps.map((step) => {
          // For winning state after AUTH
          if (authOffset < 0) {
              return { ...step, interval: 0 };
          }
          // Reducing the default interval by auth offset on reduce default animation interval
          // Example if auth offset is 3500 we should wait 500 for next step 'displayLuckyNumbers',
          // and all after them should be reduced too
          // Previous steps should be reducde to the 0 just their time has gone
          if (authOffset < step.interval) {
              return { ...step, interval: step.interval - authOffset };
          }
  
          return { ...step, interval: 0 };
      });
  
      return modifiedSteps;
  };
  
  // Funcation to get total animation delay based on authOffset
  export const getTotalAnimationDelay = (delay, authOffset) => {
      const animationSteps = getAnimationStepsByAuthOffset(delay, authOffset);
      const totalDelay = animationSteps.slice(0, 3).reduce((sum, current) => sum + current.interval, 0);
      return totalDelay;
  };
  
  /**
   * Get Delay to show cell and content for current animation step.
   * This animation is for showing cells/numbers 1 after the othe, like cascading effect.
   * Every step needs diffferent delay, even if its 0.
   * example at displayLuckyNumbers, it needs a transition delay
   * Note: why note using SCSS for loop? cell numbers is dynamic for every animation step.
   * */
  export const getStepAnimationDelay = (cellIndex, stepIndex, stepCellClasses) => {
      let transitionDelay = 1;
      if (stepIndex >= 0) {
          // order if based on last to show
          if (stepCellClasses.displayLuckyNumbers) {
              transitionDelay = cellIndex * 80;
          } else if (stepCellClasses.displayEmptyCell) {
              transitionDelay = cellIndex * 150;
          }
      }
  
      return transitionDelay;
  };
  
  /**
   * Get the step active animation classes to be used,
   * and add number of cell as a class too
   * */
  export const getCellClasses = (index, stepIndex, stepCellClasses) => {
      const nextCellClasses = { ...stepCellClasses };
      nextCellClasses[index] = true;
  
      return nextCellClasses;
  };
  
  /** Init the animation steps based on game settings coming from admin portal */
  export const adaptLuckyNumbersDelay = (csvDelays) => {
      if (isString(csvDelays)) {
          return csvDelays.split(',').map((item) => parseInt(item || '0', 10));
      }
  
      return [0, 10000, 1000, 6000, 9000];
  };
  