590 lines
28 KiB
TypeScript
590 lines
28 KiB
TypeScript
"use client";
|
|
|
|
import React, { useState, useEffect, useMemo } from "react";
|
|
import {
|
|
Search,
|
|
ChevronLeft,
|
|
ArrowRight,
|
|
Sparkles,
|
|
Heart,
|
|
AlertCircle,
|
|
ShoppingBag,
|
|
FileText,
|
|
BookOpen,
|
|
Video,
|
|
Check,
|
|
ExternalLink,
|
|
Pill,
|
|
Clock,
|
|
PlayCircle
|
|
} from "lucide-react";
|
|
import { usePetStore } from "../lib/store/usePetStore";
|
|
import { motion, AnimatePresence } from "motion/react";
|
|
import { Product } from "../lib/data/products";
|
|
import { productService } from "../lib/services/productService";
|
|
import Link from "next/link";
|
|
import Image from "next/image";
|
|
import { useRouter } from 'next/navigation';
|
|
import api from "../lib/services/api";
|
|
import { toPersian } from "../lib/utils";
|
|
|
|
type SearchTab = "all" | "products" | "blogs" | "wiki" | "videos";
|
|
|
|
interface BlogItem {
|
|
id: string;
|
|
title: string;
|
|
slug: string;
|
|
excerpt?: string;
|
|
category?: string | { name?: string };
|
|
imageUrl?: string;
|
|
readingTime?: number;
|
|
}
|
|
|
|
interface WikiItem {
|
|
id: string;
|
|
name?: string;
|
|
nameFa?: string;
|
|
scientificName?: string;
|
|
slug?: string;
|
|
description?: string;
|
|
category?: string;
|
|
}
|
|
|
|
interface VideoItem {
|
|
id: string;
|
|
title: string;
|
|
doctor?: string;
|
|
duration?: string;
|
|
thumbnail?: string;
|
|
description?: string;
|
|
}
|
|
|
|
export default function SearchResultsPage({ query }: { query: string }) {
|
|
const router = useRouter();
|
|
const { getActivePet } = usePetStore();
|
|
const activePet = getActivePet();
|
|
|
|
const [activeTab, setActiveTab] = useState<SearchTab>("all");
|
|
const [searchInput, setSearchInput] = useState(query);
|
|
|
|
const [products, setProducts] = useState<Product[]>([]);
|
|
const [blogs, setBlogs] = useState<BlogItem[]>([]);
|
|
const [wikiItems, setWikiItems] = useState<WikiItem[]>([]);
|
|
const [videos, setVideos] = useState<VideoItem[]>([]);
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
// Sync input when prop changes
|
|
useEffect(() => {
|
|
setSearchInput(query);
|
|
}, [query]);
|
|
|
|
// Fetch all searchable datasets in parallel
|
|
useEffect(() => {
|
|
let isMounted = true;
|
|
setIsLoading(true);
|
|
|
|
const loadAll = async () => {
|
|
try {
|
|
const [prodRes, blogRes, wikiRes, videoRes] = await Promise.allSettled([
|
|
productService.getProducts({ limit: 999 }),
|
|
api.get("/blogs?limit=50"),
|
|
api.get("/ingredients?limit=100"),
|
|
api.get("/videos?limit=50")
|
|
]);
|
|
|
|
if (!isMounted) return;
|
|
|
|
if (prodRes.status === "fulfilled" && prodRes.value?.data) {
|
|
setProducts(prodRes.value.data);
|
|
} else if (prodRes.status === "rejected") {
|
|
console.error("Error fetching products in SearchResultsPage:", prodRes.reason);
|
|
}
|
|
|
|
if (blogRes.status === "fulfilled" && blogRes.value?.data) {
|
|
const list = Array.isArray(blogRes.value.data.data)
|
|
? blogRes.value.data.data
|
|
: Array.isArray(blogRes.value.data)
|
|
? blogRes.value.data
|
|
: [];
|
|
setBlogs(list);
|
|
}
|
|
|
|
if (wikiRes.status === "fulfilled" && wikiRes.value?.data) {
|
|
const list = Array.isArray(wikiRes.value.data.data)
|
|
? wikiRes.value.data.data
|
|
: Array.isArray(wikiRes.value.data)
|
|
? wikiRes.value.data
|
|
: [];
|
|
setWikiItems(list);
|
|
}
|
|
|
|
if (videoRes.status === "fulfilled" && videoRes.value?.data) {
|
|
const vList = videoRes.value.data.videos || videoRes.value.data.data || videoRes.value.data;
|
|
setVideos(Array.isArray(vList) ? vList : []);
|
|
}
|
|
} catch (err) {
|
|
console.error("Error loading search datasets:", err);
|
|
} finally {
|
|
if (isMounted) setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
loadAll();
|
|
return () => { isMounted = false; };
|
|
}, []);
|
|
|
|
const cleanQuery = (query || "").trim().toLowerCase();
|
|
|
|
// 1. Filtered Products
|
|
const filteredProducts = useMemo(() => {
|
|
if (!cleanQuery) return products;
|
|
return products.filter(p =>
|
|
(p.name || '').toLowerCase().includes(cleanQuery) ||
|
|
(p.description || '').toLowerCase().includes(cleanQuery) ||
|
|
(Array.isArray(p.main_ingredients) && p.main_ingredients.some(ing => ing.toLowerCase().includes(cleanQuery))) ||
|
|
(Array.isArray(p.symptoms) && p.symptoms.some(sym => sym.toLowerCase().includes(cleanQuery))) ||
|
|
(p.nameFa || '').toLowerCase().includes(cleanQuery) ||
|
|
(p.nameEn || '').toLowerCase().includes(cleanQuery)
|
|
);
|
|
}, [products, cleanQuery]);
|
|
|
|
// 2. Filtered Blogs
|
|
const filteredBlogs = useMemo(() => {
|
|
if (!cleanQuery) return blogs;
|
|
return blogs.filter(b =>
|
|
(b.title || '').toLowerCase().includes(cleanQuery) ||
|
|
(b.excerpt || '').toLowerCase().includes(cleanQuery)
|
|
);
|
|
}, [blogs, cleanQuery]);
|
|
|
|
// 3. Filtered Wiki Items
|
|
const filteredWiki = useMemo(() => {
|
|
if (!cleanQuery) return wikiItems;
|
|
return wikiItems.filter(w =>
|
|
(w.name || '').toLowerCase().includes(cleanQuery) ||
|
|
(w.nameFa || '').toLowerCase().includes(cleanQuery) ||
|
|
(w.scientificName || '').toLowerCase().includes(cleanQuery) ||
|
|
(w.description || '').toLowerCase().includes(cleanQuery)
|
|
);
|
|
}, [wikiItems, cleanQuery]);
|
|
|
|
// 4. Filtered Videos
|
|
const filteredVideos = useMemo(() => {
|
|
if (!cleanQuery) return videos;
|
|
return videos.filter(v =>
|
|
(v.title || '').toLowerCase().includes(cleanQuery) ||
|
|
(v.doctor || '').toLowerCase().includes(cleanQuery) ||
|
|
(v.description || '').toLowerCase().includes(cleanQuery)
|
|
);
|
|
}, [videos, cleanQuery]);
|
|
|
|
const totalResults = filteredProducts.length + filteredBlogs.length + filteredWiki.length + filteredVideos.length;
|
|
const bestSellers = products.slice(0, 3);
|
|
|
|
const handleSearchSubmit = (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (searchInput.trim()) {
|
|
router.push(`/search?q=${encodeURIComponent(searchInput.trim())}`);
|
|
} else {
|
|
router.push('/search');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen bg-medical-gray-50 py-4 sm:py-10 px-3 sm:px-6 font-vazir" dir="rtl">
|
|
<div className="max-w-7xl mx-auto">
|
|
|
|
{/* Mobile-First Header Bar: Back Button & Compact Title */}
|
|
<div className="flex items-center justify-between mb-4 pb-3 border-b border-medical-gray-200">
|
|
<div className="flex items-center gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => router.back()}
|
|
className="flex items-center gap-1.5 px-3 py-1.5 bg-white border border-medical-gray-200 rounded-xl text-xs font-bold text-medical-gray-600 hover:text-canina-blue hover:border-canina-blue transition-colors shadow-2xs cursor-pointer"
|
|
>
|
|
<ArrowRight className="w-3.5 h-3.5 rotate-180" />
|
|
<span>بازگشت</span>
|
|
</button>
|
|
<span className="text-xs text-medical-gray-400 font-bold hidden sm:inline">جستجوی جامع کنینا</span>
|
|
</div>
|
|
|
|
{cleanQuery && (
|
|
<span className="text-[11px] font-black text-canina-blue bg-canina-blue/10 px-2.5 py-1 rounded-full border border-canina-blue/20">
|
|
{toPersian(totalResults)} نتیجه
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
{/* Compact Search Header & Input */}
|
|
<div className="mb-5 sm:mb-8">
|
|
<h1 className="text-xl sm:text-3xl font-black text-medical-gray-900 mb-2 font-lalezar tracking-wide">
|
|
{cleanQuery ? (
|
|
<>نتایج جستجو برای: <span className="text-canina-blue">"{query}"</span></>
|
|
) : (
|
|
"جستجوی هوشمند در تمامی بخشهای کنینا"
|
|
)}
|
|
</h1>
|
|
<p className="text-[11px] sm:text-xs text-medical-gray-500 font-medium mb-3 sm:mb-4">
|
|
جستجوی همزمان در داروها، مکملها، مقالات وبلاگ، دانشنامه ترکیبات و ویدیوهای بالینی
|
|
</p>
|
|
|
|
{/* Search Box Input */}
|
|
<form onSubmit={handleSearchSubmit} className="relative max-w-2xl">
|
|
<input
|
|
type="text"
|
|
name="q"
|
|
value={searchInput}
|
|
onChange={(e) => setSearchInput(e.target.value)}
|
|
placeholder="جستجوی دارو، مقاله، ترکیب علمی، ویدیو..."
|
|
className="w-full bg-white border border-medical-gray-200 rounded-2xl py-2.5 sm:py-3 pr-10 pl-20 text-xs sm:text-sm font-bold focus:outline-none focus:ring-2 focus:ring-canina-blue/20 shadow-xs text-medical-gray-900"
|
|
/>
|
|
<Search className="w-4 h-4 sm:w-5 sm:h-5 text-medical-gray-400 absolute right-3.5 top-1/2 -translate-y-1/2" />
|
|
<button
|
|
type="submit"
|
|
className="absolute left-1.5 top-1/2 -translate-y-1/2 px-3.5 py-1.5 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-canina-dark transition-all cursor-pointer shadow-xs"
|
|
>
|
|
جستجو
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
{/* Multi-Content Filter Tabs */}
|
|
<div className="flex items-center gap-1.5 sm:gap-2 overflow-x-auto pb-3 mb-6 micro-hscroll select-none">
|
|
{[
|
|
{ id: "all", label: "همه نتایج", count: totalResults, icon: <Sparkles className="w-3.5 h-3.5" /> },
|
|
{ id: "products", label: "محصولات و داروها", count: filteredProducts.length, icon: <ShoppingBag className="w-3.5 h-3.5" /> },
|
|
{ id: "blogs", label: "مقالات وبلاگ", count: filteredBlogs.length, icon: <FileText className="w-3.5 h-3.5" /> },
|
|
{ id: "wiki", label: "دانشنامه ترکیبات", count: filteredWiki.length, icon: <BookOpen className="w-3.5 h-3.5" /> },
|
|
{ id: "videos", label: "ویدیوهای بالینی", count: filteredVideos.length, icon: <Video className="w-3.5 h-3.5" /> },
|
|
].map(tab => (
|
|
<button
|
|
key={tab.id}
|
|
type="button"
|
|
onClick={() => setActiveTab(tab.id as SearchTab)}
|
|
className={`flex items-center gap-1.5 px-3 py-1.5 sm:px-4 sm:py-2 rounded-xl text-xs font-black transition-all shrink-0 cursor-pointer border ${
|
|
activeTab === tab.id
|
|
? "bg-canina-blue text-white border-canina-blue shadow-xs"
|
|
: "bg-white text-medical-gray-600 border-medical-gray-200 hover:border-canina-blue/50"
|
|
}`}
|
|
>
|
|
{tab.icon}
|
|
<span>{tab.label}</span>
|
|
<span className={`text-[10px] px-1.5 py-0.2 rounded-full font-bold ${
|
|
activeTab === tab.id ? "bg-white/20 text-white" : "bg-medical-gray-100 text-medical-gray-500"
|
|
}`}>
|
|
{toPersian(tab.count)}
|
|
</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
|
|
{/* RESULTS AREA */}
|
|
{cleanQuery && totalResults === 0 && !isLoading ? (
|
|
/* Empty State - Mobile-Optimized with direct suggestion cards */
|
|
<div className="space-y-8">
|
|
<div className="bg-white border border-medical-gray-200 rounded-3xl p-6 sm:p-10 text-center shadow-xs">
|
|
<div className="w-14 h-14 bg-medical-gray-50 rounded-2xl flex items-center justify-center mx-auto text-medical-gray-300 mb-3 border border-medical-gray-100">
|
|
<Search className="w-7 h-7" />
|
|
</div>
|
|
<h3 className="text-lg sm:text-xl font-black text-medical-gray-900 mb-1.5 font-vazir">نتیجهای یافت نشد</h3>
|
|
<p className="text-xs text-medical-gray-500 font-medium max-w-md mx-auto leading-relaxed mb-4">
|
|
متأسفیم، هیچ موردی با عبارت جستجو شده تطبیق نداشت. محصولات پرطرفدار زیر را بررسی کنید:
|
|
</p>
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
setSearchInput("");
|
|
router.push('/shop');
|
|
}}
|
|
className="inline-flex items-center gap-2 px-4 py-2 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-canina-dark transition-all cursor-pointer shadow-xs"
|
|
>
|
|
<span>مشاهده کاتالوگ فروشگاه</span>
|
|
<ChevronLeft className="w-4 h-4" />
|
|
</button>
|
|
</div>
|
|
|
|
{bestSellers.length > 0 && (
|
|
<div>
|
|
<h3 className="text-base sm:text-xl font-black text-medical-gray-900 mb-4 font-vazir">محصولات پیشنهادی (پرفروش)</h3>
|
|
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-6">
|
|
{bestSellers.map(p => (
|
|
<Link
|
|
key={p.id}
|
|
href={`/shop/${p.slug || p.id}`}
|
|
className="group bg-white p-3.5 sm:p-4 rounded-2xl border border-medical-gray-200 hover:border-canina-blue flex items-center sm:flex-col gap-3 shadow-2xs hover:shadow-md transition-all"
|
|
>
|
|
<div className="w-16 h-16 sm:w-28 sm:h-28 bg-medical-gray-50 rounded-xl p-2 flex items-center justify-center shrink-0">
|
|
<Image src={p.image} alt={p.name} width={100} height={100} className="w-full h-full object-contain group-hover:scale-105 transition-transform" unoptimized />
|
|
</div>
|
|
<div className="flex-1 sm:text-center min-w-0">
|
|
<h4 className="text-xs sm:text-sm font-black text-medical-gray-900 truncate mb-1">{p.nameFa || p.name}</h4>
|
|
<div className="text-[11px] font-black text-canina-blue">{p.price}</div>
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<div className="space-y-10">
|
|
|
|
{/* 1. PRODUCTS SECTION */}
|
|
{(activeTab === "all" || activeTab === "products") && filteredProducts.length > 0 && (
|
|
<section>
|
|
<div className="flex items-center justify-between mb-3.5 pb-2 border-b border-medical-gray-200">
|
|
<div className="flex items-center gap-2">
|
|
<ShoppingBag className="w-4 h-4 text-canina-blue" />
|
|
<h2 className="text-sm sm:text-base font-black text-medical-gray-900">محصولات و مکملها ({toPersian(filteredProducts.length)})</h2>
|
|
</div>
|
|
{activeTab === "all" && filteredProducts.length > 6 && (
|
|
<button
|
|
type="button"
|
|
onClick={() => setActiveTab("products")}
|
|
className="text-[11px] font-black text-canina-blue hover:underline"
|
|
>
|
|
مشاهده همه محصولات
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-6">
|
|
{(activeTab === "all" ? filteredProducts.slice(0, 6) : filteredProducts).map((product) => {
|
|
const compatibility = (() => {
|
|
if (!activePet) return null;
|
|
const sameSpecies = product.suitableFor === activePet.type || product.suitableFor === "هر دو";
|
|
const helpsSymptom = Array.isArray(activePet.medicalConditions) && Array.isArray(product.symptoms) && activePet.medicalConditions.some(c => product.symptoms.includes(c));
|
|
if (!sameSpecies) return { type: 'alert', text: `مخصوص ${product.suitableFor}` };
|
|
if (helpsSymptom) return { type: 'success', text: `توصیه شده برای ${activePet.name}` };
|
|
return { type: 'neutral', text: `مناسب برای ${activePet.name}` };
|
|
})();
|
|
|
|
return (
|
|
<Link
|
|
key={product.id}
|
|
href={`/shop/${product.slug || product.id}`}
|
|
className="group bg-white rounded-2xl p-3 sm:p-5 border border-medical-gray-200 hover:border-canina-blue shadow-2xs hover:shadow-lg transition-all flex flex-col justify-between"
|
|
>
|
|
<div className="flex items-center gap-3 sm:block mb-2">
|
|
<div className="w-20 h-20 sm:w-full sm:aspect-square bg-medical-gray-50 rounded-xl p-2 sm:p-4 flex items-center justify-center shrink-0 sm:mb-3">
|
|
<Image
|
|
src={product.image}
|
|
alt={product.nameFa || product.name}
|
|
width={150}
|
|
height={150}
|
|
className="w-full h-full object-contain group-hover:scale-105 transition-transform"
|
|
unoptimized
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex-1 min-w-0">
|
|
<div className="flex items-center gap-1.5 mb-1 flex-wrap">
|
|
<span className="text-[9px] font-black text-canina-blue bg-canina-blue/5 px-2 py-0.5 rounded border border-canina-blue/10">
|
|
{product.category}
|
|
</span>
|
|
{compatibility && (
|
|
<span className={`text-[9px] font-black px-2 py-0.5 rounded ${
|
|
compatibility.type === 'alert' ? 'bg-amber-100 text-amber-700' :
|
|
compatibility.type === 'success' ? 'bg-green-100 text-green-700' : 'bg-medical-gray-100 text-medical-gray-600'
|
|
}`}>
|
|
{compatibility.text}
|
|
</span>
|
|
)}
|
|
</div>
|
|
<h3 className="text-xs sm:text-sm font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors line-clamp-2">
|
|
{product.nameFa || product.name}
|
|
</h3>
|
|
<p className="text-[10px] text-medical-gray-400 line-clamp-1 mt-0.5">
|
|
{product.benefits || product.description}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex items-center justify-between pt-2.5 border-t border-medical-gray-100 text-xs font-black">
|
|
<span className="text-medical-gray-900">{product.price}</span>
|
|
<span className="text-[11px] text-canina-blue flex items-center gap-0.5 group-hover:-translate-x-1 transition-transform">
|
|
مشاهده و خرید
|
|
<ChevronLeft className="w-3.5 h-3.5" />
|
|
</span>
|
|
</div>
|
|
</Link>
|
|
);
|
|
})}
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* 2. BLOGS SECTION */}
|
|
{(activeTab === "all" || activeTab === "blogs") && filteredBlogs.length > 0 && (
|
|
<section>
|
|
<div className="flex items-center justify-between mb-3.5 pb-2 border-b border-medical-gray-200">
|
|
<div className="flex items-center gap-2">
|
|
<FileText className="w-4 h-4 text-emerald-600" />
|
|
<h2 className="text-sm sm:text-base font-black text-medical-gray-900">مقالات مجله سلامت ({toPersian(filteredBlogs.length)})</h2>
|
|
</div>
|
|
{activeTab === "all" && filteredBlogs.length > 4 && (
|
|
<button
|
|
type="button"
|
|
onClick={() => setActiveTab("blogs")}
|
|
className="text-[11px] font-black text-canina-blue hover:underline"
|
|
>
|
|
مشاهده همه مقالات
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4">
|
|
{(activeTab === "all" ? filteredBlogs.slice(0, 4) : filteredBlogs).map((blog) => (
|
|
<Link
|
|
key={blog.id}
|
|
href={`/blog/${blog.slug || blog.id}`}
|
|
className="group bg-white rounded-2xl p-3 border border-medical-gray-200 hover:border-emerald-500 shadow-2xs hover:shadow-md transition-all flex items-center gap-3"
|
|
>
|
|
{blog.imageUrl ? (
|
|
<div className="w-20 h-20 rounded-xl overflow-hidden bg-medical-gray-50 shrink-0">
|
|
<Image
|
|
src={blog.imageUrl}
|
|
alt={blog.title}
|
|
width={80}
|
|
height={80}
|
|
className="w-full h-full object-cover group-hover:scale-105 transition-transform"
|
|
unoptimized
|
|
/>
|
|
</div>
|
|
) : (
|
|
<div className="w-20 h-20 rounded-xl bg-emerald-50 text-emerald-600 flex items-center justify-center shrink-0">
|
|
<BookOpen className="w-6 h-6" />
|
|
</div>
|
|
)}
|
|
|
|
<div className="flex-1 min-w-0">
|
|
<span className="text-[9px] font-black text-emerald-700 bg-emerald-50 px-2 py-0.5 rounded">
|
|
{typeof blog.category === 'object' ? blog.category?.name : blog.category || 'مقاله علمی'}
|
|
</span>
|
|
<h3 className="text-xs sm:text-sm font-black text-medical-gray-900 group-hover:text-emerald-700 transition-colors line-clamp-2 mt-1">
|
|
{blog.title}
|
|
</h3>
|
|
<p className="text-[10px] text-medical-gray-400 line-clamp-1 mt-0.5">
|
|
{blog.excerpt}
|
|
</p>
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* 3. WIKI SECTION */}
|
|
{(activeTab === "all" || activeTab === "wiki") && filteredWiki.length > 0 && (
|
|
<section>
|
|
<div className="flex items-center justify-between mb-3.5 pb-2 border-b border-medical-gray-200">
|
|
<div className="flex items-center gap-2">
|
|
<BookOpen className="w-4 h-4 text-amber-500" />
|
|
<h2 className="text-sm sm:text-base font-black text-medical-gray-900">دانشنامه ترکیبات علمی ({toPersian(filteredWiki.length)})</h2>
|
|
</div>
|
|
{activeTab === "all" && filteredWiki.length > 4 && (
|
|
<button
|
|
type="button"
|
|
onClick={() => setActiveTab("wiki")}
|
|
className="text-[11px] font-black text-canina-blue hover:underline"
|
|
>
|
|
مشاهده همه ترکیبات
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4">
|
|
{(activeTab === "all" ? filteredWiki.slice(0, 4) : filteredWiki).map((wiki) => (
|
|
<Link
|
|
key={wiki.id}
|
|
href={`/wiki?search=${encodeURIComponent(wiki.nameFa || wiki.name || '')}`}
|
|
className="group bg-white rounded-2xl p-3 border border-medical-gray-200 hover:border-amber-500 shadow-2xs hover:shadow-md transition-all flex items-start gap-3"
|
|
>
|
|
<div className="w-10 h-10 rounded-xl bg-amber-50 text-amber-600 flex items-center justify-center shrink-0">
|
|
<Pill className="w-5 h-5" />
|
|
</div>
|
|
<div className="flex-1 min-w-0">
|
|
<h3 className="text-xs sm:text-sm font-black text-medical-gray-900 group-hover:text-amber-600 transition-colors">
|
|
{wiki.nameFa || wiki.name}
|
|
</h3>
|
|
{wiki.scientificName && (
|
|
<div className="text-[10px] text-medical-gray-400 font-mono mt-0.5">
|
|
{wiki.scientificName}
|
|
</div>
|
|
)}
|
|
<p className="text-[10px] text-medical-gray-500 line-clamp-2 mt-1">
|
|
{wiki.description}
|
|
</p>
|
|
</div>
|
|
<ChevronLeft className="w-4 h-4 text-medical-gray-300 group-hover:text-amber-600 transition-colors shrink-0 self-center" />
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
{/* 4. VIDEOS SECTION */}
|
|
{(activeTab === "all" || activeTab === "videos") && filteredVideos.length > 0 && (
|
|
<section>
|
|
<div className="flex items-center justify-between mb-3.5 pb-2 border-b border-medical-gray-200">
|
|
<div className="flex items-center gap-2">
|
|
<Video className="w-4 h-4 text-indigo-500" />
|
|
<h2 className="text-sm sm:text-base font-black text-medical-gray-900">ویدیوهای بالینی دامپزشکی ({toPersian(filteredVideos.length)})</h2>
|
|
</div>
|
|
{activeTab === "all" && filteredVideos.length > 3 && (
|
|
<button
|
|
type="button"
|
|
onClick={() => setActiveTab("videos")}
|
|
className="text-[11px] font-black text-canina-blue hover:underline"
|
|
>
|
|
مشاهده همه ویدیوها
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4">
|
|
{(activeTab === "all" ? filteredVideos.slice(0, 3) : filteredVideos).map((vid) => (
|
|
<Link
|
|
key={vid.id}
|
|
href="/videos"
|
|
className="group bg-white rounded-2xl overflow-hidden border border-medical-gray-200 hover:border-indigo-500 shadow-2xs hover:shadow-md transition-all flex flex-col"
|
|
>
|
|
<div className="relative aspect-video bg-medical-gray-900 flex items-center justify-center overflow-hidden">
|
|
{vid.thumbnail ? (
|
|
<Image src={vid.thumbnail} alt={vid.title} width={300} height={180} className="w-full h-full object-cover group-hover:scale-105 transition-transform" unoptimized />
|
|
) : null}
|
|
<div className="absolute inset-0 bg-black/30 flex items-center justify-center">
|
|
<PlayCircle className="w-8 h-8 text-white/90 group-hover:scale-110 transition-transform" />
|
|
</div>
|
|
{vid.duration && (
|
|
<span className="absolute bottom-2 left-2 bg-black/70 text-white text-[9px] px-1.5 py-0.5 rounded font-mono">
|
|
{vid.duration}
|
|
</span>
|
|
)}
|
|
</div>
|
|
<div className="p-3 flex-1 flex flex-col justify-between">
|
|
<div>
|
|
<h3 className="text-xs font-black text-medical-gray-900 line-clamp-2 mb-1 group-hover:text-indigo-600 transition-colors">
|
|
{vid.title}
|
|
</h3>
|
|
{vid.doctor && (
|
|
<span className="text-[10px] font-bold text-medical-gray-400 block">
|
|
{vid.doctor}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</section>
|
|
)}
|
|
|
|
</div>
|
|
)}
|
|
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|