import { useMemo } from '@wordpress/element'; import useGridPlans from './use-grid-plans'; import usePlanFeaturesForGridPlans from './use-plan-features-for-grid-plans'; import type { UseGridPlansParams } from './types'; import type { GridPlan } from '../../types'; const useGridPlansForFeaturesGrid = ( { allFeaturesList, coupon, eligibleForFreeHostingTrial, hasRedeemedDomainCredit, hiddenPlans, hideCurrentPlan, intent, isDisplayingPlansNeededForFeature, isInSignup, isSubdomainNotGenerated, selectedFeature, selectedPlan, showLegacyStorageFeature, siteId, term, useCheckPlanAvailabilityForPurchase, useFreeTrialPlanSlugs, highlightLabelOverrides, isDomainOnlySite, reflectStorageSelectionInPlanPrices, useVar42NoAiFeatures, usePlansGridRedesignFeatures, showPricingDifferentiationFeaturePills, useFocusedNewCopyTaglines, usePlansGridRedesignNewDescription, isExperimentVariant, showBillingDescriptionForIncreasedRenewalPrice, }: UseGridPlansParams ): GridPlan[] | null => { const gridPlans = useGridPlans( { allFeaturesList, coupon, eligibleForFreeHostingTrial, hasRedeemedDomainCredit, hiddenPlans, intent, isDisplayingPlansNeededForFeature, isSubdomainNotGenerated, selectedFeature, selectedPlan, showLegacyStorageFeature, siteId, term, useCheckPlanAvailabilityForPurchase, useFreeTrialPlanSlugs, highlightLabelOverrides, isDomainOnlySite, reflectStorageSelectionInPlanPrices, useFocusedNewCopyTaglines, usePlansGridRedesignNewDescription, showBillingDescriptionForIncreasedRenewalPrice, } ); const planFeaturesForFeaturesGrid = usePlanFeaturesForGridPlans( { allFeaturesList, gridPlans: gridPlans || [], hasRedeemedDomainCredit, intent, isInSignup, selectedFeature, showLegacyStorageFeature, useVar42NoAiFeatures, usePlansGridRedesignFeatures, showPricingDifferentiationFeaturePills, isExperimentVariant, } ); return useMemo( () => { if ( ! gridPlans ) { return null; } return gridPlans.reduce( ( acc, gridPlan ) => { if ( ! gridPlan.isVisible ) { return acc; } if ( hideCurrentPlan && gridPlan.current ) { return acc; } return [ ...acc, { ...gridPlan, features: planFeaturesForFeaturesGrid[ gridPlan.planSlug ], }, ]; }, [] as GridPlan[] ); }, [ gridPlans, planFeaturesForFeaturesGrid, hideCurrentPlan ] ); }; export default useGridPlansForFeaturesGrid;