/**
 * 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.
 */

import { useMemo } from "react";
import { unstable_useFeatureFlags } from "@carbon/react";
//#region src/global/js/hooks/useCarbonFeatureFlagsObject.ts
/**
* Copyright IBM Corp. 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.
*/
/**
* Custom hook that converts Carbon's FeatureFlags scope to a plain object.
* This is useful when you need to pass parent feature flags to a nested
* FeatureFlags component, ensuring all parent flags are preserved.
*
* @returns {Record<string, boolean>} An object containing all feature flags from the parent scope


*/
function useCarbonFeatureFlagsObject() {
	const parentFeatureFlags = unstable_useFeatureFlags();
	return useMemo(() => {
		const flagsObj = {};
		if (parentFeatureFlags?.flags) for (const [key, value] of parentFeatureFlags.flags) flagsObj[key] = value;
		return flagsObj;
	}, [parentFeatureFlags]);
}
//#endregion
export { useCarbonFeatureFlagsObject };
