/*
import { deepMerge } from '@jiaminghi/charts/lib/util/index'
import { deepClone } from '@jiaminghi/c-render/lib/plugin/util'
import { fade } from '@jiaminghi/color'
import { getPolylineLength, deepMerge } from '@jiaminghi/charts/lib/util'
*/



/**
 * @description Get the coordinates of the specified radian on the circle
 */
function getCircleRadianPoint(x, y, radius, radian) {
    return [x + Math.cos(radian) * radius, y + Math.sin(radian) * radius];
}



// eslint-disable-next-line
export function deepClone(obj, cache) {
    
    if (cache) { cache = new Map([]); }
    if (obj === null || typeof obj !== 'object')
        return obj;
   

    if (cache.has(obj))
        return cache.get(obj);
    
    // eslint-disable-next-line
    var clone = Array.isArray(obj) ? [] : {};
    cache.set(obj, clone);
    // @ts-ignore
    Object.keys(obj).forEach(function (key) { return (clone[key] = deepClone(obj[key], cache)); });
    return clone;
}
// eslint-disable-next-line
export function debounce(callback, delay) {
    var _this = this;
    if (delay === void 0) { delay = 0; }
    var timer = undefined;
    return function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        if (timer)
            clearTimeout(timer);
        timer = window.setTimeout(function () {
            // @ts-ignore
            callback.call.apply(callback, __spreadArray([_this], args));
        }, delay);
    };
}



export function deepMerge (target, merged) {
  for (var key in merged) {
    if (target[key] && typeof target[key] === 'object') {
      deepMerge(target[key], merged[key])

      continue
    }

    if (typeof merged[key] === 'object') {
      target[key] = deepClone(merged[key], true)

      continue
    }

    target[key] = merged[key]
  }

  return target
}

function filterNonNumber(array) {
  return array.filter(function (n) {
    return typeof n === 'number';
  });
}

export function mulAdd (nums) {
  nums = filterNonNumber(nums)

  return nums.reduce((all, num) => all + num, 0)
}

export function getTwoPointDistance (pointOne, pointTwo) {
  const minusX = Math.abs(pointOne[0] - pointTwo[0])

  const minusY = Math.abs(pointOne[1] - pointTwo[1])

  return Math.sqrt(minusX * minusX + minusY * minusY)
}

export function getPolylineLength (points) {
  const lineSegments = new Array(points.length - 1)
    .fill(0)
    .map((foo, i) => [points[i], points[i + 1]])

  const lengths = lineSegments.map(item => getTwoPointDistance(...item))

  return mulAdd(lengths)
}


/**
 * @description Test if a hex color
 * @param {string} color color string
 * @return {boolean} Test result
 */

function isHex(color) {
  if (typeof color !== 'string') return false;
  color = color.toLowerCase();
  return /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(color);
}


function getRgbValueFromHex(color) {
  color = color.replace('#', '');
  if (color.length === 3) color = Array.from(color).map(function (hexNum) {
    return hexNum + hexNum;
  }).join('');
  var colorValues = color.split('');
  return new Array(3).fill(0).map(function (_, i) {
    return parseInt("0x" + colorValues[i * 2] + colorValues[i * 2 + 1]);
  });
}
/**
 * @description Get the rgb value of the rgb/rgba color
 * @param {string} color Hex color
 * @return {RgbValue} Rgb value of the color
 */


function getRgbValueFromRgb(color) {
  return color.replace(/rgb\(|rgba\(|\)/g, '').split(',').slice(0, 3).map(function (n) {
    return parseInt(n);
  });
}

function getColorFromRgbValue(value) {
  if (!Array.isArray(value)) throw new Error("getColorFromRgbValue: " + value + " is not an array");
  var length = value.length;
  if (length !== 3 && length !== 4) throw new Error("getColorFromRgbValue: value length should be 3 or 4");
  return (length === 3 ? 'rgb(' : 'rgba(') + value.join(',') + ')';
}

function getRgbValue(color) {
  var validColor = validator(color);
  var lowerColor = validColor.toLowerCase();
  return isHex(lowerColor) ? getRgbValueFromHex(lowerColor) : getRgbValueFromRgb(lowerColor);
}

function __spreadArrays() {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
}

function fade(color, percent) {
  if (percent === void 0) {
    percent = 100;
  }

  var rgbValue = getRgbValue(color);
  return getColorFromRgbValue(__spreadArrays(rgbValue, [percent / 100]));
}