'use client';

// src/components/Stepper/step-icon.tsx
import * as React3 from "react";
import { cn } from "@paalan/react-shared/lib";
import { cva } from "class-variance-authority";
import { CheckIcon, Loader2, X } from "lucide-react";

// src/components/Stepper/use-stepper.ts
import * as React2 from "react";

// src/components/Stepper/context.tsx
import * as React from "react";
import { jsx } from "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
import { jsx as jsx2 } from "react/jsx-runtime";
var iconVariants = 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 : CheckIcon, [CustomCheckIcon]);
  return React3.useMemo(() => {
    if (isCompletedStep) {
      if (isError && isKeepError) {
        return /* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsx2(X, { className: cn(iconVariants({ size })) }) }, "icon");
      }
      return /* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsx2(Check, { className: cn(iconVariants({ size })) }) }, "check-icon");
    }
    if (isCurrentStep) {
      if (isError && ErrorIcon) {
        return /* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsx2(ErrorIcon, { className: cn(iconVariants({ size })) }) }, "error-icon");
      }
      if (isError) {
        return /* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsx2(X, { className: cn(iconVariants({ size })) }) }, "icon");
      }
      if (isLoading) {
        return /* @__PURE__ */ jsx2(Loader2, { className: cn(iconVariants({ size }), "animate-spin") });
      }
    }
    if (Icon) {
      return /* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsx2(Icon, { className: cn(iconVariants({ size })) }) }, "step-icon");
    }
    return /* @__PURE__ */ jsx2("span", { ref, className: cn("text-md text-center font-medium"), children: (index || 0) + 1 }, "label");
  }, [isCompletedStep, isCurrentStep, isError, isLoading, Icon, index, Check, ErrorIcon, isKeepError, ref, size]);
});
export {
  StepIcon
};
