'use strict';
'use client';
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
import { Button } from '../../../fd-component-toolbox/button/Button.js';
import { WizardStepper } from './WizardStepper.js';
import { cn } from '../../../../fd-toolbox/lib/utils.js';
import { isNextButtonVisible, isBackButtonVisible, getBackButtonId, getSubmitButtonId, getNextButtonId } from './Wizard.funcs.js';

var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", {
  value,
  configurable: true
});
function Wizard({
  config,
  onNextClick,
  onBackClick,
  currentStep,
  children,
  disableButton,
  submitting,
  showSubmitButton,
  onSubmit
}) {
  const nextBtnClass = !isNextButtonVisible(config.steps.length - 1, currentStep) ? "invisible" : "";
  const childrenClass = currentStep === 3 ? "min-h-60" : "min-h-10";
  return /* @__PURE__ */jsxs("div", {
    className: "flex w-full flex-col items-center gap-4",
    children: [/* @__PURE__ */jsx(WizardStepper, {
      steps: config.steps,
      currentStep
    }), /* @__PURE__ */jsx("div", {
      className: cn("w-full max-w-4xl", childrenClass),
      children
    }), /* @__PURE__ */jsxs("div", {
      className: "mt-2 flex w-full max-w-4xl justify-end gap-2",
      children: [/* @__PURE__ */jsx(Button, {
        id: getBackButtonId(currentStep),
        variant: "outline",
        onClick: onBackClick,
        className: !isBackButtonVisible(currentStep) ? "invisible" : "",
        children: "Back"
      }), showSubmitButton && currentStep < config.steps.length - 1 && /* @__PURE__ */jsx(Button, {
        id: getSubmitButtonId(currentStep),
        className: nextBtnClass,
        onClick: onSubmit,
        disabled: disableButton,
        children: submitting ? /* @__PURE__ */jsxs("div", {
          className: "flex",
          children: [/* @__PURE__ */jsx("div", {
            className: "mr-2 size-4 animate-spin rounded-full border-2 border-inherit border-r-transparent"
          }), "Submitting..."]
        }) : /* @__PURE__ */jsx(Fragment, {
          children: "Submit"
        })
      }), currentStep < config.steps.length - 1 || !config.customActions ? /* @__PURE__ */jsx(Button, {
        id: getNextButtonId(currentStep),
        className: nextBtnClass,
        onClick: onNextClick,
        disabled: disableButton,
        children: currentStep < config.steps.length - 1 ? /* @__PURE__ */jsx(Fragment, {
          children: "Next"
        }) : /* @__PURE__ */jsx("div", {
          children: submitting ? /* @__PURE__ */jsxs("div", {
            className: "flex",
            children: [/* @__PURE__ */jsx("div", {
              className: "mr-2 size-4 animate-spin rounded-full border-2 border-inherit border-r-transparent"
            }), "Submitting..."]
          }) : /* @__PURE__ */jsx(Fragment, {
            children: "Submit"
          })
        })
      }) : config.customActions.map(customAction => /* @__PURE__ */jsx(Button, {
        variant: customAction.buttonVariant,
        onClick: customAction.action,
        children: customAction.name
      }, customAction.name))]
    })]
  });
}
__name(Wizard, "Wizard");

export { Wizard };
