'use strict';

var iconsReact = require('@cloudtower/icons-react');
var core = require('@linaria/core');
var index$1 = require('../Alert/index.js');
var index = require('../Icon/index.js');
var antd5 = require('antd5');
var cs = require('classnames');
var React = require('react');
var Timeline_style = require('./Timeline.style.js');
var Timeline_widget = require('./Timeline.widget.js');

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

var cs__default = /*#__PURE__*/_interopDefault(cs);
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));
const Timeline = ({
  items,
  emptyText,
  emptyRender,
  compact,
  timelineContainerClassName,
  emptyTextClassName,
  "data-testid": dataTestId
}) => {
  if (!items.length) {
    if (emptyRender) {
      return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, emptyRender(emptyText));
    }
    return /* @__PURE__ */ React__default.default.createElement(
      "div",
      {
        "data-testid": dataTestId,
        className: core.cx(Timeline_style.EmptyWrapper, emptyTextClassName)
      },
      emptyText
    );
  }
  const iconMap = {
    success: iconsReact.CheckmarkDoneSuccessCorrect16GreenIcon,
    failed: iconsReact.XmarkFailed16RedIcon,
    progress: iconsReact.Loading16GradientBlueIcon,
    notice: iconsReact.NoticeTriangleFill16YellowIcon,
    pending: iconsReact.WaitingBreathingLed16YellowIcon,
    idle: iconsReact.TimelineNotStart16GrayIcon
  };
  const alertTypeMap = {
    success: "success",
    failed: "error",
    progress: "info",
    notice: "warning",
    pending: "info",
    idle: "normal"
  };
  return /* @__PURE__ */ React__default.default.createElement(
    "div",
    {
      "data-testid": dataTestId,
      className: core.cx(Timeline_style.TimelineWrapper, timelineContainerClassName)
    },
    /* @__PURE__ */ React__default.default.createElement(antd5.Timeline, null, items.map((item, index$2) => {
      const {
        status,
        infos,
        infosRender,
        infoAction,
        subInfo,
        subInfoRender,
        detailMessage,
        detailMessages,
        detailMessageRender
      } = item;
      const finalDetailMessages = detailMessages != null ? detailMessages : detailMessage ? [detailMessage] : [];
      return /* @__PURE__ */ React__default.default.createElement(
        antd5.Timeline.Item,
        {
          key: `timeline-item-${index$2}`,
          className: cs__default.default(Timeline_style.TimelineItemWrapper, { compact }),
          dot: /* @__PURE__ */ React__default.default.createElement(
            index,
            {
              src: iconMap[status],
              iconHeight: 16,
              iconWidth: 16,
              isRotate: status === "progress"
            }
          )
        },
        infosRender ? infosRender(infos) : /* @__PURE__ */ React__default.default.createElement(
          antd5.Flex,
          {
            vertical: true,
            justify: "space-between",
            gap: 2,
            className: "info-wrapper"
          },
          infos.map((item2, index2) => /* @__PURE__ */ React__default.default.createElement(
            Timeline_widget.TimelineArea,
            __spreadProps(__spreadValues({
              gap: 6,
              key: `title-area-${index2}`
            }, item2), {
              compact,
              suffix: !index2 && infoAction ? /* @__PURE__ */ React__default.default.createElement("span", { className: "info-action" }, infoAction) : void 0
            })
          ))
        ),
        /* @__PURE__ */ React__default.default.createElement("div", { className: "item-time" }, subInfoRender ? subInfoRender(subInfo) : subInfo ? /* @__PURE__ */ React__default.default.createElement(Timeline_widget.TimelineArea, __spreadValues({}, subInfo)) : /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null), finalDetailMessages.length > 0 ? finalDetailMessages.map(
          (detailMessage2, index2) => detailMessageRender ? detailMessageRender(detailMessage2, index2) : /* @__PURE__ */ React__default.default.createElement(
            index$1.default,
            __spreadValues({
              key: `detail-message-${index2}`,
              showIcon: false,
              type: alertTypeMap[status]
            }, detailMessage2)
          )
        ) : /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null))
      );
    }))
  );
};

exports.Timeline = Timeline;
