'use strict';

var colors = require('@ant-design/colors');
require('../../../utils/index.cjs');
var log = require('../../../utils/log.cjs');

function sortGradient(gradients) {
  let tempArr = [];
  Object.keys(gradients).forEach((key) => {
    const formattedKey = Number.parseFloat(key.replace(/%/g, ""));
    if (!Number.isNaN(formattedKey)) {
      tempArr.push({
        key: formattedKey,
        value: gradients[key]
      });
    }
  });
  tempArr = tempArr.sort((a, b) => a.key - b.key);
  return tempArr.map(({ key, value }) => `${value} ${key}%`).join(", ");
}
function handleGradient(strokeColor, directionConfig) {
  const {
    from = colors.presetPrimaryColors.blue,
    to = colors.presetPrimaryColors.blue,
    direction = directionConfig === "rtl" ? "to left" : "to right",
    ...rest
  } = strokeColor;
  if (Object.keys(rest).length !== 0) {
    const sortedGradients = sortGradient(rest);
    return { backgroundImage: `linear-gradient(${direction}, ${sortedGradients})` };
  }
  return { backgroundImage: `linear-gradient(${direction}, ${from}, ${to})` };
}
function validProgress(progress) {
  if (!progress || progress < 0)
    return 0;
  if (progress > 100)
    return 100;
  return progress;
}
function getSuccessPercent({ success, successPercent }) {
  let percent = successPercent;
  if (success && "progress" in success) {
    log.devWarning(
      false,
      "Progress",
      "`success.progress` is deprecated. Please use `success.percent` instead."
    );
    percent = success.progress;
  }
  if (success && "percent" in success)
    percent = success.percent;
  return percent;
}
function getPercentage({ percent, success, successPercent }) {
  const realSuccessPercent = validProgress(getSuccessPercent({ success, successPercent }));
  return [realSuccessPercent, validProgress(validProgress(percent) - realSuccessPercent)];
}
function getStrokeColor({
  success = {},
  strokeColor
}) {
  const { strokeColor: successColor } = success;
  return [successColor || colors.presetPrimaryColors.green, strokeColor || null];
}
function getSize(size, type, extra) {
  var _a, _b, _c, _d;
  let width = -1;
  let height = -1;
  if (type === "step") {
    const steps = extra.steps;
    const strokeWidth = extra.strokeWidth;
    if (typeof size === "string" || typeof size === "undefined") {
      width = size === "small" ? 2 : 14;
      height = strokeWidth != null ? strokeWidth : 8;
    } else if (typeof size === "number") {
      [width, height] = [size, size];
    } else {
      [width = 14, height = 8] = size;
    }
    width *= steps;
  } else if (type === "line") {
    const strokeWidth = extra == null ? void 0 : extra.strokeWidth;
    if (typeof size === "string" || typeof size === "undefined")
      height = strokeWidth || (size === "small" ? 6 : 8);
    else if (typeof size === "number")
      [width, height] = [size, size];
    else
      [width = -1, height = 8] = size;
  } else if (type === "circle" || type === "dashboard") {
    if (typeof size === "string" || typeof size === "undefined") {
      [width, height] = size === "small" ? [60, 60] : [120, 120];
    } else if (typeof size === "number") {
      [width, height] = [size, size];
    } else {
      if (process.env.NODE_ENV !== "production") {
        log.devWarning(
          false,
          "Progress",
          'Type "circle" and "dashboard" do not accept array as `size`, please use number or preset size instead.'
        );
      }
      width = (_b = (_a = size[0]) != null ? _a : size[1]) != null ? _b : 120;
      height = (_d = (_c = size[0]) != null ? _c : size[1]) != null ? _d : 120;
    }
  }
  return { width, height };
}

exports.getPercentage = getPercentage;
exports.getSize = getSize;
exports.getStrokeColor = getStrokeColor;
exports.getSuccessPercent = getSuccessPercent;
exports.handleGradient = handleGradient;
exports.sortGradient = sortGradient;
exports.validProgress = validProgress;
//# sourceMappingURL=utils.cjs.map
