import classNames from 'classnames';
import {defineComponent} from 'vue';
import {getListenersFromContext, initDefaultProps} from '../_util/props-util';
import PropTypes from '../_util/vue-types';
import {useConfigProvider} from '../config-provider';
import Icon from '../icon';
import Circle from './circle';
import Line from './line';
import {validProgress} from './utils';
const ProgressStatuses = ['normal', 'exception', 'active', 'success'];
export const ProgressType = PropTypes.oneOf(['line', 'circle', 'dashboard']);
export const ProgressSize = PropTypes.oneOf(['default', 'small']);
export const ProgressProps = {
prefixCls: PropTypes.string,
type: ProgressType,
percent: PropTypes.number,
successPercent: PropTypes.number,
format: PropTypes.func,
status: PropTypes.oneOf(ProgressStatuses),
showInfo: PropTypes.bool,
strokeWidth: PropTypes.number,
strokeLinecap: PropTypes.oneOf(['butt', 'round', 'square']),
strokeColor: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
trailColor: PropTypes.string,
width: PropTypes.number,
gapDegree: PropTypes.number,
gapPosition: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
size: ProgressSize
};
export default defineComponent({
name: 'AProgress',
props: initDefaultProps(ProgressProps, {
type: 'line',
percent: 0,
showInfo: true,
trailColor: '#f3f3f3',
size: 'default',
gapDegree: 0,
strokeLinecap: 'round'
}),
setup($props, {emit, slots}) {
const getPercentNumber = () => {
const {successPercent, percent = 0} = $props;
return parseInt(
successPercent !== undefined ? successPercent.toString() : percent.toString(),
10
);
};
const getProgressStatus = () => {
const {status} = $props;
if (ProgressStatuses.indexOf(status) < 0 && getPercentNumber() >= 100) {
return 'success';
}
return status || 'normal';
};
const renderProcessInfo = (prefixCls, progressStatus) => {
const {showInfo, format, type, percent, successPercent} = $props;
if (!showInfo) {
return null;
}
let text;
const textFormatter =
format || slots.format || (percentNumber => `${percentNumber}%`);
const iconType = type === 'circle' || type === 'dashboard' ? '' : '-circle';
if (
format ||
slots.format ||
(progressStatus !== 'exception' && progressStatus !== 'success')
) {
text = textFormatter(validProgress(percent), validProgress(successPercent));
} else if (progressStatus === 'exception') {
text =