import { XmarkFailedSeriousWarningFill16RedIcon, CheckmarkDoneSuccessCircleFill16GreenIcon, Loading16GradientBlueIcon, NoticeTriangleFill16YellowIcon, TimelineNotStart16GrayIcon } from '@cloudtower/icons-react';
import { cx } from '@linaria/core';
import useParrotTranslation from '../../hooks/useParrotTranslation.js';
import { List, Flex } from 'antd5';
import React__default, { useState, useCallback } from 'react';
import cs from 'classnames';
import { CheckPointItemStyle, CheckPointListStyle, EmptyWrapper } from './checkpointlist.style.js';
import { Show } from '../Show/index.js';
import Icon from '../../core/Icon/index.js';
import { Typo } from '../../core/Typo/index.js';
import Button from '../../core/Button/index.js';
import Link from '../../core/Link/index.js';
import Tag from '../../core/Tag/index.js';
import Alert from '../../core/Alert/index.js';
import Switch from '../../core/Switch/index.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 CheckPointItem = ({
  description,
  status,
  key,
  tagProps,
  alertProps,
  actions
}) => {
  const icon = {
    failed: XmarkFailedSeriousWarningFill16RedIcon,
    success: CheckmarkDoneSuccessCircleFill16GreenIcon,
    loading: Loading16GradientBlueIcon,
    warning: NoticeTriangleFill16YellowIcon,
    idle: TimelineNotStart16GrayIcon
  };
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(List.Item, { className: cx(CheckPointItemStyle), key }, /* @__PURE__ */ React__default.createElement(Show, { condition: Boolean(icon) }, /* @__PURE__ */ React__default.createElement(
    Icon,
    {
      src: icon[status],
      className: "icon-wrapper",
      isRotate: status === "loading"
    }
  )), /* @__PURE__ */ React__default.createElement("span", { className: cx(Typo.Label.l4_regular, "description") }, description), /* @__PURE__ */ React__default.createElement(Flex, { gap: 8 }, /* @__PURE__ */ React__default.createElement(Show, { condition: Boolean(actions == null ? void 0 : actions.length) }, actions == null ? void 0 : actions.map((action) => {
    if (action.type === "button") {
      return /* @__PURE__ */ React__default.createElement(Button, __spreadValues({}, action.props));
    }
    if (action.type === "link") {
      return /* @__PURE__ */ React__default.createElement(Link, __spreadValues({}, action.props));
    }
    if (action.type === "icon") {
      return /* @__PURE__ */ React__default.createElement(Icon, __spreadValues({}, action.props));
    }
  })), /* @__PURE__ */ React__default.createElement(Show, { condition: Boolean(tagProps) }, /* @__PURE__ */ React__default.createElement(Tag, __spreadValues({}, tagProps))))), /* @__PURE__ */ React__default.createElement(Show, { condition: Boolean(alertProps) }, /* @__PURE__ */ React__default.createElement(Alert, __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] = useState(defaultChecked);
  const onClickSwitchFn = useCallback(() => {
    const nextChecked = !checked;
    setChecked(nextChecked);
    onClickSwitch == null ? void 0 : onClickSwitch(nextChecked);
  }, [onClickSwitch, checked]);
  const isEmpty = !items.length;
  return /* @__PURE__ */ React__default.createElement(
    "div",
    {
      className: cs(CheckPointListStyle, className, {
        border
      })
    },
    /* @__PURE__ */ React__default.createElement("header", { className: cx(Typo.Label.l4_bold) }, title, /* @__PURE__ */ React__default.createElement(Show, { condition: showSwitchControl }, /* @__PURE__ */ React__default.createElement("span", { className: "switch-text" }, /* @__PURE__ */ React__default.createElement(Switch, { checked, onChange: onClickSwitchFn, size: "small" }), /* @__PURE__ */ React__default.createElement("span", null, switchText || t("common.show_unpassed"))))),
    /* @__PURE__ */ React__default.createElement(
      Show,
      {
        condition: isEmpty,
        fallback: /* @__PURE__ */ React__default.createElement(List, { split: false, bordered: false }, items.map((item, index) => /* @__PURE__ */ React__default.createElement(CheckPointItem, __spreadProps(__spreadValues({}, item), { key: `checklist-item-${index}` }))))
      },
      emptyRender ? emptyRender(emptyText) : /* @__PURE__ */ React__default.createElement("div", { className: cx(EmptyWrapper, emptyTextClassName) }, emptyText)
    )
  );
};

export { CheckPointItem, CheckPointList };
