import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { Color } from './color';
export var ColorPickerPrefixCls = 'rc-color-picker';
export var generateColor = function generateColor(color) {
  if (color instanceof Color) {
    return color;
  }
  return new Color(color);
};
export var defaultColor = generateColor('#1677ff');
export var calculateColor = function calculateColor(props) {
  var _targetRef$value;
  var offset = props.offset,
    targetRef = props.targetRef,
    containerRef = props.containerRef,
    color = props.color,
    type = props.type;
  var height = containerRef.value.offsetHeight;
  var width = containerRef.value.offsetWidth;
  var _targetRef$value$tran = (_targetRef$value = targetRef.value) === null || _targetRef$value === void 0 ? void 0 : _targetRef$value.transformDomRef.getBoundingClientRect(),
    targetWidth = _targetRef$value$tran.width,
    targetHeight = _targetRef$value$tran.height;
  var centerOffsetX = targetWidth / 2;
  var centerOffsetY = targetHeight / 2;
  var saturation = (offset.x + centerOffsetX) / width;
  var bright = 1 - (offset.y + centerOffsetY) / height;
  var hsb = color.toHsb();
  var alphaOffset = saturation;
  var hueOffset = (offset.x + centerOffsetX) / width * 360;
  if (type) {
    switch (type) {
      case 'hue':
        return generateColor(_objectSpread(_objectSpread({}, hsb), {}, {
          h: hueOffset <= 0 ? 0 : hueOffset
        }));
      case 'alpha':
        return generateColor(_objectSpread(_objectSpread({}, hsb), {}, {
          a: alphaOffset <= 0 ? 0 : alphaOffset
        }));
    }
  }
  return generateColor({
    h: hsb.h,
    s: saturation <= 0 ? 0 : saturation,
    b: bright >= 1 ? 1 : bright,
    a: hsb.a
  });
};
export var calculateOffset = function calculateOffset(containerRef, targetRef, color, type) {
  var _targetRef$value$tran3;
  var _containerRef$value$g = containerRef.value.getBoundingClientRect(),
    width = _containerRef$value$g.width,
    height = _containerRef$value$g.height;
  var _targetRef$value$tran2 = (_targetRef$value$tran3 = targetRef.value.transformDomRef) === null || _targetRef$value$tran3 === void 0 ? void 0 : _targetRef$value$tran3.getBoundingClientRect(),
    targetWidth = _targetRef$value$tran2.width,
    targetHeight = _targetRef$value$tran2.height;
  var centerOffsetX = targetWidth / 2;
  var centerOffsetY = targetHeight / 2;
  var hsb = color.value.toHsb();
  // Exclusion of boundary cases
  if (targetWidth === 0 && targetHeight === 0 || targetWidth !== targetHeight) {
    return;
  }
  if (type) {
    switch (type) {
      case 'hue':
        return {
          x: hsb.h / 360 * width - centerOffsetX,
          y: -centerOffsetY / 3
        };
      case 'alpha':
        return {
          x: hsb.a / 1 * width - centerOffsetX,
          y: -centerOffsetY / 3
        };
    }
  }
  return {
    x: hsb.s * width - centerOffsetX,
    y: (1 - hsb.b) * height - centerOffsetY
  };
};