import {TagType} from './tag-types'; import React, {CSSProperties} from 'react'; import './pdp-tag.scss'; import {TagsGenericProps} from './tags-generic-props'; import {associatedCollectionsTags} from './associated-collections-tags'; const calculatedTags: Array = ['bestseller', 'trending']; interface Props extends TagsGenericProps { label: TagType | string; } const PdpTag: React.FC = ({label, onTagClick, tagLinkEnabled}) => { let type = 'generic'; const style: CSSProperties = { backgroundColor: undefined, color: undefined }; if (calculatedTags.indexOf(label) !== -1) { type = label; } else { const tagStyle = associatedCollectionsTags.find( (tag: { backgroundColor: string; color: string; name: string; tag: string; }) => tag.tag === label ); if (tagStyle) { style.backgroundColor = tagStyle.backgroundColor; style.color = tagStyle.color; } } let handleClick; if (tagLinkEnabled) { handleClick = () => { onTagClick(label); window.location.href = `/search?q=${encodeURIComponent(label)}`; }; } return (
{label.toUpperCase()}
); }; export default PdpTag;