Files
canina/frontend/application/components/VetGallery.tsx
devops 5e0541c739
Deploy Canina / deploy (push) Successful in 2m24s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
fix(frontend): remove static fallback data and mock fallbacks across storefront
2026-10-13 16:42:46 +00:00

156 lines
7.7 KiB
TypeScript

"use client";
import React, { useState } from "react";
import { Play, Star, ShieldCheck, X } from "lucide-react";
import { motion, AnimatePresence } from "motion/react";
import Link from "next/link";
import SafeImage from "./SafeImage";
import { useSettingsStore } from "../lib/store/settingsStore";
import { videoService, Video } from "../lib/services/videoService";
import VideoModalPlayer from './VideoModalPlayer';
export interface TestimonialItem {
id?: string;
authorName?: string;
roleTitle?: string;
avatarUrl?: string;
content?: string;
clinicName?: string;
vetName?: string;
imageUrl?: string;
quote?: string;
title?: string;
thumbnail?: string;
videoUrl?: string;
description?: string;
isActive?: boolean;
}
interface DisplayVideoItem {
id: string;
title?: string;
doctor?: string;
duration?: string;
thumbnail?: string;
videoUrl?: string;
description?: string;
quote?: string;
imageUrl?: string;
vetName?: string;
}
export default function VetGallery({ testimonials = [] }: { testimonials?: TestimonialItem[] }) {
const getText = useSettingsStore(state => state.getText);
const [apiVideos, setApiVideos] = useState<Video[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [selectedVideo, setSelectedVideo] = useState<Video | null>(null);
React.useEffect(() => {
setIsLoading(true);
videoService.getVideos({ featured: true, limit: 3 })
.then((data) => {
if (data && Array.isArray(data)) {
setApiVideos(data);
}
})
.catch((err) => {
console.error('Failed to load featured videos:', err);
setApiVideos([]);
})
.finally(() => {
setIsLoading(false);
});
}, []);
if (!isLoading && apiVideos.length === 0) {
return null; // Don't render video section if no videos are configured
}
return (
<section className="py-8 sm:py-20 bg-white font-vazir relative overflow-hidden" dir="rtl">
<div className="max-w-7xl mx-auto px-4">
<div className="flex flex-col sm:flex-row sm:items-end justify-between mb-6 sm:mb-12 pb-4 sm:pb-6 border-b border-medical-gray-200 gap-3 sm:gap-6">
<div className="max-w-2xl">
<div className="inline-flex items-center gap-2 px-3 py-1 bg-canina-blue/10 text-canina-blue rounded-full text-[10px] font-black uppercase tracking-widest mb-2 sm:mb-3 font-vazir">
<Star className="w-3 h-3" />
{getText('videos_badge', "Vet Insights")}
</div>
<h2 className="text-2xl sm:text-3xl md:text-4xl font-black text-medical-gray-900 leading-tight font-lalezar tracking-wide" suppressHydrationWarning>
{getText('videos_title', "مشاوره ویدئویی")} <span className="text-canina-blue underline decoration-4 decoration-canina-blue/20 underline-offset-8">{getText('videos_title_highlight', "دوست دامپزشک پت شما")}</span>
</h2>
<p className="text-sm sm:text-base text-medical-gray-500 font-medium mt-2 sm:mt-3 leading-relaxed" suppressHydrationWarning>
{getText('videos_desc', "تیم علمی و فرموله‌کنندگان کمپانی کنینا در آلمان مستقیماً با شما صحبت می‌کنند؛ آشنایی با نحوه مصرف، مزایای بالینی و دانش پزشکی پشت هر محصول.")}
</p>
</div>
<Link
href="/videos"
className="inline-flex items-center gap-1.5 sm:gap-2 text-canina-blue font-black text-xs sm:text-sm hover:translate-x-1 transition-all rtl:hover:-translate-x-1 group font-vazir self-start sm:self-auto shrink-0"
>
<span>{getText('videos_view_all', "مشاهده همه ویدئوها")}</span>
<Play className="w-3.5 h-3.5" />
</Link>
</div>
{/* Video Grid or Skeleton */}
{isLoading ? (
<div className="flex md:grid md:grid-cols-2 lg:grid-cols-3 gap-4 md:gap-6 overflow-x-auto md:overflow-visible pb-4 md:pb-0 micro-hscroll -mx-4 px-4 md:mx-0 md:px-0 select-none snap-x snap-mandatory md:snap-none overscroll-x-contain">
{[1, 2, 3].map((i) => (
<div key={i} className="w-[68vw] sm:w-[50vw] md:w-auto flex-shrink-0 snap-start rounded-[2rem] p-2 space-y-3 animate-pulse">
<div className="aspect-video bg-medical-gray-100 rounded-[1.5rem] sm:rounded-[2rem]" />
<div className="h-5 bg-medical-gray-100 rounded-lg w-3/4" />
<div className="h-3.5 bg-medical-gray-100 rounded-lg w-1/2" />
</div>
))}
</div>
) : (
<div className="flex md:grid md:grid-cols-2 lg:grid-cols-3 gap-4 md:gap-6 overflow-x-auto md:overflow-visible pb-4 md:pb-0 micro-hscroll -mx-4 px-4 md:mx-0 md:px-0 select-none snap-x snap-mandatory md:snap-none overscroll-x-contain">
{apiVideos.map((video, index) => (
<div key={video.id} className="w-[68vw] sm:w-[50vw] md:w-auto flex-shrink-0 snap-start flex">
<motion.button
whileHover={{ y: -8 }}
onClick={() => setSelectedVideo(video)}
className="w-full text-right block group cursor-pointer focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none rounded-[1.75rem] sm:rounded-[2rem] p-1.5 sm:p-2"
>
<div className="relative aspect-video rounded-[1.5rem] sm:rounded-[2rem] overflow-hidden mb-3 sm:mb-4 shadow-md sm:shadow-xl bg-medical-gray-900">
<div className="absolute inset-0 bg-medical-gray-900/20 group-hover:bg-transparent transition-colors z-10" />
<SafeImage
src={video.thumbnail || ''}
alt={video.title || 'ویدیو دامپزشک'}
className="w-full h-full"
imgClassName="object-cover grayscale-[30%] group-hover:grayscale-0 transition-all duration-700"
/>
<div className="absolute inset-0 flex items-center justify-center z-20">
<div className="w-12 h-12 sm:w-16 sm:h-16 bg-white/90 backdrop-blur-sm rounded-full flex items-center justify-center text-canina-blue scale-90 group-hover:scale-100 group-hover:bg-white transition-all shadow-xl">
<Play className="w-4 h-4 sm:w-6 sm:h-6 ml-1" />
</div>
</div>
{video.duration && (
<div className="absolute bottom-2.5 right-2.5 sm:bottom-4 sm:right-4 bg-black/60 backdrop-blur-md text-white px-2 py-0.5 sm:py-1 rounded-lg text-[10px] sm:text-xs font-black z-20 font-vazir flex items-center gap-1 shadow-lg">
<span>⏱️</span>
<span>{video.duration}</span>
</div>
)}
</div>
<h3 className="text-sm sm:text-lg font-black text-medical-gray-900 mb-1.5 sm:mb-2 group-hover:text-canina-blue transition-colors leading-snug line-clamp-2 font-vazir">
{video.title}
</h3>
<div className="flex items-center gap-1.5 sm:gap-2 text-medical-gray-500 font-bold text-xs sm:text-sm font-vazir">
<ShieldCheck className="w-3.5 h-3.5 sm:w-4 sm:h-4 text-canina-blue" />
<span className="truncate">{video.doctor || 'کادر علمی کنینا'}</span>
</div>
</motion.button>
</div>
))}
</div>
)}
</div>
{/* Custom Feature-Rich Video Player Modal */}
<VideoModalPlayer
isOpen={!!selectedVideo}
onClose={() => setSelectedVideo(null)}
video={selectedVideo}
/>
</section>
);
}