'use client'; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import SearchBox from "@/components/input/SearchBox"; import CategoryItemRenderer from "@/components/listview/CategoryItemRenderer"; import HorizontalScrollView from "@/components/listview/HorizontalScrollView"; import Image from "next/image"; import TextAlignIcon from "@/components/icons/TextAlignIcon"; import VerticalScrollView from "@/components/listview/VerticalScrollView"; import MenuItemRenderer from "@/components/listview/MenuItemRenderer"; import React from "react"; import MenuItem from "@/components/listview/MenuItem"; import Button from "@/components/button/PrimaryButton"; import AnimatedBottomSheet from "@/components/bottomsheet/AnimatedBottomSheet"; import { Switch } from "@/components/ui/switch"; import { TicketPercentIcon } from "lucide-react"; import { Candle2, MedalStar } from 'iconsax-react' import { useQueryState } from 'next-usequerystate' import clsx from "clsx"; import CategorySmallItemRenderer from "@/components/listview/CategorySmallItemRenderer"; import { motion } from "framer-motion"; import { useTranslation } from "react-i18next"; import ComboBox, { ComboboxOption } from "@/components/combobox/Combobox"; import useToggle from "@/hooks/helpers/useToggle"; const categories = new Array(13).fill({ title: "خوراک", icon: "" }); const foods = [ { id: 1, category: 0, price: "69.000", name: "کباب چوبی ژیوان )سیخ چوبی(", contains: "فیله گوساله / سس سفید / قارچ و سیب زمینی/ پنیر پارمزان" }, { id: 2, category: 1, price: "49.000", name: "برگر گوشت گوساله", contains: "گوشت گوساله / پنیر چدار / کاهو / گوجه" }, { id: 3, category: 2, price: "29.000", name: "ساندویچ مرغ", contains: "مرغ / کاهو / گوجه / سس مایونز" }, { id: 4, category: 0, price: "89.000", name: "کباب ماهی", contains: "ماهی / سس لیمو / قارچ و سیب زمینی" }, { id: 5, category: 1, price: "39.000", name: "سالاد فصل", contains: "کاهو / گوجه / خیار / پنیر فتا" }, { id: 6, category: 3, price: "59.000", name: "پاستا گوشت", contains: "گوشت گوساله / پاستا / سس گوجه" }, { id: 7, category: 2, price: "49.000", name: "ساندویچ تن ماهی", contains: "تن ماهی / کاهو / گوجه / سس مایونز" }, { id: 8, category: 0, price: "79.000", name: "کباب گوشت گوسفندی", contains: "گوشت گوسفندی / سس سفید / قارچ و سیب زمینی" }, { id: 9, category: 1, price: "29.000", name: "برگر مرغ", contains: "مرغ / پنیر چدار / کاهو / گوجه" }, { id: 10, category: 3, price: "69.000", name: "سالاد میگو", contains: "میگو / کاهو / گوجه / خیار" }, { id: 11, category: 2, price: "39.000", name: "ساندویچ شاورما", contains: "مرغ / کاهو / گوجه / سس تارتار" }, { id: 12, category: 0, price: "99.000", name: "کباب گوشت بوقلمون", contains: "گوشت بوقلمون / سس سفید / قارچ و سیب زمینی" }, { id: 13, category: 1, price: "59.000", name: "برگر ماهی", contains: "ماهی / پنیر چدار / کاهو / گوجه" }, { id: 14, category: 3, price: "49.000", name: "سالاد مرغ", contains: "مرغ / کاهو / گوجه / خیار" } ]; const sortings = [ "PopularityDescending", "DateDescending", "PriceAscending", "RateDescending", "PriceDescending" ] const MenuIndex = () => { const { t: tCommon } = useTranslation('common'); const { t: tMenu } = useTranslation('menu', { keyPrefix: "Menu" }); const contents: Array = [ { id: '0', title: tMenu('MenuFilterDrawer.SelectContent.Options.Normal'), label: '' }, { id: '1', title: tMenu('MenuFilterDrawer.SelectContent.Options.Vegan'), label: '' }, ] const shippings: Array = [ { id: '0', title: tMenu('MenuFilterDrawer.SelectDelivery.Options.Courier'), label: '' }, ] const { state: filterModal, toggle: toggleFilterModal } = useToggle(); const { state: sortingModal, toggle: toggleSortingModal } = useToggle(); const [, setSorting] = useQueryState('sortBy', { defaultValue: '0' }); const [search, setSearch] = useQueryState("q", { defaultValue: '' }); const [selectedCategory, setSelectedCategory] = useQueryState('category', { defaultValue: '0' }); const [selectedIngredients, setSelectedIngredients] = useQueryState('ingredients', { defaultValue: '0' }); const [selectedDeliveryId, setSelectedDeliveryId] = useQueryState('delivery', { defaultValue: '0' }); const smallCategoriesRef: React.RefObject = useRef(null); const wrapperRef: React.RefObject = useRef(null); const [smallCategoriesVisible, setSmallCategoriesVisibility] = useState(false); const onScroll = useCallback(() => { if (!wrapperRef?.current?.parentElement?.parentElement?.scrollTop || !smallCategoriesRef.current?.offsetTop) return; if (wrapperRef.current.parentElement?.parentElement.scrollTop >= smallCategoriesRef.current.offsetTop) { setSmallCategoriesVisibility(true); } else { setSmallCategoriesVisibility(false); } }, [wrapperRef, smallCategoriesRef]); useEffect(() => { if (!wrapperRef.current) return; const parent = wrapperRef.current.parentElement?.parentElement; if (!parent) return; parent.addEventListener('scroll', onScroll); return () => { parent.removeEventListener('scroll', onScroll); } }, [onScroll]); const updateSearch = useCallback((e: React.ChangeEvent) => { setSearch(e.target.value); }, [setSearch]); const updateCategory = useCallback((id: number) => { setSelectedCategory(String(id)); }, [setSelectedCategory]); const changeSorting = (index: number) => { setSorting(() => String(index)); } const changeSelectedIngredients = (e: React.MouseEvent, index: number) => { setSelectedIngredients(() => contents[index]?.id || contents[0].id); } const changeSelectedDelivery = (e: React.MouseEvent, index: number) => { setSelectedDeliveryId(() => contents[index]?.id || contents[0].id); } const filteredReceiptItems = useMemo(() => { const lowerSearch = search.toLowerCase(); return foods.filter( (item) => item.category === +selectedCategory && item.name.toLowerCase().includes(lowerSearch) ); }, [selectedCategory, search]); return (
{categories.map((item, index) => ( updateCategory(index)} > category image {item.title} ))}
{categories[+selectedCategory]?.title}
{categories.map((item, index) => ( updateCategory(index)} > category image {item.title} ))} {filteredReceiptItems.map((food) => ( ))}
{tMenu('MenuFilterDrawer.PlusPoint')}
{tMenu('MenuFilterDrawer.DiscountState')}

{sortings.map((v, i) => { return (
changeSorting(i)} className="text-sm2 font-medium cursor-pointer"> {tMenu('MenuSortingDrawer.Options.' + v)}
{i < sortings.length - 1 &&
}
) })}
); }; export default MenuIndex;