'use client';
"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);

// src/components/Stepper/step-icon.tsx
var step_icon_exports = {};
__export(step_icon_exports, {
  StepIcon: () => StepIcon
});
module.exports = __toCommonJS(step_icon_exports);
var React3 = __toESM(require("react"), 1);
var import_lib = require("@paalan/react-shared/lib");
var import_class_variance_authority = require("class-variance-authority");
var import_lucide_react = require("lucide-react");

// src/components/Stepper/use-stepper.ts
var React2 = __toESM(require("react"), 1);

// src/components/Stepper/context.tsx
var React = __toESM(require("react"), 1);
var import_jsx_runtime = require("react/jsx-runtime");
var StepperContext = React.createContext({
  steps: [],
  activeStep: 0,
  initialStep: 0,
  nextStep: () => {
  },
  prevStep: () => {
  },
  resetSteps: () => {
  },
  setStep: () => {
  }
});

// src/components/Stepper/use-stepper.ts
function usePrevious(value) {
  const ref = React2.useRef();
  React2.useEffect(() => {
    ref.current = value;
  }, [value]);
  return ref.current;
}
function useStepper() {
  const context = React2.useContext(StepperContext);
  if (context === void 0) {
    throw new Error("useStepper must be used within a StepperProvider");
  }
  const { children, className, ...rest } = context;
  const isLastStep = context.activeStep === context.steps.length - 1;
  const hasCompletedAllSteps = context.activeStep === context.steps.length;
  const previousActiveStep = usePrevious(context.activeStep);
  const currentStep = context.steps[context.activeStep];
  const isOptionalStep = !!currentStep?.optional;
  const isDisabledStep = context.activeStep === 0;
  return {
    ...rest,
    isLastStep,
    hasCompletedAllSteps,
    isOptionalStep,
    isDisabledStep,
    currentStep,
    previousActiveStep
  };
}

// src/components/Stepper/step-icon.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var iconVariants = (0, import_class_variance_authority.cva)("", {
  variants: {
    size: {
      sm: "size-4",
      md: "size-4",
      lg: "size-5"
    }
  },
  defaultVariants: {
    size: "md"
  }
});
var StepIcon = React3.forwardRef((props, ref) => {
  const { size } = useStepper();
  const {
    isCompletedStep,
    isCurrentStep,
    isError,
    isLoading,
    isKeepError,
    icon: CustomIcon,
    index,
    checkIcon: CustomCheckIcon,
    errorIcon: CustomErrorIcon
  } = props;
  const Icon = React3.useMemo(() => CustomIcon ? CustomIcon : null, [CustomIcon]);
  const ErrorIcon = React3.useMemo(() => CustomErrorIcon ? CustomErrorIcon : null, [CustomErrorIcon]);
  const Check = React3.useMemo(() => CustomCheckIcon ? CustomCheckIcon : import_lucide_react.CheckIcon, [CustomCheckIcon]);
  return React3.useMemo(() => {
    if (isCompletedStep) {
      if (isError && isKeepError) {
        return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.X, { className: (0, import_lib.cn)(iconVariants({ size })) }) }, "icon");
      }
      return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Check, { className: (0, import_lib.cn)(iconVariants({ size })) }) }, "check-icon");
    }
    if (isCurrentStep) {
      if (isError && ErrorIcon) {
        return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorIcon, { className: (0, import_lib.cn)(iconVariants({ size })) }) }, "error-icon");
      }
      if (isError) {
        return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.X, { className: (0, import_lib.cn)(iconVariants({ size })) }) }, "icon");
      }
      if (isLoading) {
        return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.Loader2, { className: (0, import_lib.cn)(iconVariants({ size }), "animate-spin") });
      }
    }
    if (Icon) {
      return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { className: (0, import_lib.cn)(iconVariants({ size })) }) }, "step-icon");
    }
    return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { ref, className: (0, import_lib.cn)("text-md text-center font-medium"), children: (index || 0) + 1 }, "label");
  }, [isCompletedStep, isCurrentStep, isError, isLoading, Icon, index, Check, ErrorIcon, isKeepError, ref, size]);
});
