"use client"; import { useState, useEffect, useMemo } from "react"; import Image from "next/legacy/image"; import Link from "next/link"; import { getValidImageUrl, FALLBACK_IMAGES } from "@/lib/imageUtils"; import { useCaseStudies } from "@/lib/hooks/useCaseStudy"; import { API_CONFIG } from "@/lib/config/api"; const Story = () => { const [activeIndex, setActiveIndex] = useState(0); const [activeImageIndex, setActiveImageIndex] = useState(0); // Fetch case studies from API with ordering and limit const params = useMemo(() => ({ ordering: 'display_order', page_size: 5 }), []); const { caseStudies, loading, error } = useCaseStudies(params); // Fallback to static data if API fails or is loading const staticStoryData = [ { id: 1, category_name: "Financial Services", title: "Banking System Modernization", excerpt: "Complete digital transformation of legacy banking systems with enhanced security and real-time processing capabilities.", thumbnail: "/images/case/one.png", slug: "banking-system-modernization", display_order: 1, created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 2, category_name: "Healthcare", title: "Patient Management System", excerpt: "Enterprise-grade patient management system with HIPAA compliance and seamless integration across multiple healthcare facilities.", thumbnail: "/images/case/two.png", slug: "patient-management-system", display_order: 2, created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 3, category_name: "Manufacturing", title: "Supply Chain Optimization", excerpt: "Advanced supply chain management system with real-time tracking, predictive analytics, and automated inventory management.", thumbnail: "/images/case/three.png", slug: "supply-chain-optimization", display_order: 3, created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 4, category_name: "E-commerce", title: "Multi-Platform Integration", excerpt: "Seamless integration of multiple e-commerce platforms with unified inventory management and real-time synchronization.", thumbnail: "/images/case/four.png", slug: "multi-platform-integration", display_order: 4, created_at: new Date().toISOString(), updated_at: new Date().toISOString() }, { id: 5, category_name: "Education", title: "Learning Management System", excerpt: "Comprehensive LMS with advanced analytics, automated grading, and seamless integration with existing educational tools.", thumbnail: "/images/case/five.png", slug: "learning-management-system", display_order: 5, created_at: new Date().toISOString(), updated_at: new Date().toISOString() } ]; // Use API data if available, otherwise use static data const storyData = caseStudies.length > 0 ? caseStudies : staticStoryData; // Log when API data is loaded useEffect(() => { if (caseStudies.length > 0) { } }, [caseStudies]); const handleMouseEnter = (index: number) => { setActiveIndex(index); setActiveImageIndex(index); }; return (

Enterprise Case Studies

{storyData.map((item, index) => { return (
handleMouseEnter(index)} >

{item.category_name || "Case Study"}

{item.title}

{item.excerpt}

); })}
{storyData.map((item, index) => { // Get the image URL - handle different scenarios let imageUrl; if (item.thumbnail) { if (item.thumbnail.startsWith('http')) { // Full URL (external) imageUrl = item.thumbnail; } else if (item.thumbnail.startsWith('/media')) { // Relative path starting with /media imageUrl = `${API_CONFIG.BASE_URL}${item.thumbnail}`; } else { // Just filename or relative path imageUrl = `${API_CONFIG.MEDIA_URL}/${item.thumbnail}`; } } else { // Fallback to static image imageUrl = getValidImageUrl('/images/case/one.png', FALLBACK_IMAGES.CASE_STUDY); } return (
{item.title
); })}
); }; export default Story;