'use strict';

var iconsReact = require('@cloudtower/icons-react');
var core = require('@linaria/core');
var useParrotTranslation = require('../../hooks/useParrotTranslation.js');
var antd5 = require('antd5');
var React = require('react');
var cs = require('classnames');
var checkpointlist_style = require('./checkpointlist.style.js');
var index = require('../Show/index.js');
var index$1 = require('../../core/Icon/index.js');
var index$2 = require('../../core/Typo/index.js');
var index$3 = require('../../core/Button/index.js');
var index$4 = require('../../core/Link/index.js');
var index$5 = require('../../core/Tag/index.js');
var index$6 = require('../../core/Alert/index.js');
var index$7 = require('../../core/Switch/index.js');

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

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

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 CheckPointItem = ({
  description,
  status,
  key,
  tagProps,
  alertProps,
  actions
}) => {
  const icon = {
    failed: iconsReact.XmarkFailedSeriousWarningFill16RedIcon,
    success: iconsReact.CheckmarkDoneSuccessCircleFill16GreenIcon,
    loading: iconsReact.Loading16GradientBlueIcon,
    warning: iconsReact.NoticeTriangleFill16YellowIcon,
    idle: iconsReact.TimelineNotStart16GrayIcon
  };
  return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement(antd5.List.Item, { className: core.cx(checkpointlist_style.CheckPointItemStyle), key }, /* @__PURE__ */ React__default.default.createElement(index.Show, { condition: Boolean(icon) }, /* @__PURE__ */ React__default.default.createElement(
    index$1,
    {
      src: icon[status],
      className: "icon-wrapper",
      isRotate: status === "loading"
    }
  )), /* @__PURE__ */ React__default.default.createElement("span", { className: core.cx(index$2.Typo.Label.l4_regular, "description") }, description), /* @__PURE__ */ React__default.default.createElement(antd5.Flex, { gap: 8 }, /* @__PURE__ */ React__default.default.createElement(index.Show, { condition: Boolean(actions == null ? void 0 : actions.length) }, actions == null ? void 0 : actions.map((action) => {
    if (action.type === "button") {
      return /* @__PURE__ */ React__default.default.createElement(index$3, __spreadValues({}, action.props));
    }
    if (action.type === "link") {
      return /* @__PURE__ */ React__default.default.createElement(index$4, __spreadValues({}, action.props));
    }
    if (action.type === "icon") {
      return /* @__PURE__ */ React__default.default.createElement(index$1, __spreadValues({}, action.props));
    }
  })), /* @__PURE__ */ React__default.default.createElement(index.Show, { condition: Boolean(tagProps) }, /* @__PURE__ */ React__default.default.createElement(index$5.default, __spreadValues({}, tagProps))))), /* @__PURE__ */ React__default.default.createElement(index.Show, { condition: Boolean(alertProps) }, /* @__PURE__ */ React__default.default.createElement(index$6, __spreadValues({ showIcon: false }, alertProps))));
};
const CheckPointList = ({
  items = [],
  showSwitchControl = true,
  title,
  switchText,
  emptyRender,
  emptyText,
  emptyTextClassName,
  onClickSwitch,
  defaultChecked = false,
  className,
  border = true
}) => {
  const { t } = useParrotTranslation();
  const [checked, setChecked] = React.useState(defaultChecked);
  const onClickSwitchFn = React.useCallback(() => {
    const nextChecked = !checked;
    setChecked(nextChecked);
    onClickSwitch == null ? void 0 : onClickSwitch(nextChecked);
  }, [onClickSwitch, checked]);
  const isEmpty = !items.length;
  return /* @__PURE__ */ React__default.default.createElement(
    "div",
    {
      className: cs__default.default(checkpointlist_style.CheckPointListStyle, className, {
        border
      })
    },
    /* @__PURE__ */ React__default.default.createElement("header", { className: core.cx(index$2.Typo.Label.l4_bold) }, title, /* @__PURE__ */ React__default.default.createElement(index.Show, { condition: showSwitchControl }, /* @__PURE__ */ React__default.default.createElement("span", { className: "switch-text" }, /* @__PURE__ */ React__default.default.createElement(index$7, { checked, onChange: onClickSwitchFn, size: "small" }), /* @__PURE__ */ React__default.default.createElement("span", null, switchText || t("common.show_unpassed"))))),
    /* @__PURE__ */ React__default.default.createElement(
      index.Show,
      {
        condition: isEmpty,
        fallback: /* @__PURE__ */ React__default.default.createElement(antd5.List, { split: false, bordered: false }, items.map((item, index) => /* @__PURE__ */ React__default.default.createElement(CheckPointItem, __spreadProps(__spreadValues({}, item), { key: `checklist-item-${index}` }))))
      },
      emptyRender ? emptyRender(emptyText) : /* @__PURE__ */ React__default.default.createElement("div", { className: core.cx(checkpointlist_style.EmptyWrapper, emptyTextClassName) }, emptyText)
    )
  );
};

exports.CheckPointItem = CheckPointItem;
exports.CheckPointList = CheckPointList;
