/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

const require_runtime = require('../../_virtual/_rolldown/runtime.js');
const require_index = require('../../node_modules/classnames/index.js');
const require_pconsole = require('../../global/js/utils/pconsole.js');
const require_settings = require('../../settings.js');
const require_usePreviousValue = require('../../global/js/hooks/usePreviousValue.js');
const require_useRetrieveStepData = require('../../global/js/hooks/useRetrieveStepData.js');
const require_CreateTearsheet = require('./CreateTearsheet.js');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");

//#region src/components/CreateTearsheet/CreateTearsheetStep.tsx
/**
* Copyright IBM Corp. 2021, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const componentName = "CreateTearsheetStep";
const blockClass = `${require_settings.pkg.prefix}--tearsheet-create__step`;
const defaults = {
	hasFieldset: true,
	includeStep: true
};
const CreateTearsheetStep = (0, react.forwardRef)(({ children, className, description, disableSubmit, experimentalSecondarySubmit, fieldsetLegendText, fieldsetLegendId, hasFieldset = defaults.hasFieldset, includeStep = defaults.includeStep, introStep, invalid, onMount, onNext, onPrevious, secondaryButtonDisabled, secondaryLabel, subtitle, title, ...rest }, ref) => {
	const localRef = (0, react.useRef)(null);
	const stepRef = ref || localRef;
	const stepRefValue = stepRef.current;
	const stepsContext = (0, react.useContext)(require_CreateTearsheet.StepsContext);
	const stepNumber = (0, react.useContext)(require_CreateTearsheet.StepNumberContext);
	const [shouldIncludeStep, setShouldIncludeStep] = (0, react.useState)(includeStep);
	const previousState = require_usePreviousValue.usePreviousValue({ currentStep: stepsContext?.currentStep });
	require_useRetrieveStepData.useRetrieveStepData({
		stepsContext,
		stepNumber,
		introStep: !!introStep,
		shouldIncludeStep,
		secondaryLabel: secondaryLabel || "",
		title,
		invalid: !!invalid
	});
	(0, react.useEffect)(() => {
		if (stepNumber === stepsContext?.currentStep && previousState?.currentStep !== stepsContext?.currentStep) {
			stepsContext?.setOnMount(onMount);
			stepsContext?.setExperimentalSecondarySubmit(experimentalSecondarySubmit);
		}
	}, [
		onMount,
		experimentalSecondarySubmit,
		stepsContext,
		stepNumber,
		previousState?.currentStep
	]);
	(0, react.useEffect)(() => {
		setShouldIncludeStep(includeStep);
	}, [
		includeStep,
		stepsContext,
		title
	]);
	(0, react.useEffect)(() => {
		if (stepNumber === stepsContext?.currentStep) {
			stepsContext.setIsDisabled(!!disableSubmit);
			stepsContext?.setOnNext(onNext);
			stepsContext?.setOnPrevious(onPrevious);
			stepsContext?.setSecondaryButtonDisabled?.(!!secondaryButtonDisabled);
			stepsContext?.setExperimentalSecondarySubmit(experimentalSecondarySubmit);
		}
	}, [
		stepsContext,
		stepNumber,
		disableSubmit,
		onNext,
		onPrevious,
		secondaryButtonDisabled,
		stepRef,
		stepRefValue,
		experimentalSecondarySubmit
	]);
	const renderDescription = () => {
		if (description) {
			if (typeof description === "string") return /* @__PURE__ */ react.default.createElement("p", { className: `${blockClass}--description` }, description);
			if ((0, react.isValidElement)(description)) return /* @__PURE__ */ react.default.createElement("div", { className: `${blockClass}--description` }, description);
		}
		return null;
	};
	return stepsContext ? /* @__PURE__ */ react.default.createElement("div", {
		ref: stepRef,
		inert: stepNumber !== stepsContext?.currentStep
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.Grid, {
		...rest,
		className: (0, import_classnames.default)(blockClass, className, {
			[`${blockClass}__step--hidden-step`]: stepNumber !== stepsContext?.currentStep,
			[`${blockClass}__step--visible-step`]: stepNumber === stepsContext?.currentStep
		})
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.Column, {
		xlg: 12,
		lg: 12,
		md: 8,
		sm: 4
	}, /* @__PURE__ */ react.default.createElement("h4", { className: `${blockClass}--title` }, title), subtitle && /* @__PURE__ */ react.default.createElement("h5", { className: `${blockClass}--subtitle` }, subtitle), renderDescription()), /* @__PURE__ */ react.default.createElement(_carbon_react.Column, { span: 100 }, hasFieldset ? /* @__PURE__ */ react.default.createElement(_carbon_react.FormGroup, {
		legendText: fieldsetLegendText,
		className: `${blockClass}--fieldset`,
		legendId: fieldsetLegendId
	}, children) : children))) : require_pconsole.default.warn(`You have tried using a ${componentName} component outside of a CreateTearsheet. This is not allowed. ${componentName}s should always be children of the CreateTearsheet`);
});
CreateTearsheetStep.propTypes = {
	children: prop_types.default.node,
	className: prop_types.default.string,
	description: prop_types.default.node,
	disableSubmit: prop_types.default.bool,
	experimentalSecondarySubmit: prop_types.default.shape({
		labelText: prop_types.default.string,
		disabled: prop_types.default.bool,
		hideSecondarySubmit: prop_types.default.bool,
		onClick: prop_types.default.func
	}),
	fieldsetLegendId: prop_types.default.node,
	fieldsetLegendText: prop_types.default.string,
	hasFieldset: prop_types.default.bool,
	includeStep: prop_types.default.bool,
	introStep: prop_types.default.bool,
	invalid: prop_types.default.bool,
	onMount: prop_types.default.func,
	onNext: prop_types.default.func,
	onPrevious: prop_types.default.func,
	secondaryButtonDisabled: prop_types.default.bool,
	secondaryLabel: prop_types.default.string,
	subtitle: prop_types.default.string,
	title: prop_types.default.node.isRequired
};

//#endregion
exports.CreateTearsheetStep = CreateTearsheetStep;