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

export { Timeline };
