var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
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;
};
import React, { useContext, useMemo } from "react";
import classnames from "classnames";
import { BORDER } from "../utils/constant";
import Icon from "../icon";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const StepsItem = (_a) => {
  var _b = _a, {
    children
  } = _b, props = __objRest(_b, [
    "children"
  ]);
  const {
    index,
    parent: parentProps
  } = props;
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("step", prefixCls);
  if (!parentProps) {
    if (process.env.NODE_ENV !== "production") {
      console.error("[rc-ui-lib] <Step> must be a child component of <Steps>.");
    }
  }
  const getStatus = () => {
    const active = +parentProps.active;
    if (index < active) {
      return "finish";
    }
    return index === active ? "process" : "waiting";
  };
  const isActive = () => getStatus() === "process";
  const lineStyle = useMemo(() => ({
    background: getStatus() === "finish" ? parentProps.activeColor : parentProps.inactiveColor
  }), [index, parentProps.active, parentProps.activeColor, parentProps.inactiveColor]);
  const titleStyle = useMemo(() => {
    if (isActive()) {
      return {
        color: parentProps.activeColor
      };
    }
    if (getStatus() === "waiting") {
      return {
        color: parentProps.inactiveColor
      };
    }
    return {};
  }, [index, parentProps.active, parentProps.activeColor, parentProps.inactiveColor]);
  const onClickStep = () => {
    if (parentProps.onClickStep)
      parentProps.onClickStep(index);
  };
  const renderCircle = () => {
    const {
      iconPrefix,
      finishIcon,
      activeIcon,
      activeColor,
      inactiveIcon
    } = parentProps;
    if (isActive()) {
      if (/* @__PURE__ */ React.isValidElement(parentProps.activeIcon)) {
        return parentProps.activeIcon;
      }
      return /* @__PURE__ */ React.createElement(Icon, {
        className: classnames(bem("icon", "active")),
        name: activeIcon,
        color: activeColor,
        classPrefix: iconPrefix
      });
    }
    if (getStatus() === "finish" && (finishIcon || /* @__PURE__ */ React.isValidElement(parentProps.finishIcon))) {
      if (/* @__PURE__ */ React.isValidElement(parentProps.finishIcon)) {
        return parentProps.finishIcon;
      }
      return /* @__PURE__ */ React.createElement(Icon, {
        className: classnames(bem("icon", "finish")),
        name: finishIcon,
        color: activeColor,
        classPrefix: iconPrefix
      });
    }
    if (/* @__PURE__ */ React.isValidElement(parentProps.inactiveIcon)) {
      return parentProps.inactiveIcon;
    }
    if (inactiveIcon) {
      return /* @__PURE__ */ React.createElement(Icon, {
        className: classnames(bem("icon")),
        name: inactiveIcon,
        classPrefix: iconPrefix
      });
    }
    return /* @__PURE__ */ React.createElement("i", {
      className: classnames(bem("circle")),
      style: lineStyle
    });
  };
  const status = getStatus();
  return /* @__PURE__ */ React.createElement("div", {
    style: props.style,
    className: classnames(props.className, BORDER, bem([parentProps.direction, {
      [status]: status
    }]))
  }, /* @__PURE__ */ React.createElement("div", {
    className: classnames(bem("title", {
      active: isActive()
    })),
    style: titleStyle,
    onClick: onClickStep
  }, children), /* @__PURE__ */ React.createElement("div", {
    className: classnames(bem("circle-container")),
    onClick: onClickStep
  }, renderCircle()), /* @__PURE__ */ React.createElement("div", {
    className: classnames(bem("line")),
    style: lineStyle
  }));
};
var stdin_default = StepsItem;
export {
  stdin_default as default
};
