feat(media): implement omnichannel media gallery with drag-and-drop, video support, and quick access podcast/video hub
This commit is contained in:
1 parent
32e40a820c
commit
d9c693c41b
13 files changed
+9449
-8874
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { Search, Filter, Box, Plus, Edit2, Trash2, Image as ImageIcon, X, HelpCircle, ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
|
||||
import { Search, Filter, Box, Plus, Edit2, Trash2, Image as ImageIcon, X, HelpCircle, ArrowUpDown, ArrowUp, ArrowDown, GripVertical, Film, Play, ChevronRight, ChevronLeft, Link2 } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api, { BASE_DOMAIN } from '../services/api';
|
||||
import Spinner from '../components/ui/Spinner';
|
||||
@@ -224,6 +224,85 @@ export default function Products() {
|
||||
preorderDeposit: '' as number | string
|
||||
});
|
||||
|
||||
const [draggedMediaIdx, setDraggedMediaIdx] = useState<number | null>(null);
|
||||
const [dragOverMediaIdx, setDragOverMediaIdx] = useState<number | null>(null);
|
||||
const [customMediaUrl, setCustomMediaUrl] = useState('');
|
||||
const [showCustomMediaInput, setShowCustomMediaInput] = useState(false);
|
||||
|
||||
const isVideoMedia = (url?: string) => {
|
||||
if (!url) return false;
|
||||
const clean = url.toLowerCase().trim();
|
||||
return (
|
||||
clean.endsWith('.mp4') ||
|
||||
clean.endsWith('.webm') ||
|
||||
clean.endsWith('.mov') ||
|
||||
clean.endsWith('.mkv') ||
|
||||
clean.endsWith('.m4v') ||
|
||||
clean.includes('aparat.com') ||
|
||||
clean.includes('youtube.com') ||
|
||||
clean.includes('youtu.be') ||
|
||||
clean.includes('vimeo.com') ||
|
||||
clean.includes('/video/') ||
|
||||
clean.startsWith('data:video')
|
||||
);
|
||||
};
|
||||
|
||||
const handleDragStart = (idx: number) => {
|
||||
setDraggedMediaIdx(idx);
|
||||
};
|
||||
|
||||
const handleDragOver = (e: React.DragEvent, idx: number) => {
|
||||
e.preventDefault();
|
||||
if (dragOverMediaIdx !== idx) {
|
||||
setDragOverMediaIdx(idx);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDragLeave = () => {
|
||||
setDragOverMediaIdx(null);
|
||||
};
|
||||
|
||||
const handleDrop = (e: React.DragEvent, dropIdx: number) => {
|
||||
e.preventDefault();
|
||||
if (draggedMediaIdx === null || draggedMediaIdx === dropIdx) {
|
||||
setDraggedMediaIdx(null);
|
||||
setDragOverMediaIdx(null);
|
||||
return;
|
||||
}
|
||||
const updated = [...(formData.images || [])];
|
||||
const [movedItem] = updated.splice(draggedMediaIdx, 1);
|
||||
updated.splice(dropIdx, 0, movedItem);
|
||||
setFormData(prev => ({ ...prev, images: updated }));
|
||||
setDraggedMediaIdx(null);
|
||||
setDragOverMediaIdx(null);
|
||||
};
|
||||
|
||||
const handleMoveMedia = (idx: number, direction: 'left' | 'right') => {
|
||||
const images = formData.images || [];
|
||||
// In RTL layout, 'left' button visually moves item forward (idx + 1), 'right' moves item backward (idx - 1)
|
||||
const targetIdx = direction === 'left' ? idx + 1 : idx - 1;
|
||||
if (targetIdx < 0 || targetIdx >= images.length) return;
|
||||
const updated = [...images];
|
||||
const temp = updated[idx];
|
||||
updated[idx] = updated[targetIdx];
|
||||
updated[targetIdx] = temp;
|
||||
setFormData(prev => ({ ...prev, images: updated }));
|
||||
};
|
||||
|
||||
const handleAddCustomMedia = () => {
|
||||
const trimmed = customMediaUrl.trim();
|
||||
if (!trimmed) return;
|
||||
const currentImages = formData.images || [];
|
||||
if (!currentImages.includes(trimmed)) {
|
||||
setFormData(prev => ({ ...prev, images: [...currentImages, trimmed] }));
|
||||
toast.success(isVideoMedia(trimmed) ? 'ویدیو به گالری اضافه شد' : 'تصویر به گالری اضافه شد');
|
||||
} else {
|
||||
toast.error('این لینک قبلاً در گالری ثبت شده است');
|
||||
}
|
||||
setCustomMediaUrl('');
|
||||
setShowCustomMediaInput(false);
|
||||
};
|
||||
|
||||
const openModal = (product?: Product) => {
|
||||
setMediaImageError(false);
|
||||
if (product) {
|
||||
@@ -1655,62 +1734,208 @@ export default function Products() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Product Gallery Images (Multiple Angles & Views) */}
|
||||
{/* Product Gallery Media (Images & Videos with Drag & Drop Reordering) */}
|
||||
<div className="bg-white p-5 rounded-2xl border border-gray-200 shadow-sm space-y-4">
|
||||
<div className="flex items-center justify-between border-b pb-2">
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 border-b pb-3">
|
||||
<div>
|
||||
<h4 className="font-bold text-gray-800 text-sm flex items-center gap-2">
|
||||
<ImageIcon className="w-4 h-4 text-blue-600" />
|
||||
گالری تصاویر جانبی محصول (Gallery Images)
|
||||
<span>گالری چندرسانهای محصول (تصاویر و ویدیوها)</span>
|
||||
{formData.images && formData.images.length > 0 && (
|
||||
<span className="text-[10px] font-bold bg-blue-50 text-blue-700 px-2 py-0.5 rounded-full border border-blue-100 font-mono">
|
||||
{formData.images.length} آیتم
|
||||
</span>
|
||||
)}
|
||||
</h4>
|
||||
<p className="text-[11px] text-gray-400 font-medium mt-0.5">تصاویر زوایای مختلف، پشت بستهبندی، جدول ارزش غذایی و مشخصات فنی</p>
|
||||
<p className="text-[11px] text-gray-400 font-medium mt-0.5">
|
||||
ترتیب نمایش را با کشیدن و رها کردن (Drag & Drop) یا دکمههای جابهجایی تغییر دهید. پشتیبانی از انواع تصاویر و ویدیوها (MP4 / آپارات / یوتیوب).
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowCustomMediaInput(prev => !prev)}
|
||||
className="bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer flex items-center gap-1.5"
|
||||
>
|
||||
<Link2 className="w-3.5 h-3.5" />
|
||||
لینک ویدیو / تصویر
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMediaTargetField('gallery');
|
||||
setIsMediaSelectorOpen(true);
|
||||
}}
|
||||
className="bg-blue-600 hover:bg-blue-700 text-white px-3.5 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer flex items-center gap-1.5 shadow-xs"
|
||||
>
|
||||
<Plus className="w-3.5 h-3.5" />
|
||||
افزودن از رسانهها
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMediaTargetField('gallery');
|
||||
setIsMediaSelectorOpen(true);
|
||||
}}
|
||||
className="bg-blue-600 hover:bg-blue-700 text-white px-4 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer flex items-center gap-1.5"
|
||||
>
|
||||
<Plus className="w-3.5 h-3.5" />
|
||||
افزودن عکس به گالری
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Custom URL Form */}
|
||||
{showCustomMediaInput && (
|
||||
<div className="p-3 bg-blue-50/60 border border-blue-100 rounded-xl space-y-2 animate-in fade-in duration-150">
|
||||
<label className="text-xs font-bold text-blue-900 block">
|
||||
افزودن مستقیم آدرس اینترنتی رسانه (عکس یا ویدیو):
|
||||
</label>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={customMediaUrl}
|
||||
onChange={(e) => setCustomMediaUrl(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
handleAddCustomMedia();
|
||||
}
|
||||
}}
|
||||
placeholder="https://... یا /uploads/video.mp4 یا لینک آپارات / یوتیوب"
|
||||
className="flex-1 px-3 py-2 rounded-xl border border-blue-200 bg-white font-mono text-xs outline-none focus:ring-2 focus:ring-blue-500"
|
||||
dir="ltr"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleAddCustomMedia}
|
||||
className="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-xl text-xs font-bold whitespace-nowrap cursor-pointer"
|
||||
>
|
||||
ثبت در گالری
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setCustomMediaUrl('');
|
||||
setShowCustomMediaInput(false);
|
||||
}}
|
||||
className="px-3 py-2 bg-gray-200 hover:bg-gray-300 text-gray-700 rounded-xl text-xs font-bold cursor-pointer"
|
||||
>
|
||||
انصراف
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Gallery Grid with Drag & Drop */}
|
||||
{formData.images && formData.images.length > 0 ? (
|
||||
<div className="grid grid-cols-2 sm:grid-cols-4 md:grid-cols-6 gap-3">
|
||||
{formData.images.map((imgUrl, idx) => (
|
||||
<div key={idx} className="relative group rounded-xl border border-gray-200 overflow-hidden bg-gray-50 aspect-square flex items-center justify-center p-2 shadow-xs">
|
||||
<img
|
||||
src={getProductImageUrl(imgUrl)}
|
||||
alt={`Gallery ${idx + 1}`}
|
||||
className="max-h-full max-w-full object-contain"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-1.5 p-1">
|
||||
<button
|
||||
type="button"
|
||||
title="حذف از گالری"
|
||||
onClick={() => {
|
||||
const updated = formData.images.filter((_, i) => i !== idx);
|
||||
setFormData({ ...formData, images: updated });
|
||||
}}
|
||||
className="w-7 h-7 rounded-lg bg-red-600 hover:bg-red-700 text-white flex items-center justify-center transition-colors"
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-3">
|
||||
{formData.images.map((mediaUrl, idx) => {
|
||||
const isVideo = isVideoMedia(mediaUrl);
|
||||
const isDragging = draggedMediaIdx === idx;
|
||||
const isOver = dragOverMediaIdx === idx;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
draggable
|
||||
onDragStart={() => handleDragStart(idx)}
|
||||
onDragOver={(e) => handleDragOver(e, idx)}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={(e) => handleDrop(e, idx)}
|
||||
onDragEnd={() => {
|
||||
setDraggedMediaIdx(null);
|
||||
setDragOverMediaIdx(null);
|
||||
}}
|
||||
className={`relative group rounded-2xl border transition-all aspect-square flex flex-col items-center justify-center p-2 select-none cursor-grab active:cursor-grabbing ${
|
||||
isOver
|
||||
? 'border-purple-600 bg-purple-50 scale-105 shadow-lg ring-2 ring-purple-400'
|
||||
: isDragging
|
||||
? 'opacity-40 border-dashed border-gray-400 bg-gray-100 scale-95'
|
||||
: 'border-gray-200 bg-gray-50/80 hover:border-purple-300 hover:shadow-md'
|
||||
}`}
|
||||
>
|
||||
{/* Grip Handle Icon */}
|
||||
<div className="absolute top-1.5 right-1.5 w-6 h-6 rounded-lg bg-black/40 backdrop-blur-xs text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10">
|
||||
<GripVertical className="w-3.5 h-3.5" />
|
||||
</div>
|
||||
|
||||
{/* Media Preview (Video or Image) */}
|
||||
{isVideo ? (
|
||||
<div className="w-full h-full flex flex-col items-center justify-center relative rounded-xl overflow-hidden bg-neutral-900 text-white">
|
||||
<Film className="w-8 h-8 text-blue-400 opacity-60 mb-1" />
|
||||
<div className="w-7 h-7 rounded-full bg-blue-600 text-white flex items-center justify-center shadow-md">
|
||||
<Play className="w-3.5 h-3.5 fill-white ml-0.5" />
|
||||
</div>
|
||||
<span className="absolute bottom-1 right-1 bg-blue-600/90 text-white text-[8px] font-bold px-1.5 py-0.5 rounded font-vazir">
|
||||
ویدیو
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<img
|
||||
src={getProductImageUrl(mediaUrl)}
|
||||
alt={`Gallery ${idx + 1}`}
|
||||
className="max-h-full max-w-full object-contain pointer-events-none"
|
||||
onError={(e) => {
|
||||
(e.target as HTMLElement).style.display = 'none';
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Overlay on hover: Delete & Move Left/Right */}
|
||||
<div className="absolute inset-0 bg-black/70 backdrop-blur-2xs opacity-0 group-hover:opacity-100 transition-opacity rounded-2xl flex flex-col items-center justify-between p-2 z-20">
|
||||
<div className="w-full flex items-center justify-between">
|
||||
<span className="text-[10px] text-white/90 font-mono font-bold">
|
||||
#{idx + 1}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
title="حذف از گالری"
|
||||
onClick={() => {
|
||||
const updated = formData.images.filter((_, i) => i !== idx);
|
||||
setFormData(prev => ({ ...prev, images: updated }));
|
||||
}}
|
||||
className="w-6 h-6 rounded-lg bg-red-600 hover:bg-red-700 text-white flex items-center justify-center transition-colors cursor-pointer"
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="text-center">
|
||||
<span className="text-[9px] text-white/70 block truncate max-w-[100px]" dir="ltr">
|
||||
{mediaUrl.split('/').pop()?.slice(0, 15) || 'رسانه'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Reorder buttons (left/right for quick shift) */}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
disabled={idx === 0}
|
||||
title="انتقال به عقب"
|
||||
onClick={() => handleMoveMedia(idx, 'right')}
|
||||
className="w-6 h-6 rounded-md bg-white/20 hover:bg-white/40 disabled:opacity-30 disabled:cursor-not-allowed text-white flex items-center justify-center transition-colors cursor-pointer"
|
||||
>
|
||||
<ChevronRight className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={idx === formData.images.length - 1}
|
||||
title="انتقال به جلو"
|
||||
onClick={() => handleMoveMedia(idx, 'left')}
|
||||
className="w-6 h-6 rounded-md bg-white/20 hover:bg-white/40 disabled:opacity-30 disabled:cursor-not-allowed text-white flex items-center justify-center transition-colors cursor-pointer"
|
||||
>
|
||||
<ChevronLeft className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Index badge when not hovered */}
|
||||
<span className="absolute bottom-1 right-1 bg-black/60 text-white text-[9px] px-1.5 py-0.5 rounded font-mono group-hover:opacity-0 transition-opacity">
|
||||
#{idx + 1}
|
||||
</span>
|
||||
</div>
|
||||
<span className="absolute bottom-1 right-1 bg-black/60 text-white text-[9px] px-1.5 py-0.5 rounded font-mono">
|
||||
#{idx + 1}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-6 text-gray-400 bg-gray-50/50 rounded-xl border border-dashed border-gray-200">
|
||||
<ImageIcon className="w-8 h-8 mx-auto mb-2 opacity-30 text-gray-400" />
|
||||
<p className="text-xs font-bold text-gray-500">هنوز عکس جانبی به گالری محصول اضافه نشده است.</p>
|
||||
<p className="text-[10px] text-gray-400 mt-1">با زدن دکمه «افزودن عکس به گالری» میتوانید چند عکس اضافه نمایید.</p>
|
||||
<div className="text-center py-8 text-gray-400 bg-gray-50/50 rounded-2xl border border-dashed border-gray-200 space-y-2">
|
||||
<div className="w-12 h-12 rounded-2xl bg-gray-100 flex items-center justify-center mx-auto text-gray-400">
|
||||
<ImageIcon className="w-6 h-6 opacity-40" />
|
||||
</div>
|
||||
<p className="text-xs font-bold text-gray-600">گالری محصول خالی است.</p>
|
||||
<p className="text-[11px] text-gray-400">
|
||||
با زدن دکمه «افزودن از رسانهها» یا «لینک ویدیو / تصویر» میتوانید تصاویر جانبی یا ویدیوهای محصول را اضافه کنید.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -32,7 +32,10 @@ import {
|
||||
Share2,
|
||||
Phone,
|
||||
Download,
|
||||
Play
|
||||
Play,
|
||||
Film,
|
||||
Headphones,
|
||||
Volume2
|
||||
} from "lucide-react";
|
||||
|
||||
const ICON_MAP: Record<string, React.ComponentType<{ className?: string }>> = {
|
||||
@@ -80,6 +83,46 @@ const ProductImageZoomModal = dynamic(() => import("./ProductImageZoomModal"), {
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
interface GalleryMediaItem {
|
||||
id: string;
|
||||
type: 'image' | 'video' | 'podcast';
|
||||
url: string;
|
||||
thumbnail: string;
|
||||
title: string;
|
||||
badge?: string;
|
||||
videoData?: {
|
||||
title?: string;
|
||||
doctor?: string;
|
||||
description?: string;
|
||||
videoUrl?: string;
|
||||
thumbnail?: string;
|
||||
};
|
||||
podcastData?: {
|
||||
audioUrl?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
cover?: string;
|
||||
};
|
||||
}
|
||||
|
||||
function isVideoUrl(url?: string): boolean {
|
||||
if (!url) return false;
|
||||
const clean = url.toLowerCase().trim();
|
||||
return (
|
||||
clean.endsWith('.mp4') ||
|
||||
clean.endsWith('.webm') ||
|
||||
clean.endsWith('.mov') ||
|
||||
clean.endsWith('.mkv') ||
|
||||
clean.endsWith('.m4v') ||
|
||||
clean.includes('aparat.com') ||
|
||||
clean.includes('youtube.com') ||
|
||||
clean.includes('youtu.be') ||
|
||||
clean.includes('vimeo.com') ||
|
||||
clean.includes('/video/') ||
|
||||
clean.startsWith('data:video')
|
||||
);
|
||||
}
|
||||
|
||||
export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
const router = useRouter();
|
||||
const [product, setProduct] = useState<Product | null>(null);
|
||||
@@ -91,10 +134,18 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
const [dosageConfig, setDosageConfig] = useState<DosageConfig | null>(null);
|
||||
const [isFullDescriptionOpen, setIsFullDescriptionOpen] = useState(false);
|
||||
|
||||
const [activeMediaIndex, setActiveMediaIndex] = useState(0);
|
||||
const [activeImage, setActiveImage] = useState<string | null>(null);
|
||||
const [isImageZoomOpen, setIsImageZoomOpen] = useState(false);
|
||||
const [isVideoModalOpen, setIsVideoModalOpen] = useState(false);
|
||||
const [isFullVideoDescOpen, setIsFullVideoDescOpen] = useState(false);
|
||||
const [activeMediaForVideoModal, setActiveMediaForVideoModal] = useState<{
|
||||
title?: string;
|
||||
doctor?: string;
|
||||
videoUrl?: string;
|
||||
thumbnail?: string;
|
||||
description?: string;
|
||||
} | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
Promise.resolve().then(() => setIsMounted(true));
|
||||
@@ -229,6 +280,99 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
Promise.resolve().then(() => setItemQuantity(suggestedQty));
|
||||
}, [calculation?.duration]);
|
||||
|
||||
// Omnichannel Product Media Gallery (Featured Image + Gallery Images/Videos + Dedicated Video + Podcast)
|
||||
const galleryMedia = useMemo<GalleryMediaItem[]>(() => {
|
||||
if (!product) return [];
|
||||
const items: GalleryMediaItem[] = [];
|
||||
|
||||
// 1. Featured Image (Always first)
|
||||
if (product.image) {
|
||||
items.push({
|
||||
id: 'featured-image',
|
||||
type: 'image',
|
||||
url: product.image,
|
||||
thumbnail: product.image,
|
||||
title: product.nameFa || product.name || 'تصویر شاخص محصول',
|
||||
badge: 'تصویر اصلی'
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Additional Gallery Media from product.images in custom configured order
|
||||
if (product.images && Array.isArray(product.images)) {
|
||||
product.images.forEach((mUrl, idx) => {
|
||||
if (!mUrl || mUrl === product.image) return;
|
||||
const isVid = isVideoUrl(mUrl);
|
||||
if (isVid) {
|
||||
items.push({
|
||||
id: `gallery-vid-${idx}`,
|
||||
type: 'video',
|
||||
url: mUrl,
|
||||
thumbnail: product.videoCover || product.image,
|
||||
title: `ویدیو معرفی ${idx + 1}`,
|
||||
badge: 'ویدیو',
|
||||
videoData: {
|
||||
title: `ویدیو محصول ${product.nameFa || product.name}`,
|
||||
doctor: 'کادر علمی و تخصصی کنینا',
|
||||
videoUrl: mUrl,
|
||||
thumbnail: product.videoCover || product.image,
|
||||
description: product.videoDescription || product.description,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
items.push({
|
||||
id: `gallery-img-${idx}`,
|
||||
type: 'image',
|
||||
url: mUrl,
|
||||
thumbnail: mUrl,
|
||||
title: `تصویر گالری ${idx + 1}`,
|
||||
badge: 'تصویر'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 3. Dedicated Video (product.videoUrl) if present and not duplicated
|
||||
if (product.videoUrl && !items.some(it => it.url === product.videoUrl)) {
|
||||
items.push({
|
||||
id: 'dedicated-video',
|
||||
type: 'video',
|
||||
url: product.videoUrl,
|
||||
thumbnail: product.videoCover || product.image,
|
||||
title: product.videoTitle || 'ویدیو راهنمای مصرف و معرفی',
|
||||
badge: 'ویدیوکست',
|
||||
videoData: {
|
||||
title: product.videoTitle || `ویدیو راهنمای ${product.nameFa || product.name}`,
|
||||
doctor: 'کادر علمی و تخصصی کنینا',
|
||||
videoUrl: product.videoUrl,
|
||||
thumbnail: product.videoCover || product.image,
|
||||
description: product.videoDescription || product.description,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 4. Dedicated Podcast (product.podcastUrl) if present and not duplicated
|
||||
if (product.podcastUrl && !items.some(it => it.url === product.podcastUrl)) {
|
||||
items.push({
|
||||
id: 'dedicated-podcast',
|
||||
type: 'podcast',
|
||||
url: product.podcastUrl,
|
||||
thumbnail: product.podcastCover || product.image,
|
||||
title: product.podcastTitle || 'پادکست و بررسی صوتی بالینی',
|
||||
badge: 'پادکست',
|
||||
podcastData: {
|
||||
audioUrl: product.podcastUrl,
|
||||
title: product.podcastTitle || 'پادکست و بررسی صوتی بالینی مکمل',
|
||||
description: product.podcastDescription || product.description,
|
||||
cover: product.podcastCover || product.image,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
}, [product]);
|
||||
|
||||
const activeMedia = galleryMedia[activeMediaIndex] || galleryMedia[0];
|
||||
|
||||
if (isLoading) return (
|
||||
<div className="min-h-screen bg-medical-gray-50 p-6 max-w-7xl mx-auto font-vazir" dir="rtl">
|
||||
<div className="animate-pulse space-y-6">
|
||||
@@ -292,16 +436,17 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
|
||||
{/* Above the Fold Grid */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-12 gap-4 sm:gap-8 md:gap-12 items-center md:items-start text-center md:text-right font-vazir w-full" dir="rtl">
|
||||
{/* Right Column: Product Image Frame & Gallery (md:col-span-5) */}
|
||||
{/* Right Column: Omnichannel Product Media Hub & Gallery (md:col-span-5) */}
|
||||
<div className="md:col-span-5 w-full mx-auto max-w-sm md:max-w-none space-y-3 sm:space-y-4">
|
||||
<motion.div
|
||||
initial={{ opacity: 0, scale: 0.95 }}
|
||||
key={activeMedia?.id || 'media-box'}
|
||||
initial={{ opacity: 0, scale: 0.96 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
onClick={() => setIsImageZoomOpen(true)}
|
||||
className="bg-white rounded-2xl sm:rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[260px] sm:h-[380px] flex items-center justify-center p-2 sm:p-4 cursor-zoom-in"
|
||||
title="کلیک برای مشاهده تصویر بزرگتر"
|
||||
transition={{ duration: 0.2 }}
|
||||
className="bg-white rounded-2xl sm:rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[280px] sm:h-[390px] flex items-center justify-center p-2 sm:p-4 select-none"
|
||||
>
|
||||
<div className="absolute top-4 left-4 sm:top-6 sm:left-6 flex flex-col gap-1.5 sm:gap-2 z-10 items-start">
|
||||
{/* Top Floating Badges */}
|
||||
<div className="absolute top-4 left-4 sm:top-6 sm:left-6 flex flex-col gap-1.5 sm:gap-2 z-10 items-start pointer-events-none">
|
||||
{product.specialBadge && (
|
||||
<div className="px-2.5 py-1 bg-medical-gray-900 text-white rounded-full text-[9px] sm:text-[10px] font-black uppercase tracking-widest font-vazir whitespace-nowrap shadow-sm">
|
||||
{product.specialBadge}
|
||||
@@ -323,7 +468,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
</div>
|
||||
|
||||
{/* Species Suitable Badges (Dog / Cat) */}
|
||||
<div className="absolute bottom-4 left-4 flex gap-1.5 z-10">
|
||||
<div className="absolute bottom-4 left-4 flex gap-1.5 z-10 pointer-events-none">
|
||||
{(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && (
|
||||
<div className="w-7 h-7 bg-white/90 backdrop-blur-sm rounded-lg flex items-center justify-center text-medical-gray-600 border border-medical-gray-200 shadow-sm" title="مناسب برای سگ">
|
||||
<Dog className="w-4 h-4 text-canina-blue" />
|
||||
@@ -335,55 +480,159 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<SafeImage
|
||||
src={activeImage || product.image}
|
||||
alt={product.name}
|
||||
priority={true}
|
||||
sizes="(max-width: 768px) 100vw, 400px"
|
||||
className="w-full h-full"
|
||||
imgClassName="w-full h-full object-contain drop-shadow-2xl group-hover:scale-105 transition-transform duration-700 mx-auto my-auto"
|
||||
/>
|
||||
<div className="absolute bottom-4 right-4 bg-black/60 backdrop-blur-md text-white px-3 py-1 rounded-full text-[10px] font-black flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<span>بزرگنمایی</span>
|
||||
</div>
|
||||
|
||||
{/* 1. Image Viewer */}
|
||||
{(!activeMedia || activeMedia.type === 'image') && (
|
||||
<div
|
||||
onClick={() => setIsImageZoomOpen(true)}
|
||||
className="w-full h-full flex items-center justify-center cursor-zoom-in relative"
|
||||
title="کلیک برای مشاهده تصویر بزرگتر"
|
||||
>
|
||||
<SafeImage
|
||||
src={activeMedia?.url || product.image}
|
||||
alt={product.name}
|
||||
priority={true}
|
||||
sizes="(max-width: 768px) 100vw, 400px"
|
||||
className="w-full h-full"
|
||||
imgClassName="w-full h-full object-contain drop-shadow-2xl group-hover:scale-105 transition-transform duration-700 mx-auto my-auto"
|
||||
/>
|
||||
<div className="absolute bottom-4 right-4 bg-black/60 backdrop-blur-md text-white px-3 py-1 rounded-full text-[10px] font-black flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<span>بزرگنمایی</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 2. Video Player Frame */}
|
||||
{activeMedia?.type === 'video' && (
|
||||
<div
|
||||
onClick={() => {
|
||||
setActiveMediaForVideoModal(activeMedia.videoData || {
|
||||
title: activeMedia.title || product.name,
|
||||
videoUrl: activeMedia.url,
|
||||
thumbnail: activeMedia.thumbnail,
|
||||
description: product.description,
|
||||
});
|
||||
setIsVideoModalOpen(true);
|
||||
}}
|
||||
className="w-full h-full relative cursor-pointer overflow-hidden rounded-2xl bg-neutral-950 flex items-center justify-center group/vid"
|
||||
title="برای پخش ویدیو کلیک کنید"
|
||||
>
|
||||
<SafeImage
|
||||
src={activeMedia.thumbnail || product.image}
|
||||
alt={activeMedia.title || product.name}
|
||||
className="w-full h-full opacity-60 group-hover/vid:opacity-40 transition-opacity"
|
||||
imgClassName="w-full h-full object-cover group-hover/vid:scale-105 transition-transform duration-700"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/85 via-black/30 to-black/50 flex flex-col items-center justify-center gap-3 p-4 text-center">
|
||||
<div className="w-16 h-16 sm:w-20 sm:h-20 rounded-full bg-canina-blue text-white flex items-center justify-center shadow-2xl shadow-canina-blue/60 group-hover/vid:scale-110 transition-transform">
|
||||
<Play className="w-8 h-8 sm:w-10 sm:h-10 fill-white ml-1" />
|
||||
</div>
|
||||
<div className="space-y-1.5 max-w-xs">
|
||||
<span className="inline-flex items-center gap-1.5 px-3 py-1 bg-canina-blue text-white text-[11px] font-black rounded-full shadow-md font-vazir">
|
||||
<Film className="w-3.5 h-3.5" />
|
||||
<span>پخش ویدیو معرفی محصول</span>
|
||||
</span>
|
||||
<p className="text-xs font-bold text-white/90 truncate font-vazir">
|
||||
{activeMedia.title || product.nameFa || product.name}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 3. Podcast Player Frame */}
|
||||
{activeMedia?.type === 'podcast' && (
|
||||
<div
|
||||
onClick={() => {
|
||||
const el = document.getElementById('podcast-player-section');
|
||||
if (el) {
|
||||
el.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
}}
|
||||
className="w-full h-full relative cursor-pointer overflow-hidden rounded-2xl bg-gradient-to-br from-purple-950 via-slate-900 to-indigo-950 flex flex-col items-center justify-center p-6 text-white text-center group/pod"
|
||||
title="مشاهده و پخش پادکست بالینی"
|
||||
>
|
||||
<div className="w-16 h-16 sm:w-20 sm:h-20 rounded-2xl bg-purple-600/30 border border-purple-400/30 flex items-center justify-center mb-3 shadow-xl group-hover/pod:scale-105 transition-transform">
|
||||
<Headphones className="w-8 h-8 sm:w-10 sm:h-10 text-purple-300 animate-pulse" />
|
||||
</div>
|
||||
|
||||
{/* Animated Audio Bars */}
|
||||
<div className="flex items-center gap-1 mb-3">
|
||||
<span className="w-1 h-3 bg-purple-400 rounded-full animate-bounce" style={{ animationDelay: '0ms' }} />
|
||||
<span className="w-1 h-6 bg-purple-300 rounded-full animate-bounce" style={{ animationDelay: '150ms' }} />
|
||||
<span className="w-1 h-8 bg-purple-400 rounded-full animate-bounce" style={{ animationDelay: '300ms' }} />
|
||||
<span className="w-1 h-4 bg-purple-300 rounded-full animate-bounce" style={{ animationDelay: '75ms' }} />
|
||||
<span className="w-1 h-6 bg-purple-400 rounded-full animate-bounce" style={{ animationDelay: '225ms' }} />
|
||||
</div>
|
||||
|
||||
<span className="inline-flex items-center gap-1.5 px-3 py-1 bg-purple-600 text-white text-[11px] font-black rounded-full shadow-md font-vazir mb-1">
|
||||
<Headphones className="w-3.5 h-3.5" />
|
||||
<span>پادکست و بررسی صوتی بالینی</span>
|
||||
</span>
|
||||
<p className="text-xs font-bold text-white/90 line-clamp-2 max-w-xs font-vazir mt-1">
|
||||
{activeMedia.title || "بررسی تخصصی اثر مکمل توسط تیم علمی"}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
|
||||
{/* Multiple Gallery Thumbnails Strip */}
|
||||
{(() => {
|
||||
const allGalleryImages = [
|
||||
product.image,
|
||||
...(product.images || []).filter(img => img && img !== product.image)
|
||||
].filter(Boolean);
|
||||
{/* Multiple Gallery Media Thumbnails Strip */}
|
||||
{galleryMedia.length > 1 && (
|
||||
<div className="flex items-center gap-2 overflow-x-auto py-2 px-1 sleek-hscroll">
|
||||
{galleryMedia.map((item, idx) => {
|
||||
const isSelected = activeMediaIndex === idx;
|
||||
|
||||
if (allGalleryImages.length <= 1) return null;
|
||||
return (
|
||||
<button
|
||||
key={item.id || idx}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setActiveMediaIndex(idx);
|
||||
if (item.type === 'image') {
|
||||
setActiveImage(item.url);
|
||||
}
|
||||
}}
|
||||
className={`relative w-16 h-16 sm:w-18 sm:h-18 rounded-2xl overflow-hidden bg-white border-2 transition-all shrink-0 p-1 cursor-pointer flex items-center justify-center ${
|
||||
isSelected
|
||||
? 'border-canina-blue shadow-lg scale-105 ring-2 ring-canina-blue/30'
|
||||
: 'border-medical-gray-200 hover:border-canina-blue/50 opacity-75 hover:opacity-100'
|
||||
}`}
|
||||
>
|
||||
<SafeImage
|
||||
src={item.thumbnail || item.url || product.image}
|
||||
alt={`${product.name} - ${idx + 1}`}
|
||||
className="w-full h-full"
|
||||
imgClassName="w-full h-full object-contain"
|
||||
/>
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 overflow-x-auto py-2 px-1 sleek-hscroll">
|
||||
{allGalleryImages.map((imgUrl, idx) => {
|
||||
const isSelected = (activeImage || product.image) === imgUrl;
|
||||
return (
|
||||
<button
|
||||
key={idx}
|
||||
type="button"
|
||||
onClick={() => setActiveImage(imgUrl)}
|
||||
className={`relative w-16 h-16 rounded-2xl overflow-hidden bg-white border-2 transition-all shrink-0 p-1 cursor-pointer ${
|
||||
isSelected
|
||||
? 'border-canina-blue shadow-md scale-105 ring-2 ring-canina-blue/20'
|
||||
: 'border-medical-gray-200 hover:border-canina-blue/50 opacity-70 hover:opacity-100'
|
||||
}`}
|
||||
>
|
||||
<SafeImage
|
||||
src={imgUrl}
|
||||
alt={`${product.name} - ${idx + 1}`}
|
||||
className="w-full h-full"
|
||||
imgClassName="w-full h-full object-contain"
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
{/* Video Overlay Badge on thumbnail */}
|
||||
{item.type === 'video' && (
|
||||
<div className="absolute inset-0 bg-black/40 flex items-center justify-center">
|
||||
<div className="w-6 h-6 rounded-full bg-canina-blue text-white flex items-center justify-center shadow-md">
|
||||
<Play className="w-3 h-3 fill-white ml-0.5" />
|
||||
</div>
|
||||
<span className="absolute bottom-0.5 right-0.5 bg-blue-600 text-white text-[7px] font-bold px-1 rounded font-vazir">
|
||||
ویدیو
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Podcast Overlay Badge on thumbnail */}
|
||||
{item.type === 'podcast' && (
|
||||
<div className="absolute inset-0 bg-purple-950/60 flex items-center justify-center">
|
||||
<div className="w-6 h-6 rounded-full bg-purple-600 text-white flex items-center justify-center shadow-md">
|
||||
<Headphones className="w-3.5 h-3.5 text-white" />
|
||||
</div>
|
||||
<span className="absolute bottom-0.5 right-0.5 bg-purple-600 text-white text-[7px] font-bold px-1 rounded font-vazir">
|
||||
صوت
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Left Column: Product Title & Description (md:col-span-7) */}
|
||||
@@ -882,16 +1131,18 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
|
||||
{/* Podcast Player Row (Inline Direct Player with Soundcloud Waveform) */}
|
||||
{product.podcastUrl && (
|
||||
<PodcastInlinePlayer
|
||||
podcast={{
|
||||
audioUrl: product.podcastUrl,
|
||||
title: product.podcastTitle || "پادکست و بررسی صوتی بالینی مکمل",
|
||||
description: product.podcastDescription || product.description,
|
||||
cover: product.podcastCover,
|
||||
productName: product.name,
|
||||
fallbackCover: product.image,
|
||||
}}
|
||||
/>
|
||||
<div id="podcast-player-section" className="scroll-mt-24">
|
||||
<PodcastInlinePlayer
|
||||
podcast={{
|
||||
audioUrl: product.podcastUrl,
|
||||
title: product.podcastTitle || "پادکست و بررسی صوتی بالینی مکمل",
|
||||
description: product.podcastDescription || product.description,
|
||||
cover: product.podcastCover,
|
||||
productName: product.name,
|
||||
fallbackCover: product.image,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* PDF Catalog Download Row */}
|
||||
@@ -1251,26 +1502,29 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
<ProductImageZoomModal
|
||||
isOpen={isImageZoomOpen}
|
||||
onClose={() => setIsImageZoomOpen(false)}
|
||||
images={[
|
||||
product.image,
|
||||
...(product.images || []).filter(img => img && img !== product.image)
|
||||
].filter(Boolean) as string[]}
|
||||
activeImage={activeImage || product.image || ""}
|
||||
onSelectImage={(img) => setActiveImage(img)}
|
||||
images={galleryMedia.filter(m => m.type === 'image').map(m => m.url)}
|
||||
activeImage={activeMedia?.type === 'image' ? activeMedia.url : (galleryMedia.find(m => m.type === 'image')?.url || product.image || "")}
|
||||
onSelectImage={(img) => {
|
||||
const foundIdx = galleryMedia.findIndex(m => m.url === img);
|
||||
if (foundIdx !== -1) setActiveMediaIndex(foundIdx);
|
||||
}}
|
||||
productName={product.nameFa || product.name}
|
||||
/>
|
||||
|
||||
{/* Dedicated Video Modal Player */}
|
||||
<VideoModalPlayer
|
||||
isOpen={isVideoModalOpen}
|
||||
onClose={() => setIsVideoModalOpen(false)}
|
||||
video={product.videoUrl ? {
|
||||
onClose={() => {
|
||||
setIsVideoModalOpen(false);
|
||||
setActiveMediaForVideoModal(null);
|
||||
}}
|
||||
video={activeMediaForVideoModal || (product.videoUrl ? {
|
||||
title: product.videoTitle || product.name,
|
||||
doctor: "کادر علمی و تخصصی کنینا",
|
||||
videoUrl: product.videoUrl,
|
||||
thumbnail: product.videoCover || product.image,
|
||||
description: product.videoDescription || product.description,
|
||||
} : null}
|
||||
} : null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user