"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.parsePropertyObject = parsePropertyObject;

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

var EASING_VALUES = {
  regular: 'cubic-bezier(0.35, 0, 0.1, 1)',
  entry: 'cubic-bezier(0.1, 0, 0, 1)',
  exit: 'cubic-bezier(0.3, 0, 1, 0.8)',
  linear: 'linear'
};
var DURATION_VALUES = {
  instant: '0ms',
  quick1: '80ms',
  quick2: '120ms',
  moderate1: '180ms',
  moderate2: '260ms',
  gentle1: '320ms',
  gentle2: '400ms'
};
var TRANSLATE_VALUES = {
  xxs: '4px',
  xs: '8px',
  s: '16px',
  m: '24px',
  l: '40px',
  xl: '64px',
  '-xxs': '-4px',
  '-xs': '-8px',
  '-s': '-16px',
  '-m': '-24px',
  '-l': '-40px',
  '-xl': '-64px'
};
var DEFAULT_EASING_VALUE = EASING_VALUES['regular'];
var DEFAULT_DURATION_VALUE = DURATION_VALUES['instant'];
var DEFAULT_OPACITY_VALUE = '1';
var DEFAULT_TRANSLATE_VALUE = '0px';
var DEFAULT_SCALE_VALUE = '1';
var DEFAULT_TRANSFORM_ORIGIN_VALUE = 'center';
var DEFAULT_WIDTH_HEIGHT_VALUE = 'auto';

function parsePropertyObject(_ref) {
  var _transform$scaleX, _transform$scaleY;

  var className = _ref.className,
      duration = _ref.duration,
      easing = _ref.easing,
      transform = _ref.transform,
      width = _ref.width,
      height = _ref.height,
      opacity = _ref.opacity;
  var translateX = getTranslateValue(transform === null || transform === void 0 ? void 0 : transform.translateX);
  var translateY = getTranslateValue(transform === null || transform === void 0 ? void 0 : transform.translateY);
  var scaleX = getScaleValue((_transform$scaleX = transform === null || transform === void 0 ? void 0 : transform.scaleX) !== null && _transform$scaleX !== void 0 ? _transform$scaleX : transform === null || transform === void 0 ? void 0 : transform.scale);
  var scaleY = getScaleValue((_transform$scaleY = transform === null || transform === void 0 ? void 0 : transform.scaleY) !== null && _transform$scaleY !== void 0 ? _transform$scaleY : transform === null || transform === void 0 ? void 0 : transform.scale);
  return {
    className: className || '',
    transform: {
      value: getTransformValue({
        translateX: translateX,
        translateY: translateY,
        scaleX: scaleX,
        scaleY: scaleY
      }),
      duration: getDurationValue((transform === null || transform === void 0 ? void 0 : transform.duration) || duration),
      easing: getEasingValue((transform === null || transform === void 0 ? void 0 : transform.easing) || easing),
      origin: getTransformOriginValue(transform),
      translateX: translateX,
      translateY: translateY,
      scaleX: scaleX,
      scaleY: scaleY
    },
    width: {
      value: getWidthHeightValue(_typeof(width) === 'object' ? width.value : width),
      duration: getDurationValue(_typeof(width) === 'object' && width.duration || duration),
      easing: getEasingValue(_typeof(width) === 'object' && width.easing || easing)
    },
    height: {
      value: getWidthHeightValue(_typeof(height) === 'object' ? height.value : height),
      duration: getDurationValue(_typeof(height) === 'object' && height.duration || duration),
      easing: getEasingValue(_typeof(height) === 'object' && height.easing || easing)
    },
    opacity: {
      value: getOpacityValue(_typeof(opacity) === 'object' ? opacity.value : opacity),
      duration: getDurationValue(_typeof(opacity) === 'object' && opacity.duration || duration),
      easing: getEasingValue(_typeof(opacity) === 'object' && opacity.easing || easing)
    }
  };
}

function getDurationValue(duration) {
  if (duration === undefined) {
    return DEFAULT_DURATION_VALUE;
  }

  if (typeof duration === 'number') {
    return "".concat(duration, "ms");
  }

  if (DURATION_VALUES[duration] !== undefined) {
    return DURATION_VALUES[duration];
  }

  return DEFAULT_DURATION_VALUE;
}

function getEasingValue(easing) {
  if (easing === undefined) {
    return DEFAULT_EASING_VALUE;
  }

  return EASING_VALUES[easing];
}

function getTranslateValue(translate) {
  if (translate === undefined) {
    return DEFAULT_TRANSLATE_VALUE;
  }

  if (typeof translate === 'number') {
    return "".concat(translate, "px");
  } // $FlowFixMe: could be TransitionTranslateType or a string


  if (TRANSLATE_VALUES[translate] !== undefined) {
    return TRANSLATE_VALUES[translate];
  }

  return translate;
}

function getScaleValue(scale) {
  return scale === undefined ? DEFAULT_SCALE_VALUE : String(scale);
}

function getTransformValue(_ref2) {
  var translateX = _ref2.translateX,
      translateY = _ref2.translateY,
      scaleX = _ref2.scaleX,
      scaleY = _ref2.scaleY;
  return "translate3d(".concat(translateX, ", ").concat(translateY, ", 0px) scale3d(").concat(scaleX, ", ").concat(scaleY, ", 1)");
}

function getTransformOriginValue(transform) {
  return transform && transform.origin || DEFAULT_TRANSFORM_ORIGIN_VALUE;
}

function getOpacityValue(opacity) {
  return opacity === undefined ? DEFAULT_OPACITY_VALUE : String(opacity);
}

function getWidthHeightValue(widthHeight) {
  if (widthHeight === undefined) {
    return DEFAULT_WIDTH_HEIGHT_VALUE;
  }

  if (typeof widthHeight === 'number') {
    return "".concat(widthHeight, "px");
  }

  return widthHeight;
}