import { classes } from '../Slider.tokens.js';

var getSingleSliderLayout = function getSingleSliderLayout(_ref) {
  var value = _ref.value,
    min = _ref.min,
    max = _ref.max,
    isVertical = _ref.isVertical,
    isHovered = _ref.isHovered,
    reversed = _ref.reversed,
    scaleTicks = _ref.scaleTicks,
    showRangeValues = _ref.showRangeValues,
    showScale = _ref.showScale,
    showCurrentValue = _ref.showCurrentValue,
    currentValueVisibility = _ref.currentValueVisibility,
    label = _ref.label,
    labelContentLeft = _ref.labelContentLeft,
    labelContent = _ref.labelContent,
    labelPlacement = _ref.labelPlacement,
    sliderAlign = _ref.sliderAlign,
    rangeValuesPlacementOld = _ref.rangeValuesPlacementOld,
    scaleAlign = _ref.scaleAlign,
    pointerSize = _ref.pointerSize,
    pointerVisibility = _ref.pointerVisibility,
    valuePlacement = _ref.valuePlacement;
  var innerShowScale = Boolean((showRangeValues || showScale) && !scaleTicks);
  var innerShowCurrentValue = !scaleTicks && (currentValueVisibility === 'hover' ? showCurrentValue && isHovered : showCurrentValue);
  var hasLabelContent = Boolean(label || labelContentLeft || labelContent) && (!isVertical || sliderAlign !== 'none');
  var labelPlacementClass = !isVertical && (labelPlacement === 'outer' || labelPlacement === 'top') ? classes.labelPlacementOuter : classes.labelPlacementInner;
  var rangeValuesPlacement = rangeValuesPlacementOld === 'outer' || scaleAlign === 'bottom' || scaleAlign === 'top' || Boolean(scaleTicks) ? 'outer' : 'inner';
  var scaleAlignClass = rangeValuesPlacement === 'outer' ? classes.rangeValuesPlacementOuter : classes.rangeValuesPlacementInner;
  var labelVerticalPlacement = reversed ? 'bottom' : 'top';
  var showPointer = pointerSize !== 'none' && (pointerVisibility === 'always' || isHovered);
  var FADE_RANGE = 0.3;
  var fadeOpacity = function fadeOpacity(proximity) {
    return Math.min(1, Math.max(0, proximity / FADE_RANGE));
  };
  var thumbPercent = (value - min) / (max - min);
  var progressSize = "calc(".concat(thumbPercent, " * 100%)");
  var progressSizeStyle = isVertical ? {
    height: progressSize
  } : {
    width: progressSize
  };
  var shouldFadeRangeValues = innerShowCurrentValue && valuePlacement !== 'none';
  var rangeMaxValueOpacity = shouldFadeRangeValues ? fadeOpacity(reversed ? thumbPercent : 1 - thumbPercent) : 1;
  var rangeMinValueOpacity = shouldFadeRangeValues ? fadeOpacity(reversed ? 1 - thumbPercent : thumbPercent) : 1;
  var nearHighFactor = Math.min(1, Math.max(0, (thumbPercent - (1 - FADE_RANGE)) / FADE_RANGE));
  var nearLowFactor = Math.min(1, Math.max(0, (FADE_RANGE - thumbPercent) / FADE_RANGE));
  var verticalScaleCompensation = reversed ? '' : ' scaleY(-1)';
  var getHorizontalCurrentValueStyle = function getHorizontalCurrentValueStyle() {
    var left = "calc(".concat(thumbPercent, " * 100%)");
    if (nearHighFactor > 0) {
      return {
        left: left,
        transform: "translateX(-".concat(50 + nearHighFactor * 50, "%)")
      };
    }
    if (nearLowFactor > 0) {
      return {
        left: left,
        transform: "translateX(-".concat(50 - nearLowFactor * 50, "%)")
      };
    }
    return {
      left: left
    };
  };
  var getVerticalCurrentValueStyle = function getVerticalCurrentValueStyle() {
    var top = "calc(".concat(1 - thumbPercent, " * 100%)");
    if (nearHighFactor > 0) {
      return {
        top: top,
        transform: "translateY(-".concat(50 - nearHighFactor * 50, "%)").concat(verticalScaleCompensation)
      };
    }
    if (nearLowFactor > 0) {
      return {
        top: top,
        transform: "translateY(-".concat(50 + nearLowFactor * 50, "%)").concat(verticalScaleCompensation)
      };
    }
    return {
      top: top
    };
  };
  var currentValueStyle = isVertical ? getVerticalCurrentValueStyle() : getHorizontalCurrentValueStyle();
  return {
    innerShowScale: innerShowScale,
    innerShowCurrentValue: innerShowCurrentValue,
    hasLabelContent: hasLabelContent,
    labelPlacementClass: labelPlacementClass,
    rangeValuesPlacement: rangeValuesPlacement,
    scaleAlignClass: scaleAlignClass,
    labelVerticalPlacement: labelVerticalPlacement,
    showPointer: showPointer,
    currentValueStyle: currentValueStyle,
    progressSizeStyle: progressSizeStyle,
    rangeMinValueOpacity: rangeMinValueOpacity,
    rangeMaxValueOpacity: rangeMaxValueOpacity
  };
};

export { getSingleSliderLayout };
