'use strict';

var iconsReact = require('@cloudtower/icons-react');
var style = require('./style.js');
var index = require('../Tooltip/index.js');
var antd = require('antd');
var cs = require('classnames');
var React = require('react');

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));
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 StepTitle = (props) => {
  const { current, step, index: index$1, isVerticalMode, preview } = props;
  const textRef = React.useRef(null);
  const [tooltipEnable, setTooltipEnable] = React.useState({
    visible: false
  });
  const showCompletedIcon = !preview && index$1 < current;
  React.useLayoutEffect(() => {
    if (textRef.current && textRef.current.offsetWidth < textRef.current.scrollWidth) {
      setTooltipEnable({});
    }
  }, [textRef]);
  return /* @__PURE__ */ React__default.default.createElement(index, __spreadProps(__spreadValues({}, tooltipEnable), { title: step.title }), /* @__PURE__ */ React__default.default.createElement(
    "div",
    {
      className: isVerticalMode ? style.VerticalStepContentStyle : style.HorizontalStepContentStyle
    },
    /* @__PURE__ */ React__default.default.createElement("span", { className: "step-item-prefix-container" }, showCompletedIcon ? /* @__PURE__ */ React__default.default.createElement(iconsReact.CheckmarkDoneSuccessCorrect16SecondaryIcon, null) : index$1 + 1),
    /* @__PURE__ */ React__default.default.createElement("span", { ref: textRef, className: "step-item-title" }, /* @__PURE__ */ React__default.default.createElement("span", { className: "step-item-title" }, step.title))
  ));
};
const Steps = (props) => {
  const _a = props, {
    stepsConfig,
    direction,
    containerClassname,
    current = 0,
    disabled,
    preview = false
  } = _a, stepsProps = __objRest(_a, [
    "stepsConfig",
    "direction",
    "containerClassname",
    "current",
    "disabled",
    "preview"
  ]);
  const isVerticalMode = direction === "vertical";
  const isPreviewMode = isVerticalMode && preview;
  return /* @__PURE__ */ React__default.default.createElement(
    "div",
    {
      className: cs__default.default(
        containerClassname,
        style.StepsStyle,
        isVerticalMode ? style.VerticalStyle : style.HorizontalStyle
      )
    },
    /* @__PURE__ */ React__default.default.createElement(
      antd.Steps,
      __spreadProps(__spreadValues({}, stepsProps), {
        direction,
        current,
        type: "default"
      }),
      (stepsConfig == null ? void 0 : stepsConfig.length) ? stepsConfig.map((step, index) => {
        var _a2;
        return /* @__PURE__ */ React__default.default.createElement(
          antd.Steps.Step,
          __spreadProps(__spreadValues({
            key: index
          }, step), {
            disabled: isPreviewMode ? false : (_a2 = disabled != null ? disabled : step == null ? void 0 : step.disabled) != null ? _a2 : index > current,
            className: cs__default.default(
              step.className,
              isPreviewMode ? "preview-mode" : ""
            ),
            title: /* @__PURE__ */ React__default.default.createElement(
              StepTitle,
              {
                index,
                step,
                current,
                isVerticalMode,
                preview: isPreviewMode
              }
            )
          })
        );
      }) : props.children
    )
  );
};
var Steps$1 = Steps;

module.exports = Steps$1;
