'use client' import AnimatedBottomSheet from '@/components/bottomsheet/AnimatedBottomSheet'; import EqualizerIcon from '@/components/icons/EqualizerIcon'; import TelegramIcon from '@/components/icons/TelegramIcon'; import TabContainer from '@/components/tab/TabContainer'; import { TabHeader } from '@/components/tab/TabHeader'; import Comment from '@/components/utils/Comment'; import RateBar from '@/components/utils/RateBar'; import useToggle from '@/hooks/helpers/useToggle'; import { ArrowDown2, CallCalling, Clock, Gallery, InfoCircle, Instagram, Location, Star1, Whatsapp } from 'iconsax-react'; import { useQueryState } from 'next-usequerystate'; import Image from 'next/image'; import React from 'react' import { useGetAbout, useGetReviews, useGetSchedules } from './hooks/useAboutData'; import AboutSkeleton from './components/AboutSkeleton'; const sortings = [ 'جدیدترین', 'قدیمی ترین' ] function AboutPage() { const { data: aboutData, isLoading: aboutLoading } = useGetAbout(); const { data: reviewsData, isLoading: reviewsLoading } = useGetReviews(); const { data: schedulesData, isLoading: schedulesLoading } = useGetSchedules(); const [sorting, setSorting] = useQueryState('sortBy', { defaultValue: '0' }); const { state: sortingModal, toggle: toggleSortingModal, set: setSortingModal } = useToggle(); const shop = aboutData?.data; const schedules = schedulesData?.data || []; const isLoading = aboutLoading || reviewsLoading || schedulesLoading; if (isLoading) { return ; } const changeSorting = (index: number) => { setSorting(() => String(index)); setSortingModal(false); } const formatTime = (time: string): string => { return time.substring(0, 5); }; const getDayName = (weekDay: number): string => { const days = ['یکشنبه', 'دوشنبه', 'سه‌شنبه', 'چهارشنبه', 'پنج‌شنبه', 'جمعه', 'شنبه']; return days[weekDay] || ''; }; const groupSchedulesByDay = () => { const grouped: Record = {}; schedules .filter(schedule => schedule.isActive) .forEach(schedule => { if (!grouped[schedule.weekDay]) { grouped[schedule.weekDay] = []; } grouped[schedule.weekDay].push(schedule); }); return grouped; }; const getTodaySchedule = () => { const today = new Date().getDay(); const todaySchedules = schedules.filter(schedule => schedule.isActive && schedule.weekDay === today ); if (todaySchedules.length > 0) { const firstSchedule = todaySchedules[0]; return `${formatTime(firstSchedule.openTime)} تا ${formatTime(firstSchedule.closeTime)}`; } return null; }; const firstTab = () => { if (!shop) return null; return (

{shop.name}

{shop.establishedYear && (

تاسیس: {shop.establishedYear}

)} {shop.tagNames && shop.tagNames.length > 0 && (

نوع محصولات: {shop.tagNames.join('، ')}

)}
{shop.logo && (
logo
)}
{shop.description && (

درباره مجموعه

{shop.description}

{shop.images && shop.images.length > 0 && (
عکس های فروشگاه
)}
)}
{(shop.phone || shop.telegram || shop.whatsapp || shop.instagram) && (

ارتباط

{shop.phone && } {shop.telegram && } {shop.whatsapp && } {shop.instagram && }
)} {shop.address && (

آدرس

{shop.address}

{shop.latitude && shop.longitude && (
موقعیت روی نقشه
)}
)} {schedules.length > 0 && getTodaySchedule() && (
باز
امروز از ساعت {getTodaySchedule()}
)} {schedules.length > 0 && (
{Object.entries(groupSchedulesByDay()) .sort(([a], [b]) => Number(a) - Number(b)) .map(([weekDay, daySchedules]) => (
{getDayName(Number(weekDay))}
{daySchedules.map((schedule, index) => ( {formatTime(schedule.openTime)} - {formatTime(schedule.closeTime)} {index < daySchedules.length - 1 && '، '} ))}
))}
)}
) } const formatDate = (dateString: string): string => { const date = new Date(dateString); return date.toLocaleDateString('fa-IR', { year: 'numeric', month: 'long', day: 'numeric' }); }; const secondTab = () => { const reviews = (reviewsData?.data || []).filter(review => review.isApproved); const sortedReviews = [...reviews].sort((a, b) => { if (sorting === '0') { // جدیدترین return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); } else { // قدیمی ترین return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(); } }); const averageRating = reviews.length > 0 ? reviews.reduce((sum, review) => sum + review.rating, 0) / reviews.length : 0; const ratingCounts = { 5: reviews.filter(r => r.rating === 5).length, 4: reviews.filter(r => r.rating === 4).length, 3: reviews.filter(r => r.rating === 3).length, 2: reviews.filter(r => r.rating === 2).length, 1: reviews.filter(r => r.rating === 1).length, }; const totalReviews = reviews.length; const ratingPercentages = { 5: totalReviews > 0 ? Math.round((ratingCounts[5] / totalReviews) * 100) : 0, 4: totalReviews > 0 ? Math.round((ratingCounts[4] / totalReviews) * 100) : 0, 3: totalReviews > 0 ? Math.round((ratingCounts[3] / totalReviews) * 100) : 0, 2: totalReviews > 0 ? Math.round((ratingCounts[2] / totalReviews) * 100) : 0, 1: totalReviews > 0 ? Math.round((ratingCounts[1] / totalReviews) * 100) : 0, }; return (
{averageRating.toFixed(1)}

نظرات کاربران

{sortedReviews.length > 0 ? ( sortedReviews.map((review) => (
)) ) : (

هنوز نظری ثبت نشده است

)}
{sortings.map((v, i) => { return (
changeSorting(i)} className="text-sm2 font-normal cursor-pointer"> {v}
{i < sortings.length - 1 &&
}
) })}
) } return (
}> }>
) } export default AboutPage