export const DATE_KEY = 'date_created';
export const SEARCH_KEY = 'search';

/**
 * @function getColumnStyle
 * @description Get the column style.
 *
 * @since 4.3.0
 *
 * @param {object}  styleProps The style properties.
 * @param {boolean} equalGrid  Whether the grid is equal or not.
 *
 * @return {object} The column style.
 */
export const getColumnStyle = (
	styleProps = {},
	equalGrid = false
) => {
	const defaultStyle = { flex: '1 0px' };

	if ( ! styleProps || equalGrid ) {
		return defaultStyle;
	}

	// Filter style props to only allowed properties.
	const allowedProperties = [ 'flex', 'flexGrow', 'flexShrink', 'flexBasis' ];
	const filteredStyleProps = Object.keys( styleProps )
		.filter( ( key ) => allowedProperties.includes( key ) )
		.reduce( ( obj, key ) => {
			obj[ key ] = styleProps[ key ];
			return obj;
		}, {} );

	return Object.assign( defaultStyle, filteredStyleProps );
};

/**
 * @function getModules
 * @description Get the modules from module names provided
 *
 * @since 4.3.0
 *
 * @param {Array} modules     The modules to filter.
 * @param {Array} moduleNames The module names to filter.
 *
 * @return {object} The modules.
 */
export const getModules = ( modules = [], moduleNames = [] ) => {
	const initialObj = moduleNames.reduce( ( carry, moduleName ) => {
		carry[ moduleName ] = false;
		return carry;
	}, {} );

	return modules.reduce( ( carry, module ) => {
		if ( moduleNames.includes( module.name ) ) {
			return {
				...carry,
				[ module.name ]: module,
			};
		}

		return carry;
	}, initialObj );
};
