"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.progressProps = exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _vue = require("vue");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _classNames = _interopRequireDefault(require("../_util/classNames"));
var _is = require("../_util/is");
var _util = require("../_util/util");
require("../_util/type");
// Visually hidden styles for screen readers
const VISUALLY_HIDDEN_STYLE = {
  position: 'absolute',
  width: '1px',
  height: '1px',
  padding: '0px',
  margin: '-1px',
  overflow: 'hidden',
  clip: 'rect(0, 0, 0, 0)',
  whiteSpace: 'nowrap',
  border: '0px'
};
const progressProps = () => ({
  prefixCls: {
    type: String,
    required: true
  },
  percent: {
    type: Number,
    default: undefined
  },
  render: {
    type: Function,
    default: undefined
  },
  classNames: {
    type: Object,
    default: undefined
  },
  styles: {
    type: Object,
    default: undefined
  },
  rootClassName: {
    type: String,
    default: undefined
  },
  rootStyle: {
    type: Object,
    default: undefined
  },
  width: {
    type: [String, Number],
    default: undefined
  },
  height: {
    type: [String, Number],
    default: undefined
  }
});
exports.progressProps = progressProps;
const Progress = (0, _vue.defineComponent)({
  name: 'ImageProgress',
  props: progressProps(),
  setup(props) {
    // Check if percent is a valid finite number
    const hasPercent = (0, _vue.computed)(() => (0, _is.isNumber)(props.percent) && Number.isFinite(props.percent));
    // Calculate percent value (clamped to 0-100 for progress bar width)
    const percentValue = (0, _vue.computed)(() => hasPercent.value ? Math.max(0, Math.min(100, Math.round(props.percent))) : 0);
    // ARIA attributes for accessibility
    const ariaProps = (0, _vue.computed)(() => hasPercent.value ? {
      role: 'progressbar',
      'aria-valuemin': 0,
      'aria-valuemax': 100,
      'aria-valuenow': percentValue.value,
      'aria-label': `${percentValue.value}%`
    } : {
      'aria-busy': true
    });
    return () => {
      const {
        prefixCls,
        classNames: progressClassNames,
        styles: progressStyles,
        rootClassName,
        rootStyle,
        width,
        height,
        render: progressRender
      } = props;
      // Render progress bar (rail with ::before pseudo for track)
      const progressBar = hasPercent.value ? (0, _vue.createVNode)("div", {
        "class": (0, _classNames.default)(`${prefixCls}-progress-rail`, progressClassNames === null || progressClassNames === void 0 ? void 0 : progressClassNames.rail),
        "style": (0, _extends2.default)((0, _extends2.default)({}, progressStyles === null || progressStyles === void 0 ? void 0 : progressStyles.rail), {
          '--progress-percent': `${percentValue.value}%`
        })
      }, null) : null;
      // Render progress content
      const progressContent = progressRender ? progressRender(progressBar, percentValue.value) : (0, _vue.createVNode)(_vue.Fragment, null, [progressBar, hasPercent.value && (0, _vue.createVNode)("div", {
        "class": (0, _classNames.default)(`${prefixCls}-progress-indicator`, progressClassNames === null || progressClassNames === void 0 ? void 0 : progressClassNames.indicator),
        "style": progressStyles === null || progressStyles === void 0 ? void 0 : progressStyles.indicator
      }, [`${percentValue.value}%`])]);
      return (0, _vue.createVNode)("div", (0, _objectSpread2.default)({
        "class": (0, _classNames.default)(prefixCls, `${prefixCls}-progress-wrapper`, progressClassNames === null || progressClassNames === void 0 ? void 0 : progressClassNames.root, rootClassName),
        "style": (0, _extends2.default)((0, _extends2.default)({
          width: (0, _util.toPx)(width),
          height: (0, _util.toPx)(height)
        }, rootStyle), progressStyles === null || progressStyles === void 0 ? void 0 : progressStyles.root)
      }, ariaProps.value), [!hasPercent.value && (0, _vue.createVNode)("span", {
        "role": "status",
        "aria-live": "polite",
        "style": VISUALLY_HIDDEN_STYLE
      }, [(0, _vue.createTextVNode)("Loading")]), (0, _vue.createVNode)("div", {
        "class": `${prefixCls}-progress-ink-1`
      }, null), (0, _vue.createVNode)("div", {
        "class": `${prefixCls}-progress-ink-2`
      }, null), (0, _vue.createVNode)("div", {
        "class": (0, _classNames.default)(`${prefixCls}-progress-content`, progressClassNames === null || progressClassNames === void 0 ? void 0 : progressClassNames.content),
        "style": progressStyles === null || progressStyles === void 0 ? void 0 : progressStyles.content
      }, [progressContent])]);
    };
  }
});
var _default = exports.default = Progress;