import { cx } from '@linaria/core';
import { styled } from '@linaria/react';
import { StatusColorMap } from './progress.const.js';
import { FlexFullContentStyle, ProgressStyle, BaseProgressStyle } from './progress.style.js';
import { Area } from './progress.widgets.js';
export { TitleArea } from './progress.widgets.js';
import { isStringArray } from '../../utils/isStringArr.js';
import { Progress as Progress$1 } from 'antd5';
import React__default from 'react';
import { Antd5PrefixCls } from '../../utils/constants.js';

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__*/styled('div')({
  name: "Row",
  class: "E_r77hffu",
  propsAsIs: false
});
const _exp = /*#__PURE__*/() => ({
  type
}) => type === "rich" ? "6px" : "4px";
const ProgressContainer = /*#__PURE__*/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.createElement(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 (isStringArray(rightBottom)) {
      items = [...rightBottom, `${percent}%`];
    }
    if (items) {
      actionNode = /* @__PURE__ */React__default.createElement(Area, {
        items: items.map(desc => ({
          type: "description",
          children: desc
        })),
        split: "dot"
      });
    }
    titleNode = createAreaNode(leftTop, cx(FlexFullContentStyle, "progress-leftTop"), "description");
  } else {
    statusTextNode = createAreaNode(rightTop, "progress-status", "description", 2);
    titleNode = createAreaNode(leftTop, "progress-leftTop", "title");
  }
  return /* @__PURE__ */React__default.createElement(ProgressContainer, {
    type,
    className: cx(className, ProgressStyle)
  }, titleNode ? /* @__PURE__ */React__default.createElement(Row, null, titleNode, statusTextNode) : null, /* @__PURE__ */React__default.createElement(Progress$1, __spreadProps(__spreadValues({
    className: isBaseProgress ? BaseProgressStyle : "",
    strokeWidth: storkeWidth,
    showInfo: false
  }, props), {
    prefixCls: `${Antd5PrefixCls}-progress`,
    status: finalStatus === "active" ? "active" : void 0,
    percent: indeterminate ? 100 : percent,
    strokeColor: StatusColorMap[finalStatus]
  })), leftBottom || actionNode ? /* @__PURE__ */React__default.createElement(Row, null, isStringArray(leftBottom) ? /* @__PURE__ */React__default.createElement(Area, {
    className: FlexFullContentStyle,
    items: leftBottom.map(desc => ({
      type: "description",
      children: desc,
      multiLines: !rightBottom ? 2 : 1
    })),
    gap: isRichProgress ? 2 : 0,
    split: "dot"
  }) : leftBottom, actionNode) : null);
};

export { Area, Progress };
