'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var colors = require('@ant-design/colors');
var devWarning = require('../vc-util/devWarning.js');
var type = require('../_util/type.js');
var props = require('./props.js');
var utils = require('./utils.js');

const lineProps = () => ({
  ...props.progressProps(),
  strokeColor: type.anyType(),
  direction: type.stringType()
});
const sortGradient = (gradients) => {
  let tempArr = [];
  Object.keys(gradients).forEach((key) => {
    const formattedKey = parseFloat(key.replace(/%/g, ""));
    if (!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(", ");
};
const 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})`
  };
};
var Line = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "Line",
  inheritAttrs: false,
  props: lineProps(),
  setup(props, {
    slots,
    attrs
  }) {
    const backgroundProps = vue.computed(() => {
      const {
        strokeColor,
        direction
      } = props;
      return strokeColor && typeof strokeColor !== "string" ? handleGradient(strokeColor, direction) : {
        backgroundColor: strokeColor
      };
    });
    const borderRadius = vue.computed(() => props.strokeLinecap === "square" || props.strokeLinecap === "butt" ? 0 : void 0);
    const trailStyle = vue.computed(() => props.trailColor ? {
      backgroundColor: props.trailColor
    } : void 0);
    const mergedSize = vue.computed(() => {
      var _a;
      return (_a = props.size) != null ? _a : [-1, props.strokeWidth || (props.size === "small" ? 6 : 8)];
    });
    const sizeRef = vue.computed(() => utils.getSize(mergedSize.value, "line", {
      strokeWidth: props.strokeWidth
    }));
    if (process.env.NODE_ENV !== "production") {
      devWarning.default("strokeWidth" in props, "Progress", "`strokeWidth` is deprecated. Please use `size` instead.");
    }
    const percentStyle = vue.computed(() => {
      const {
        percent
      } = props;
      return {
        width: `${utils.validProgress(percent)}%`,
        height: `${sizeRef.value.height}px`,
        borderRadius: borderRadius.value,
        ...backgroundProps.value
      };
    });
    const successPercent = vue.computed(() => {
      return utils.getSuccessPercent(props);
    });
    const successPercentStyle = vue.computed(() => {
      const {
        success
      } = props;
      return {
        width: `${utils.validProgress(successPercent.value)}%`,
        height: `${sizeRef.value.height}px`,
        borderRadius: borderRadius.value,
        backgroundColor: success == null ? void 0 : success.strokeColor
      };
    });
    const outerStyle = {
      width: sizeRef.value.width < 0 ? "100%" : sizeRef.value.width,
      height: `${sizeRef.value.height}px`
    };
    return () => {
      var _a;
      return vue.createVNode(vue.Fragment, null, [vue.createVNode("div", vue.mergeProps(attrs, {
        "class": [`${props.prefixCls}-outer`, attrs.class],
        "style": [attrs.style, outerStyle]
      }), [vue.createVNode("div", {
        "class": `${props.prefixCls}-inner`,
        "style": trailStyle.value
      }, [vue.createVNode("div", {
        "class": `${props.prefixCls}-bg`,
        "style": percentStyle.value
      }, null), successPercent.value !== void 0 ? vue.createVNode("div", {
        "class": `${props.prefixCls}-success-bg`,
        "style": successPercentStyle.value
      }, null) : null])]), (_a = slots.default) == null ? void 0 : _a.call(slots)]);
    };
  }
});

exports.default = Line;
exports.handleGradient = handleGradient;
exports.lineProps = lineProps;
exports.sortGradient = sortGradient;
//# sourceMappingURL=Line.js.map
