"use client" import { useState, useEffect } from "react" import dynamic from "next/dynamic" import { useParams, useRouter } from "next/navigation" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { Checkbox } from "@/components/ui/checkbox" import { assemblySteps } from "./assemblySteps" import { bootSetupSteps } from "./bootSetupSteps" import { budgetOfficePCSteps } from "./budgetOfficePC" import { budgetGamingBuildSteps } from "./budgetGamingBuild" import { Clock, Users, CheckCircle, AlertTriangle, Info, Wrench, Lightbulb, Play, Youtube, XCircle } from "lucide-react" export default function GuideDetailPage() { const params = useParams() const router = useRouter() const guideSteps = params.id === "pc-first-boot-setup" ? bootSetupSteps : params.id === "budget-office-pc" ? budgetOfficePCSteps : params.id === "budget-gaming-build" ? budgetGamingBuildSteps : assemblySteps const [currentStep, setCurrentStep] = useState(0) // Start with introduction (step 0) const [completedSteps, setCompletedSteps] = useState([]) const [isPlaying, setIsPlaying] = useState(false) const [isMounted, setIsMounted] = useState(false) useEffect(() => { setIsMounted(true) }, []) // Load saved progress from localStorage useEffect(() => { if (typeof window !== 'undefined' && params.id) { const savedProgress = localStorage.getItem(`guide-progress-${params.id}`) if (savedProgress) { try { const parsed = JSON.parse(savedProgress) setCompletedSteps(parsed) } catch (error) { console.error('Error loading saved progress:', error) } } } }, [params.id]) const guides: Record = { "pc-assembly-guide": { id: params.id, title: "Complete PC Assembly Guide", description: "Step-by-step guide for building your PC from scratch with detailed visuals and instructions", difficulty: "Beginner", duration: "2-3 hours", views: "45.2k", category: "Gaming", estimatedCost: "₱44,000-66,000", totalSteps: guideSteps.length, tools: [ "Screwdriver (magnetic tip recommended)", "Anti-static wrist strap (optional)", "Thermal paste", "Clean workspace", "Motherboard manual", ], }, "pc-first-boot-setup": { id: params.id, title: "PC First Boot & Setup Guide", description: "Step-by-step guide to powering on your PC for the first time, configuring BIOS, installing Windows, and setting up drivers", difficulty: "Beginner", duration: "45–60 minutes", views: "12.3k", category: "Setup", estimatedCost: "N/A", totalSteps: guideSteps.length, tools: [ "Monitor and keyboard connected", "Power supply switched on", "Internet connection for driver updates", ], videoUrl: "https://www.youtube.com/embed/pJFvqaIa-38" }, "budget-office-pc": { id: params.id, title: "Budget Office PC Build", description: "Affordable step-by-step guide for building a budget office PC", difficulty: "Beginner", duration: "2-3 hours", views: "18.4k", category: "Office", estimatedCost: "₱22,000-30,000", totalSteps: guideSteps.length, tools: [ "Screwdriver (magnetic tip recommended)", "Anti-static wrist strap (optional)", "Thermal paste", "Clean workspace", "Motherboard manual", ], videoUrl: "https://www.youtube.com/embed/v_57sTb46c4" }, "budget-gaming-build": { id: params.id, title: "Best 700$ Gaming PC Build Guide", description: "An excellent build for 1080p gaming and you can stream to twitch or youtube", difficulty: "Beginner", duration: "2-3 hours", views: "32.7k", category: "Gaming", estimatedCost: "₱30,000-40,000", totalSteps: guideSteps.length, videoUrl: "https://www.youtube.com/embed/9ywZChvfft4", // <- add your video here tools: [ "Screwdriver (magnetic tip recommended)", "Anti-static wrist strap (optional)", "Thermal paste", "Clean workspace", "Motherboard manual", ], }, } // ✅ Fallback prevents crashes const guide = guides[params.id] ?? guides["pc-assembly-guide"] const progress = (completedSteps.length / guide.totalSteps) * 100 const currentStepData = guideSteps.find((step) => step.id === currentStep) const handleStepComplete = (stepId: number) => { setCompletedSteps((prev) => { const wasCompleted = prev.includes(stepId) const newCompleted = wasCompleted ? prev.filter((id) => id !== stepId) : [...prev, stepId] // Save to localStorage if (typeof window !== 'undefined' && params.id) { localStorage.setItem(`guide-progress-${params.id}`, JSON.stringify(newCompleted)) } // Auto-proceed to next step if marking as complete (not unmarking) if (!wasCompleted && stepId === currentStep) { const maxStep = guideSteps.length - 1 if (currentStep < maxStep) { // Small delay for better UX setTimeout(() => { setCurrentStep(currentStep + 1) }, 800) } } return newCompleted }) } const nextStep = () => { const maxStep = guideSteps.length - 1 if (currentStep < maxStep) { setCurrentStep(currentStep + 1) } } const prevStep = () => { if (currentStep > 0) { setCurrentStep(currentStep - 1) } } const resetProgress = () => { if (confirm('Are you sure you want to reset your progress? This cannot be undone.')) { setCompletedSteps([]) setCurrentStep(0) // Reset to introduction if (typeof window !== 'undefined' && params.id) { localStorage.removeItem(`guide-progress-${params.id}`) } } } return (
{/* Main Content */}
{/* Guide Header */}
{guide.title} {guide.description}
{/* Progress Bar and Video */} {/* Progress Bar */}
Progress
{completedSteps.length}/{guide.totalSteps} steps completed {completedSteps.length > 0 && ( )}
{/* full width */}
{/* Centered Video */} {guide.videoUrl && (