'use client'; import Settings from 'settings'; import { useLocalization } from './use-localization'; type UseCommonProductAttributesArgs = { attributes: { [key: string]: { value: string } }; }; type CommonProductAttributes = { name: string; value: string }[]; export const useCommonProductAttributes = ( args: UseCommonProductAttributesArgs ) => { const { attributes } = args; const commonProductAttributes: CommonProductAttributes = []; const { t } = useLocalization(); Settings.commonProductAttributes.forEach((commonProductAttribute) => { const attribute = Object.entries(attributes).find( // Object.entries gives us an array of [key, value] pairs. ([key]) => key === commonProductAttribute.key )?.[1]; // We only want the value, so we get the second item in the array. if (attribute) { commonProductAttributes.push({ name: t( `common.common_product_attributes.${commonProductAttribute.translationKey}` ), value: attribute.value }); } }); return commonProductAttributes; };