'use strict';

var core = require('@linaria/core');
var react = require('@linaria/react');
var progress_const = require('./progress.const.js');
var progress_style = require('./progress.style.js');
var progress_widgets = require('./progress.widgets.js');
var isStringArr = require('../../utils/isStringArr.js');
var antd5 = require('antd5');
var React = require('react');
var constants = require('../../utils/constants.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
  enumerable: true,
  configurable: true,
  writable: true,
  value
}) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
    if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
  }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) {
    if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop];
  }
  return target;
};
const Row = /*#__PURE__*/react.styled('div')({
  name: "Row",
  class: "E_r77hffu",
  propsAsIs: false
});
const _exp = /*#__PURE__*/() => ({
  type
}) => type === "rich" ? "6px" : "4px";
const ProgressContainer = /*#__PURE__*/react.styled('div')({
  name: "ProgressContainer",
  class: "E_p1cmxsf7",
  propsAsIs: false,
  vars: {
    "p1cmxsf7-0": [_exp()]
  }
});
const getStatus = (status, percent, indeterminate) => {
  if (indeterminate) return "active";
  if (!status && percent >= 100) return "success";
  return status || "active";
};
const createAreaNode = (content, className, type, gap = 6) => {
  return typeof content === "string" ? /* @__PURE__ */React__default.default.createElement(progress_widgets.Area, {
    className,
    items: [{
      type,
      children: content
    }],
    gap
  }) : content;
};
const Progress = _a => {
  var _b = _a,
    {
      type = "simple",
      status,
      size = "small",
      leftTop,
      rightTop,
      leftBottom,
      rightBottom,
      percent = 0,
      className,
      indeterminate
    } = _b,
    props = __objRest(_b, ["type", "status", "size", "leftTop", "rightTop", "leftBottom", "rightBottom", "percent", "className", "indeterminate"]);
  const finalStatus = getStatus(status, percent, indeterminate);
  const storkeWidth = size === "small" ? 4 : 8;
  const isBaseProgress = type === "base";
  const isRichProgress = type === "rich";
  let titleNode;
  let actionNode = rightBottom;
  let statusTextNode;
  if (type === "simple") {
    let items;
    if (!rightBottom) {
      items = [`${percent}%`];
    } else if (isStringArr.isStringArray(rightBottom)) {
      items = [...rightBottom, `${percent}%`];
    }
    if (items) {
      actionNode = /* @__PURE__ */React__default.default.createElement(progress_widgets.Area, {
        items: items.map(desc => ({
          type: "description",
          children: desc
        })),
        split: "dot"
      });
    }
    titleNode = createAreaNode(leftTop, core.cx(progress_style.FlexFullContentStyle, "progress-leftTop"), "description");
  } else {
    statusTextNode = createAreaNode(rightTop, "progress-status", "description", 2);
    titleNode = createAreaNode(leftTop, "progress-leftTop", "title");
  }
  return /* @__PURE__ */React__default.default.createElement(ProgressContainer, {
    type,
    className: core.cx(className, progress_style.ProgressStyle)
  }, titleNode ? /* @__PURE__ */React__default.default.createElement(Row, null, titleNode, statusTextNode) : null, /* @__PURE__ */React__default.default.createElement(antd5.Progress, __spreadProps(__spreadValues({
    className: isBaseProgress ? progress_style.BaseProgressStyle : "",
    strokeWidth: storkeWidth,
    showInfo: false
  }, props), {
    prefixCls: `${constants.Antd5PrefixCls}-progress`,
    status: finalStatus === "active" ? "active" : void 0,
    percent: indeterminate ? 100 : percent,
    strokeColor: progress_const.StatusColorMap[finalStatus]
  })), leftBottom || actionNode ? /* @__PURE__ */React__default.default.createElement(Row, null, isStringArr.isStringArray(leftBottom) ? /* @__PURE__ */React__default.default.createElement(progress_widgets.Area, {
    className: progress_style.FlexFullContentStyle,
    items: leftBottom.map(desc => ({
      type: "description",
      children: desc,
      multiLines: !rightBottom ? 2 : 1
    })),
    gap: isRichProgress ? 2 : 0,
    split: "dot"
  }) : leftBottom, actionNode) : null);
};

exports.Area = progress_widgets.Area;
exports.TitleArea = progress_widgets.TitleArea;
exports.Progress = Progress;
