"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Stepper_exports = {};
__export(Stepper_exports, {
  Item: () => Item,
  Step: () => Step,
  StepText: () => StepText,
  default: () => Stepper_default
});
module.exports = __toCommonJS(Stepper_exports);
var import_react = __toESM(require("react"));
var import_styled_components = __toESM(require("styled-components"));
var import_styled_system = require("styled-system");
var import__ = require("../../../../index");
var import_Text = __toESM(require("../../../asorted/Text"));
var import_Flex = __toESM(require("../../../layout/Flex"));
const Item = {
  Container: import_styled_components.default.div.attrs({
    mx: "8px"
  })`
    display: flex;
    justify-content: center;
    align-items: center;
    width: ${(p) => p.theme.space[8]}px;
    height: ${(p) => p.theme.space[8]}px;
    ${import_styled_system.color}
    ${import_styled_system.border}
    ${import_styled_system.space}
  `,
  Spacer: import_styled_components.default.div`
    display: flex;
    align-self: stretch;
    ${import_styled_system.space}
  `,
  Current: import_styled_components.default.div.attrs({
    backgroundColor: "primary.c90"
  })`
    width: 6px;
    height: 6px;
    border-radius: 6px;
    ${import_styled_system.color}
  `,
  Pending: import_styled_components.default.div.attrs({
    backgroundColor: "neutral.c70"
  })`
    width: ${(p) => p.theme.space[2]}px;
    height: ${(p) => p.theme.space[2]}px;
    border-radius: ${(p) => p.theme.space[2]}px;
    ${import_styled_system.color}
  `,
  Completed: () => /* @__PURE__ */ import_react.default.createElement(import__.IconsLegacy.CheckAloneMedium, { size: 16 }),
  Disabled: () => /* @__PURE__ */ import_react.default.createElement(import__.IconsLegacy.CloseMedium, { size: 16 }),
  Errored: () => /* @__PURE__ */ import_react.default.createElement(import__.IconsLegacy.CloseMedium, { size: 16 })
};
const StepText = (0, import_styled_components.default)(import_Text.default)`
  text-align: center;
  white-space: pre-wrap;
  color: ${(p) => {
  if (p.state === "errored") {
    return p.theme.colors.error.c50;
  }
  if (p.state === "disabled") {
    return p.theme.colors.neutral.c50;
  }
  if (p.state === "pending") {
    return p.theme.colors.neutral.c70;
  }
  return p.theme.colors.neutral.c100;
}};
`;
const BaseSeparator = import_styled_components.default.div`
  flex: 1;
  position: relative;
  overflow-x: hidden;
  background-color: ${(p) => p.theme.colors.neutral.c40};
  height: 1px;
  top: ${(p) => p.theme.space[5]}px;
`;
const Separator = {
  Step: (0, import_styled_components.default)(BaseSeparator)``,
  Item: (0, import_styled_components.default)(BaseSeparator)``
};
const stepContentsByState = {
  pending: /* @__PURE__ */ import_react.default.createElement(Item.Container, null, /* @__PURE__ */ import_react.default.createElement(Item.Pending, null)),
  current: /* @__PURE__ */ import_react.default.createElement(Item.Container, { backgroundColor: "primary.c20", borderRadius: "8px" }, /* @__PURE__ */ import_react.default.createElement(Item.Current, null)),
  completed: /* @__PURE__ */ import_react.default.createElement(Item.Container, { color: "primary.c90", backgroundColor: "primary.c20", borderRadius: "8px" }, /* @__PURE__ */ import_react.default.createElement(Item.Completed, null)),
  errored: /* @__PURE__ */ import_react.default.createElement(Item.Container, { color: "error.c50", backgroundColor: "warning.c30", borderRadius: "8px" }, /* @__PURE__ */ import_react.default.createElement(Item.Errored, null)),
  disabled: /* @__PURE__ */ import_react.default.createElement(Item.Container, { color: "neutral.c50" }, /* @__PURE__ */ import_react.default.createElement(Item.Disabled, null))
};
const Step = (0, import_react.memo)(function Step2({
  state,
  label: Label,
  hideLeftSeparator,
  nextState
}) {
  const inactive = state === "pending";
  const nextInactive = state === "pending";
  return /* @__PURE__ */ import_react.default.createElement(import_Flex.default, { flexDirection: "column", alignItems: "center", flex: 20 }, /* @__PURE__ */ import_react.default.createElement(Item.Spacer, { mb: 5 }, !hideLeftSeparator && /* @__PURE__ */ import_react.default.createElement(Separator.Item, { inactive, position: "left" }) || /* @__PURE__ */ import_react.default.createElement(import_Flex.default, { flex: "1" }), stepContentsByState[state], nextState && /* @__PURE__ */ import_react.default.createElement(Separator.Item, { inactive: nextInactive, position: "right" }) || /* @__PURE__ */ import_react.default.createElement(import_Flex.default, { flex: "1" })), typeof Label === "string" ? /* @__PURE__ */ import_react.default.createElement(StepText, { state, variant: "small" }, Label) : /* @__PURE__ */ import_react.default.createElement(Label, { state }));
});
function getState(activeIndex, index, errored, disabled, completed) {
  if (completed) {
    return "completed";
  }
  if (disabled) {
    return "disabled";
  }
  if (activeIndex < index) {
    return "pending";
  }
  if (activeIndex === index) {
    return errored ? "errored" : "current";
  }
  return "completed";
}
function Stepper({
  steps,
  activeIndex = 0,
  errored,
  disabledIndexes,
  filterDuplicate,
  isOver,
  ...extraProps
}) {
  const displayedSteps = filterDuplicate ? steps.filter((step, index) => index === 0 || step !== steps[index - 1]) : steps;
  const dislayedActiveIndex = filterDuplicate ? displayedSteps.findIndex((step) => step === steps[activeIndex]) : activeIndex;
  return /* @__PURE__ */ import_react.default.createElement(import_Flex.default, { flexWrap: "nowrap", justifyContent: "space-between", ...extraProps }, displayedSteps.map((step, idx) => {
    const state = getState(
      dislayedActiveIndex,
      idx,
      errored,
      disabledIndexes == null ? void 0 : disabledIndexes.includes(idx),
      isOver
    );
    const nextState = idx < displayedSteps.length - 1 ? getState(dislayedActiveIndex, idx + 1) : void 0;
    return /* @__PURE__ */ import_react.default.createElement(import_react.Fragment, { key: idx }, idx > 0 && /* @__PURE__ */ import_react.default.createElement(Separator.Step, { inactive: state === "pending" }), /* @__PURE__ */ import_react.default.createElement(Step, { label: step, state, nextState, hideLeftSeparator: idx === 0 }));
  }));
}
var Stepper_default = (0, import_react.memo)(Stepper);
//# sourceMappingURL=index.js.map
