'use client' import { FC, useState } from 'react' import { ArrowLeft2 } from 'iconsax-react' import { useRouter } from 'next/navigation' type Props = { isOpen: boolean onClose: () => void } const CategoryModal: FC = ({ isOpen, onClose }) => { const router = useRouter() const [selectedMainCategory, setSelectedMainCategory] = useState(0) const [expandedSubcategory, setExpandedSubcategory] = useState(null) // Main categories for the left column const mainCategories = [ { icon: '🏪', title: 'سوپر مارکت ارگانیک' }, { icon: '🍞', title: 'خانه نان و شیرینی سالم' }, { icon: '🍎', title: 'بوفه رژیم‌های خاص' }, { icon: '💪', title: 'بوفه سبک زندگی' }, { icon: '🌿', title: 'عطاری سلامت' }, { icon: '🎁', title: 'بوفه هدایا و سوغات' } ] // Subcategories for each main category const categorySubcategories = { 'سوپر مارکت ارگانیک': [ { title: 'ارگانیک گواهی‌دار', hasChildren: false }, { title: 'روغن های سالم', hasChildren: true }, { title: 'چاشنی سلامت', hasChildren: true }, { title: 'صبحانه سالم', hasChildren: false }, { title: 'نوشیدنی سالم', hasChildren: false }, { title: 'آرایشی', hasChildren: false }, { title: 'بهداشتی', hasChildren: false }, { title: 'تازه خوری', hasChildren: false }, { title: 'حبوبات و غلات', hasChildren: false }, { title: 'تنقلات', hasChildren: false }, { title: 'چای و دمنوش', hasChildren: false }, { title: 'قهوه', hasChildren: false }, { title: 'قند و شکر', hasChildren: false } ], 'خانه نان و شیرینی سالم': [ { title: 'نان سنتی', hasChildren: false }, { title: 'نان صنعتی', hasChildren: false }, { title: 'شیرینی', hasChildren: false }, { title: 'کیک و کلوچه', hasChildren: false } ], 'بوفه رژیم‌های خاص': [ { title: 'رژیم کتو', hasChildren: false }, { title: 'رژیم وگان', hasChildren: false }, { title: 'بدون گلوتن', hasChildren: false } ], 'بوفه سبک زندگی': [ { title: 'ورزشی', hasChildren: false }, { title: 'لاغری', hasChildren: false }, { title: 'سالمندان', hasChildren: false } ], 'عطاری سلامت': [ { title: 'گیاهان دارویی', hasChildren: false }, { title: 'عسل طبیعی', hasChildren: false }, { title: 'دمنوش', hasChildren: false } ], 'بوفه هدایا و سوغات': [ { title: 'هدایا', hasChildren: false }, { title: 'سوغات', hasChildren: false }, { title: 'بسته بندی ویژه', hasChildren: false } ] } // Third level subcategories (for items that expand) const thirdLevelCategories = { 'روغن های سالم': [ { icon: '🫒', title: 'روغن زیتون پیوست و مو' }, { icon: '🌻', title: 'روغن ماساژ' }, { icon: '🥥', title: 'روغن های خوراکی' } ], 'چاشنی سلامت': [ { icon: '🥒', title: 'ترشی' }, { icon: '🥫', title: 'رب ها' }, { icon: '🍯', title: 'سس ها' }, { icon: '🥬', title: 'سبزیجات خشک' }, { icon: '🌶️', title: 'ادویه' }, { icon: '🍎', title: 'سرکه' }, { icon: '🫒', title: 'زیتون' } ] } const handleMainCategoryClick = (index: number) => { setSelectedMainCategory(index) setExpandedSubcategory(null) } const handleSubcategoryClick = (subcategory: { title: string; hasChildren: boolean }) => { if (subcategory.hasChildren && thirdLevelCategories[subcategory.title as keyof typeof thirdLevelCategories]) { setExpandedSubcategory(expandedSubcategory === subcategory.title ? null : subcategory.title) } else { router.push(`/products/${subcategory.title}`) onClose() } } if (!isOpen) return null const currentMainCategory = mainCategories[selectedMainCategory] const currentSubcategories = categorySubcategories[currentMainCategory.title as keyof typeof categorySubcategories] || [] return (
{/* Left Column - Main Categories */}
{mainCategories.map((category, index) => (
handleMainCategoryClick(index)} >
{category.icon}
{category.title}
{index < mainCategories.length - 1 && (
)}
))}
{/* Right Column - Subcategories */}
{/* Special Categories */}
{ router.push('/products') onClose() }} > همه محصولات سوپر مارکت ارگانیک
{ router.push('/products/organic') onClose() }} > ارگانیک گواهی‌دار
{/* Subcategories List */}
{currentSubcategories.map((subcategory, index) => (
handleSubcategoryClick(subcategory)} > {subcategory.title} {subcategory.hasChildren && ( )}
{/* Expanded third level categories */} {expandedSubcategory === subcategory.title && thirdLevelCategories[subcategory.title as keyof typeof thirdLevelCategories] && (
همه محصولات {subcategory.title}
{thirdLevelCategories[subcategory.title as keyof typeof thirdLevelCategories].map((item, itemIndex) => (
{ router.push(`/products/${item.title}`) onClose() }} >
{item.icon}
{item.title}
))}
)} {index < currentSubcategories.length - 1 && (
)}
))}
) } export default CategoryModal