import React, { useState } from 'react'; // Utils import { MESSAGES } from '../../../../utils/message'; // // icons import Dot from '../../../../assets/images/templates/dot'; import ArrowDown from '../../../../assets/images/templates/arrow-down'; import Button from '../../../GenericUIBlocks/Button'; import Typography from '../../../GenericUIBlocks/Typography'; // styles import './styles.scss'; const TemplatesCard = (props: any) => { const { templates, loading, handleLoadTemplateModel, platformName, currentTemplateType, product, searchApplied, primaryColorRGBA, designerQueryAmount, } = props; const [isFilpedIds, setIsFlipedIds] = useState([]); const singleSideProducts = [2, 4, 5, 16]; // handler for Flip const handleFlip = (templateId: string) => { const existingTemplateIds = isFilpedIds || []; let updatedIds: string[]; if (existingTemplateIds.includes(templateId)) { updatedIds = existingTemplateIds.filter((item) => item !== templateId); } else { updatedIds = [...existingTemplateIds, templateId]; } setIsFlipedIds(updatedIds); }; // handler for setting color const colorSetter = (templateId: any, side: string) => { const result = !isFilpedIds.includes(templateId) && side === 'Front' ? { fill: '#FFFFFF' } : isFilpedIds.includes(templateId) && side === 'Back' ? { fill: '#FFFFFF' } : { fill: '#878585' }; return result; }; // handler for setting rotation const transformSetter = (templateId: any) => { const result = isFilpedIds.includes(templateId) ? { transform: 'rotateY(0deg)', boxShadow: `inset 0 0 0 2px ${primaryColorRGBA}`, } : { transform: 'rotateY(360deg)', boxShadow: `inset 0 0 0 2px ${primaryColorRGBA}`, }; return result; }; return ( <> {loading ? (
{MESSAGES.TEMPLATE.LOADING_TEMPLATE}
) : templates.length ? ( templates.map((template: any, index: string) => { return (
template {!singleSideProducts.includes(Number(product?.id)) && (
handleFlip(template?.id)} style={colorSetter(template?.id, 'Front')} /> handleFlip(template?.id)} style={colorSetter(template?.id, 'Back')} /> handleLoadTemplateModel(template)} />
)}
{template?.title} Template ID: {template?.id}
); }) ) : currentTemplateType?.id === '1' ? (
{MESSAGES.TEMPLATE.NO_MY_TEMPLATES}
) : currentTemplateType?.id === '2' ? (
{MESSAGES.TEMPLATE.NO_TEAM_TEMPLATES}
) : currentTemplateType?.id === '3' ? (
{platformName ? `No ${platformName} Templates to show` : MESSAGES.TEMPLATE.NO_OLC_TEMPLATES}
) : ( <> )} ); }; export default TemplatesCard;