/**
 * 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_settings = require('../../settings.js');
const require_useCreateComponentFocus = require('../../global/js/hooks/useCreateComponentFocus.js');
const require_useCreateComponentStepChange = require('../../global/js/hooks/useCreateComponentStepChange.js');
const require_usePreviousValue = require('../../global/js/hooks/usePreviousValue.js');
const require_getNumberOfHiddenSteps = require('../../global/js/utils/getNumberOfHiddenSteps.js');
const require_useValidCreateStepCount = require('../../global/js/hooks/useValidCreateStepCount.js');
const require_devtools = require('../../global/js/utils/devtools.js');
const require_SimpleHeader = require('../SimpleHeader/SimpleHeader.js');
const require_ActionSet = require('../ActionSet/ActionSet.js');
const require_CreateInfluencer = require('../CreateInfluencer/CreateInfluencer.js');
const require_lastIndexInArray = require('../../global/js/utils/lastIndexInArray.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/CreateFullPage/CreateFullPage.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 blockClass = `${require_settings.pkg.prefix}--create-full-page`;
const componentName = "CreateFullPage";
const StepsContext = (0, react.createContext)(null);
const StepNumberContext = (0, react.createContext)(-1);
/**
* Use with creations that must be completed in order for a service to be usable.
*
* ### Grid
*
* The `CreateFullPage` component utilizes Carbons' grid system in the inner
content of the main section inside of the component. You can read more guidance
on the Carbon's grid system
[here](https://www.carbondesignsystem.com/guidelines/2x-grid/overview). You can
include `<Row>` and `<Column>` components inside of each `CreateFullPageStep`
component to get the desired affect.
*/
const CreateFullPage = react.default.forwardRef(({ breadcrumbsOverflowAriaLabel, breadcrumbs, backButtonText, cancelButtonText, children, className, initialStep, maxVisibleBreadcrumbs, modalDangerButtonText, modalDescription, modalSecondaryButtonText, modalTitle, nextButtonText, onClickInfluencerStep, onClose, onRequestSubmit, firstFocusElement, submitButtonText, noTrailingSlash, title, secondaryTitle, breadcrumbOverflowTooltipAlign = "right", ...rest }, ref) => {
	const [createFullPageActions, setCreateFullPageActions] = (0, react.useState)([]);
	const [shouldViewAll, setShouldViewAll] = (0, react.useState)(false);
	const [currentStep, setCurrentStep] = (0, react.useState)(1);
	const [isSubmitting, setIsSubmitting] = (0, react.useState)(false);
	const [modalIsOpen, setModalIsOpen] = (0, react.useState)(false);
	const previousState = require_usePreviousValue.usePreviousValue({ currentStep });
	const [isDisabled, setIsDisabled] = (0, react.useState)(false);
	const [onPrevious, setOnPrevious] = (0, react.useState)();
	const [onNext, setOnNext] = (0, react.useState)();
	const [onMount, setOnMount] = (0, react.useState)();
	const [stepData, setStepData] = (0, react.useState)([]);
	const [firstIncludedStep, setFirstIncludedStep] = (0, react.useState)(1);
	const [lastIncludedStep, setLastIncludedStep] = (0, react.useState)();
	const stepLength = react.default.Children.toArray(children).filter((item) => (0, react.isValidElement)(item) && item.props.includeStep !== false).length;
	(0, react.useEffect)(() => {
		const firstItem = stepData.findIndex((item) => item?.shouldIncludeStep) + 1;
		const lastItem = require_lastIndexInArray.lastIndexInArray(stepData, "shouldIncludeStep", true);
		if (firstItem !== firstIncludedStep) setFirstIncludedStep(firstItem);
		if (lastItem !== lastIncludedStep) setLastIncludedStep(lastItem);
		if (Number(initialStep) > stepLength || Number(initialStep) <= 0) setCurrentStep(1);
		else if (initialStep) {
			const numberOfHiddenSteps = require_getNumberOfHiddenSteps.getNumberOfHiddenSteps(stepData, initialStep);
			setCurrentStep(Number(initialStep + numberOfHiddenSteps));
		}
	}, [
		stepData,
		firstIncludedStep,
		lastIncludedStep,
		initialStep,
		modalIsOpen,
		stepLength
	]);
	(0, react.useEffect)(() => {
		checkForValidInitialStep();
	}, [initialStep]);
	require_useCreateComponentFocus.useCreateComponentFocus({
		previousState,
		currentStep,
		blockClass: `.${blockClass} .${require_settings.pkg.prefix}--create-full-page__step`,
		onMount,
		firstFocusElement
	});
	require_useValidCreateStepCount.useValidCreateStepCount(stepData.length, componentName);
	require_useCreateComponentStepChange.useCreateComponentStepChange({
		firstIncludedStep,
		lastIncludedStep,
		stepData,
		onPrevious,
		onNext,
		isSubmitDisabled: isDisabled,
		setCurrentStep,
		setIsSubmitting,
		setShouldViewAll,
		onClose,
		onRequestSubmit,
		componentName,
		currentStep,
		shouldViewAll,
		backButtonText,
		cancelButtonText,
		submitButtonText,
		nextButtonText,
		isSubmitting,
		componentBlockClass: blockClass,
		setCreateComponentActions: setCreateFullPageActions,
		setModalIsOpen
	});
	const checkForValidInitialStep = () => {
		if (initialStep && stepLength && Number(initialStep) > stepLength || Number(initialStep) <= 0) console.warn(`${componentName}: An invalid \`initialStep\` prop was supplied. The \`initialStep\` prop should be a number that is greater than 0 or less than or equal to the number of steps your ${componentName} has.`);
	};
	/* istanbul ignore next */
	return /* @__PURE__ */ react.default.createElement("div", {
		...rest,
		ref,
		className: (0, import_classnames.default)(blockClass, className),
		...require_devtools.getDevtoolsProps(componentName)
	}, (title || breadcrumbs) && /* @__PURE__ */ react.default.createElement(require_SimpleHeader.SimpleHeader, {
		title,
		breadcrumbs,
		noTrailingSlash,
		overflowAriaLabel: breadcrumbsOverflowAriaLabel,
		maxVisible: maxVisibleBreadcrumbs,
		className: `${blockClass}__header`,
		overflowTooltipAlign: breadcrumbOverflowTooltipAlign
	}), /* @__PURE__ */ react.default.createElement("div", { className: `${blockClass}__influencer-and-body-container` }, /* @__PURE__ */ react.default.createElement("div", { className: `${blockClass}__influencer` }, /* @__PURE__ */ react.default.createElement(require_CreateInfluencer.CreateInfluencer, {
		stepData,
		currentStep,
		title: secondaryTitle,
		onClickStep: onClickInfluencerStep
	})), /* @__PURE__ */ react.default.createElement("div", { className: `${blockClass}__body` }, /* @__PURE__ */ react.default.createElement("div", { className: `${blockClass}__main` }, /* @__PURE__ */ react.default.createElement("div", { className: `${blockClass}__content` }, /* @__PURE__ */ react.default.createElement(_carbon_react.Form, {
		className: `${blockClass}__form`,
		"aria-label": title,
		onSubmit: (e) => e.preventDefault()
	}, /* @__PURE__ */ react.default.createElement(StepsContext.Provider, { value: {
		currentStep,
		setIsDisabled,
		setOnPrevious: (fn) => setOnPrevious(() => fn),
		setOnNext: (fn) => setOnNext(() => fn),
		setOnMount: (fn) => setOnMount(() => fn),
		setStepData,
		stepData
	} }, react.default.Children.toArray(children).filter(Boolean).map((child, index) => /* @__PURE__ */ react.default.createElement(StepNumberContext.Provider, {
		value: index + 1,
		key: index
	}, child))))), /* @__PURE__ */ react.default.createElement(require_ActionSet.ActionSet, {
		className: `${blockClass}__buttons`,
		actions: createFullPageActions,
		buttonSize: "2xl",
		size: "2xl"
	}))), /* @__PURE__ */ react.default.createElement(_carbon_react.ComposedModal, {
		className: `${blockClass}__modal`,
		size: "sm",
		open: modalIsOpen,
		"aria-label": modalTitle,
		onClose: () => {
			setModalIsOpen(false);
		}
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.ModalHeader, { title: modalTitle }), /* @__PURE__ */ react.default.createElement(_carbon_react.ModalBody, null, /* @__PURE__ */ react.default.createElement("p", null, modalDescription)), /* @__PURE__ */ react.default.createElement(_carbon_react.ModalFooter, null, /* @__PURE__ */ react.default.createElement(_carbon_react.Button, {
		type: "button",
		kind: "secondary",
		onClick: () => {
			setModalIsOpen(!modalIsOpen);
		},
		"data-modal-primary-focus": true
	}, modalSecondaryButtonText), /* @__PURE__ */ react.default.createElement(_carbon_react.Button, {
		type: "button",
		kind: "danger",
		onClick: onClose
	}, modalDangerButtonText)))));
});
CreateFullPage.displayName = componentName;
CreateFullPage.propTypes = {
	backButtonText: prop_types.default.string.isRequired,
	breadcrumbOverflowTooltipAlign: _carbon_react.Tooltip.propTypes.align,
	breadcrumbs: prop_types.default.arrayOf(prop_types.default.shape({
		key: prop_types.default.string.isRequired,
		label: prop_types.default.string.isRequired,
		href: prop_types.default.string,
		title: prop_types.default.string,
		isCurrentPage: prop_types.default.bool
	})),
	breadcrumbsOverflowAriaLabel: prop_types.default.string,
	cancelButtonText: prop_types.default.string.isRequired,
	children: prop_types.default.node,
	className: prop_types.default.string,
	firstFocusElement: prop_types.default.string,
	initialStep: prop_types.default.number,
	maxVisibleBreadcrumbs: prop_types.default.number,
	modalDangerButtonText: prop_types.default.string.isRequired,
	modalDescription: prop_types.default.string,
	modalSecondaryButtonText: prop_types.default.string.isRequired,
	modalTitle: prop_types.default.string.isRequired,
	nextButtonText: prop_types.default.string.isRequired,
	noTrailingSlash: prop_types.default.bool,
	onClickInfluencerStep: prop_types.default.func,
	onClose: prop_types.default.func,
	onRequestSubmit: prop_types.default.func.isRequired,
	secondaryTitle: prop_types.default.string,
	sideNavAriaLabel: prop_types.default.string,
	submitButtonText: prop_types.default.string.isRequired,
	title: prop_types.default.string
};

//#endregion
exports.CreateFullPage = CreateFullPage;
exports.StepNumberContext = StepNumberContext;
exports.StepsContext = StepsContext;