import {useMemo, useState} from 'react'; import {Link} from 'react-router'; import {CartForm} from '@shopify/hydrogen'; import {AbiirProductListItem} from '~/components/AbiirProductListItem'; import {Shell} from '~/components/AbiirStorePages'; import type {AbiirInfoPageCms} from '~/lib/abiirStaticPages'; import {ABIIR_PRODUCT_LIST_GRID_CLASS} from '~/lib/abiirProductListGrid'; import type {AbiirProductListItemData} from '~/lib/featuredProducts'; import { ABIIR_QUIZ_PRODUCT_HANDLES_IN_ORDER, ABIIR_SKINCARE_QUIZ_QUESTIONS, getMatchingQuizProductHandles, type QuizLetter, } from '~/lib/abiirSkincareQuiz'; const TOTAL = 7; const optionButtonClass = "flex w-full cursor-pointer items-center gap-3 border border-[rgba(26,26,24,0.12)] bg-[#f8f4ef] px-4 py-3.5 text-left font-['Jost',sans-serif] text-[0.95rem] font-normal not-italic leading-snug text-[#1a1a18] transition-colors hover:border-[#c17d5c] hover:bg-[#ede8e0] sm:px-5 sm:py-4"; const optionLetterClass = "flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-[rgba(26,26,24,0.15)] bg-[#ede8e0] font-['Jost',sans-serif] text-[0.75rem] font-medium text-[#5d0b24]"; type Props = { cms: AbiirInfoPageCms; quizProducts: AbiirProductListItemData[]; }; export function AbiirSkincareQuiz({cms, quizProducts}: Props) { const [step, setStep] = useState(0); /** Index 0..6 → selected letter when that question was answered */ const [answers, setAnswers] = useState<(QuizLetter | null)[]>(() => Array.from({length: TOTAL}, () => null), ); const isResults = step >= TOTAL; const productByHandle = useMemo(() => { const m = new Map(); for (const row of quizProducts) { const h = row.handle?.trim(); if (h) m.set(h, row); } return m; }, [quizProducts]); const recommendedRows = useMemo(() => { if (!isResults) return []; if (answers.some((a) => a == null)) return []; const letters = answers as readonly QuizLetter[]; const handles = getMatchingQuizProductHandles(letters); const set = new Set(handles); const out: AbiirProductListItemData[] = []; for (const h of ABIIR_QUIZ_PRODUCT_HANDLES_IN_ORDER) { if (set.has(h)) { const row = productByHandle.get(h); if (row) out.push(row); } } return out; }, [answers, isResults, productByHandle]); const linesToAddAll = useMemo( () => recommendedRows .filter((r) => Boolean(r.firstVariantId) && r.availableForSale !== false) .map((r) => ({merchandiseId: r.firstVariantId as string, quantity: 1})), [recommendedRows], ); function choose(letter: QuizLetter) { setAnswers((prev) => { const next = [...prev]; next[step] = letter; return next; }); setStep((s) => s + 1); } function goBack() { if (step <= 0) return; if (isResults) { setStep(TOTAL - 1); return; } setStep((s) => s - 1); setAnswers((prev) => { const next = [...prev]; next[step - 1] = null; return next; }); } const q = !isResults ? ABIIR_SKINCARE_QUIZ_QUESTIONS[step] : null; return (
{!isResults && q ? ( <>

Question {step + 1} of {TOTAL}

{q.prompt}

{q.options.map((opt) => ( ))}
{step > 0 ? (
) : null} ) : ( <>

Your picks

Based on your answers, here are products we think you will love.

{recommendedRows.length ? (
{recommendedRows.map((item, index) => ( ))}
) : (

We could not match a preset bundle to every combination. Explore the full line or reach out—we are happy to help you build a ritual.

)}
{linesToAddAll.length ? ( {(fetcher) => ( )} ) : ( )} Shop all products
)}
); }